s3-winbind: Implemented samr backend function common_lookup_usergroups.
authorAndreas Schneider <asn@samba.org>
Wed, 9 Jun 2010 12:57:15 +0000 (14:57 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 5 Jul 2010 13:59:07 +0000 (15:59 +0200)
source3/winbindd/winbindd_samr.c

index 337ff99d42912af4775dacd72b54438219a50c2d..d2ce4259b31a1b7e8431f552456eb14704153769 100644 (file)
@@ -1203,11 +1203,89 @@ error:
 static NTSTATUS common_lookup_usergroups(struct winbindd_domain *domain,
                                         TALLOC_CTX *mem_ctx,
                                         const struct dom_sid *user_sid,
-                                        uint32_t *num_groups,
-                                        struct dom_sid **user_gids)
+                                        uint32_t *pnum_groups,
+                                        struct dom_sid **puser_grpsids)
 {
-       /* TODO FIXME */
-       return NT_STATUS_NOT_IMPLEMENTED;
+       struct rpc_pipe_client *samr_pipe;
+       struct policy_handle dom_pol, usr_pol;
+       uint32_t samr_access = SEC_FLAG_MAXIMUM_ALLOWED;
+       struct samr_RidWithAttributeArray *rid_array = NULL;
+       struct dom_sid *user_grpsids = NULL;
+       uint32_t num_groups = 0, i;
+       uint32_t user_rid;
+       TALLOC_CTX *tmp_ctx;
+       NTSTATUS status;
+
+       DEBUG(3,("samr: lookup usergroups\n"));
+
+       if (!sid_peek_check_rid(&domain->sid, user_sid, &user_rid)) {
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       if (pnum_groups) {
+               *pnum_groups = 0;
+       }
+
+       if (puser_grpsids) {
+               *puser_grpsids = NULL;
+       }
+
+       tmp_ctx = talloc_stackframe();
+       if (tmp_ctx == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       status = open_internal_samr_conn(tmp_ctx, domain, &samr_pipe, &dom_pol);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto error;
+       }
+
+       /* Get user handle */
+       status = rpccli_samr_OpenUser(samr_pipe,
+                                     tmp_ctx,
+                                     &dom_pol,
+                                     samr_access,
+                                     user_rid,
+                                     &usr_pol);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       /* Query user rids */
+       status = rpccli_samr_GetGroupsForUser(samr_pipe,
+                                             tmp_ctx,
+                                             &usr_pol,
+                                             &rid_array);
+       num_groups = rid_array->count;
+
+       rpccli_samr_Close(samr_pipe, tmp_ctx, &usr_pol);
+
+       if (!NT_STATUS_IS_OK(status) || num_groups == 0) {
+               return status;
+       }
+
+       user_grpsids = TALLOC_ARRAY(tmp_ctx, struct dom_sid, num_groups);
+       if (user_grpsids == NULL) {
+               status = NT_STATUS_NO_MEMORY;
+               goto error;
+       }
+
+       for (i = 0; i < num_groups; i++) {
+               sid_compose(&(user_grpsids[i]), &domain->sid,
+                           rid_array->rids[i].rid);
+       }
+
+       if (pnum_groups) {
+               *pnum_groups = num_groups;
+       }
+
+       if (puser_grpsids) {
+               *puser_grpsids = talloc_move(mem_ctx, &user_grpsids);
+       }
+
+error:
+       TALLOC_FREE(tmp_ctx);
+       return status;
 }
 
 static NTSTATUS common_lookup_useraliases(struct winbindd_domain *domain,