s4-privs Add a lookup by index of privilages
authorAndrew Bartlett <abartlet@samba.org>
Thu, 26 Aug 2010 08:38:59 +0000 (18:38 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Sat, 11 Sep 2010 08:46:05 +0000 (18:46 +1000)
Now that privileges are no longer given luid values sequentially,
we need another way to look them up for enumeration.

Andrew Bartlett

Signed-off-by: Andrew Tridgell <tridge@samba.org>
source4/libcli/security/privilege.c
source4/rpc_server/lsa/dcesrv_lsa.c

index c21e1cbb6f9be6d7cf1276e64702a35619a22d66..9fd71928839324186fc7d6dd672053750278a7a6 100644 (file)
@@ -235,6 +235,17 @@ enum sec_privilege sec_privilege_from_mask(uint64_t mask)
        return -1;
 }
 
+/*
+  map a privilege name to a privilege id. Return -1 if not found
+*/
+enum sec_privilege sec_privilege_from_index(int idx)
+{
+       if (idx >= 0 && idx<ARRAY_SIZE(privilege_names)) {
+               return privilege_names[idx].privilege;
+       }
+       return -1;
+}
+
 
 /*
   return a privilege mask given a privilege id
index 51b6339a122a5c6f24270b35b998f9bcd96bb0d8..988acda10b3648c2f8b99601bc36f1794f25c876 100644 (file)
@@ -291,6 +291,7 @@ static NTSTATUS dcesrv_lsa_EnumPrivs(struct dcesrv_call_state *dce_call, TALLOC_
        struct dcesrv_handle *h;
        struct lsa_policy_state *state;
        uint32_t i;
+       enum sec_privilege priv;
        const char *privname;
 
        DCESRV_PULL_HANDLE(h, r->in.handle, LSA_HANDLE_POLICY);
@@ -298,12 +299,11 @@ static NTSTATUS dcesrv_lsa_EnumPrivs(struct dcesrv_call_state *dce_call, TALLOC_
        state = h->data;
 
        i = *r->in.resume_handle;
-       if (i == 0) i = 1;
 
-       while ((privname = sec_privilege_name(i)) &&
+       while (((priv = sec_privilege_from_index(i)) != -1) &&
               r->out.privs->count < r->in.max_count) {
                struct lsa_PrivEntry *e;
-
+               privname = sec_privilege_name(priv);
                r->out.privs->privs = talloc_realloc(r->out.privs,
                                                       r->out.privs->privs, 
                                                       struct lsa_PrivEntry,