From 84f01a1607275b65899bffc672739f4c9bd018e4 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 27 Aug 2010 12:19:09 +1000 Subject: [PATCH] libcli/security Don't export privs[] as a global variable Instead, provide access functions for the LSA and net sam callers for the information they need. They still only enumerate the first 8 privileges that have traditionally been exposed. Andrew Bartlett Signed-off-by: Andrew Tridgell --- libcli/security/privileges.c | 43 +++++++++++++++------------------ libcli/security/privileges.h | 25 ++++++------------- source3/rpc_server/srv_lsa_nt.c | 7 ++---- source3/utils/net_sam.c | 6 ++--- 4 files changed, 31 insertions(+), 50 deletions(-) diff --git a/libcli/security/privileges.c b/libcli/security/privileges.c index 24a58e49e88..a33ef57a60e 100644 --- a/libcli/security/privileges.c +++ b/libcli/security/privileges.c @@ -55,7 +55,12 @@ const uint64_t se_take_ownership = SE_TAKE_OWNERSHIP; #define NUM_SHORT_LIST_PRIVS 8 -PRIVS privs[] = { +static const struct { + enum sec_privilege luid; + uint64_t privilege_mask; + const char *name; + const char *description; +} privs[] = { {SEC_PRIV_MACHINE_ACCOUNT, SE_MACHINE_ACCOUNT, "SeMachineAccountPrivilege", "Add machines to domain"}, {SEC_PRIV_TAKE_OWNERSHIP, SE_TAKE_OWNERSHIP, "SeTakeOwnershipPrivilege", "Take ownership of files or other objects"}, @@ -404,7 +409,7 @@ bool user_has_any_privilege(struct security_token *token, const uint64_t *privil } /******************************************************************* - return the number of elements in the privlege array + return the number of elements in the 'short' privlege array (traditional source3 behaviour) *******************************************************************/ int num_privileges_in_short_list( void ) @@ -412,27 +417,6 @@ int num_privileges_in_short_list( void ) return NUM_SHORT_LIST_PRIVS; } -/********************************************************************* - Generate the struct lsa_LUIDAttribute structure based on a bitmask - The assumption here is that the privilege has already been validated - so we are guaranteed to find it in the list. -*********************************************************************/ - -enum sec_privilege get_privilege_luid( uint64_t *privilege_mask ) -{ - int i; - - uint32_t num_privs = ARRAY_SIZE(privs); - - for ( i=0; i= 0 && idxin.resume_handle; int num_privs = num_privileges_in_short_list(); struct lsa_PrivEntry *entries = NULL; - struct lsa_LUIDAttribute luid; /* remember that the enum_context starts at 0 and not 1 */ @@ -1495,9 +1492,9 @@ NTSTATUS _lsa_EnumPrivs(struct pipes_struct *p, entries[i].luid.high = 0; } else { - init_lsa_StringLarge(&entries[i].name, privs[i].name); + init_lsa_StringLarge(&entries[i].name, sec_privilege_name_from_index(i)); - entries[i].luid.low = get_privilege_luid( &privs[i].privilege_mask ); + entries[i].luid.low = sec_privilege_from_index(i); entries[i].luid.high = 0; } } diff --git a/source3/utils/net_sam.c b/source3/utils/net_sam.c index 99eac045e02..6a9e261ea08 100644 --- a/source3/utils/net_sam.c +++ b/source3/utils/net_sam.c @@ -631,8 +631,6 @@ static int net_sam_policy(struct net_context *c, int argc, const char **argv) return net_run_function(c, argc, argv, "net sam policy", func); } -extern PRIVS privs[]; - static int net_sam_rights_list(struct net_context *c, int argc, const char **argv) { @@ -647,10 +645,10 @@ static int net_sam_rights_list(struct net_context *c, int argc, if (argc == 0) { int i; - int num = count_all_privileges(); + int num = num_privileges_in_short_list(); for (i=0; i