svn commit: samba r9395 - in branches/SOC/SAMBA_3_0/source: . include libmsrpc libmsrpc/test libmsrpc/test/sam

skel at samba.org skel at samba.org
Thu Aug 18 20:36:14 GMT 2005


Author: skel
Date: 2005-08-18 20:36:13 +0000 (Thu, 18 Aug 2005)
New Revision: 9395

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9395

Log:
fixed infinite loop in cac_SamEnumGroups() if there are no groups in the sam

adduser can be used to delete a user that already exists


Modified:
   branches/SOC/SAMBA_3_0/source/Makefile.in
   branches/SOC/SAMBA_3_0/source/include/libmsrpc.h
   branches/SOC/SAMBA_3_0/source/libmsrpc/cac_samr.c
   branches/SOC/SAMBA_3_0/source/libmsrpc/test/Makefile
   branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/adduser.c
   branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/samgroup.c


Changeset:
Modified: branches/SOC/SAMBA_3_0/source/Makefile.in
===================================================================
--- branches/SOC/SAMBA_3_0/source/Makefile.in	2005-08-18 16:41:27 UTC (rev 9394)
+++ branches/SOC/SAMBA_3_0/source/Makefile.in	2005-08-18 20:36:13 UTC (rev 9395)
@@ -137,7 +137,7 @@
 EVERYTHING_PROGS = bin/debug2html at EXEEXT@ bin/smbfilter at EXEEXT@ bin/talloctort at EXEEXT@ \
 	bin/log2pcap at EXEEXT@
 
-SHLIBS = @SHLIB_PROGS@ @LIBSMBCLIENT@
+SHLIBS = @SHLIB_PROGS@ @LIBSMBCLIENT@ cac
 
 SCRIPTS = $(srcdir)/script/smbtar $(builddir)/script/findsmb
 

Modified: branches/SOC/SAMBA_3_0/source/include/libmsrpc.h
===================================================================
--- branches/SOC/SAMBA_3_0/source/include/libmsrpc.h	2005-08-18 16:41:27 UTC (rev 9394)
+++ branches/SOC/SAMBA_3_0/source/include/libmsrpc.h	2005-08-18 20:36:13 UTC (rev 9395)
@@ -1429,6 +1429,8 @@
 
       /**Array storing the descriptions of all the groups returned*/
       char **descriptions;
+
+      BOOL done;
    } out;
 };
 

Modified: branches/SOC/SAMBA_3_0/source/libmsrpc/cac_samr.c
===================================================================
--- branches/SOC/SAMBA_3_0/source/libmsrpc/cac_samr.c	2005-08-18 16:41:27 UTC (rev 9394)
+++ branches/SOC/SAMBA_3_0/source/libmsrpc/cac_samr.c	2005-08-18 20:36:13 UTC (rev 9395)
@@ -788,6 +788,7 @@
 
    srv->cli.pipe_idx = PI_SAMR;
 
+   printf("addgroupmember: adding rid 0x%x\n", op->in.rid);
    hnd->status = cli_samr_add_groupmem( &(srv->cli), mem_ctx, op->in.group_hnd, op->in.rid);
 
    if(!NT_STATUS_IS_OK(hnd->status))
@@ -869,6 +870,7 @@
 
    /*try to delete the users one by one*/
    for(i = 0; i < num_mem && NT_STATUS_IS_OK(hnd->status); i++) {
+      printf("cleargroupmembers: removing user 0x%x\n", rid[i]);
       hnd->status = cli_samr_del_groupmem(&(srv->cli), mem_ctx, group_hnd, rid[i]);
    }
 
@@ -922,6 +924,7 @@
 
 
    for(i = 0; i < op->in.num_members && NT_STATUS_IS_OK(hnd->status); i++) {
+      printf("setgroupmembers: adding 0x%x\n", op->in.rids[i]);
       hnd->status = cli_samr_add_groupmem( &(srv->cli), mem_ctx, op->in.group_hnd, op->in.rids[i]);
    }
 
@@ -958,10 +961,8 @@
       return CAC_FAILURE;
    }
 
-    /* cli_samr_enum_dom_users returns NT_STATUS_OK and sets resume_idx to 0 if all users have been enumerated, making it tricky to use in a loop
-     *  If all users have been enumerated and the developer has not modified op between calls, then the following will be true*/
-   /*FIXME: is there a better solution?*/
-   if(op->out.resume_idx == 0 && op->out.num_groups != 0 && op->out.rids != NULL && op->out.names != NULL)
+   /*using this BOOL is the only reliable way to know that we are done*/
+   if(op->out.done == True) /*we return failure so the call will break out of a loop*/
       return CAC_FAILURE;
 
    srv = cac_GetServer(hnd);
@@ -978,10 +979,14 @@
                                                 &acct_buf, &num_groups_out);
 
 
-   /*if there are no more entries, the operation will return NT_STATUS_OK. 
-    * We want to return failure if no results were returned*/
-   if(!NT_STATUS_IS_OK(hnd->status) && NT_STATUS_V(hnd->status) != NT_STATUS_V(STATUS_MORE_ENTRIES))
+   if(NT_STATUS_IS_OK(hnd->status)) {
+      op->out.done = True;
+   }
+   else if(NT_STATUS_V(hnd->status) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+      /*if there are no more entries, the operation will return NT_STATUS_OK. 
+       * We want to return failure if no results were returned*/
       return CAC_FAILURE;
+   }
 
    names_out = talloc_array(mem_ctx, char *, num_groups_out);
    if(!names_out) {

Modified: branches/SOC/SAMBA_3_0/source/libmsrpc/test/Makefile
===================================================================
--- branches/SOC/SAMBA_3_0/source/libmsrpc/test/Makefile	2005-08-18 16:41:27 UTC (rev 9394)
+++ branches/SOC/SAMBA_3_0/source/libmsrpc/test/Makefile	2005-08-18 20:36:13 UTC (rev 9395)
@@ -79,5 +79,8 @@
 samgroup: sam/samgroup.o test_util.o
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< test_util.o $(LIBS)
 
+samalias: sam/samalias.o test_util.o
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< test_util.o $(LIBS)
+
 clean:
 	rm -f $(TESTS) *.o lsa/*.o reg/*.o sam/*.o

Modified: branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/adduser.c
===================================================================
--- branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/adduser.c	2005-08-18 16:41:27 UTC (rev 9394)
+++ branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/adduser.c	2005-08-18 20:36:13 UTC (rev 9395)
@@ -8,6 +8,10 @@
 
    fstring tmp;
 
+   struct SamOpenUser ou;
+
+   POLICY_HND *user_hnd = NULL;
+
    mem_ctx = talloc_init("cac_adduser");
 
    hnd = cac_NewServerHandle();
@@ -49,7 +53,25 @@
    cactest_readline(stdin, tmp);
 
    if(tmp[0] == 'y') {
-      if(!cac_SamDeleteUser(hnd, mem_ctx, cdu.out.user))
+
+      if(!cdu.out.user) {
+         ZERO_STRUCT(ou);
+         ou.in.sam = sod.out.pol;
+         ou.in.access = MAXIMUM_ALLOWED_ACCESS;
+         ou.in.username = talloc_strdup(mem_ctx, cdu.in.username);
+
+         if(!cac_SamOpenUser(hnd, mem_ctx, &ou)) {
+            fprintf(stderr, "Could not open user for deletion. Error: %s\n", nt_errstr(hnd->status));
+         }
+
+         user_hnd = ou.out.user;
+      }
+
+      else {
+         user_hnd = cdu.out.user;
+      }
+
+      if(!cac_SamDeleteUser(hnd, mem_ctx, user_hnd))
          fprintf(stderr, "Could not delete user. Error: %s\n", nt_errstr(hnd->status));
    }
    else {

Modified: branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/samgroup.c
===================================================================
--- branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/samgroup.c	2005-08-18 16:41:27 UTC (rev 9394)
+++ branches/SOC/SAMBA_3_0/source/libmsrpc/test/sam/samgroup.c	2005-08-18 20:36:13 UTC (rev 9395)
@@ -64,6 +64,7 @@
       printf("[r]emove member\n");
       printf("[x] clear members\n");
       printf("[s]et members\n");
+      printf("[n] close group\n");
 
       printf("[q]uit\n\n");
       printf("Enter option: ");
@@ -348,6 +349,19 @@
             }
 
             break;
+
+         case 'n':
+            if(!group_hnd) {
+               printf("Must open group first!\n");
+            }
+
+            if(!cac_SamClose(hnd, mem_ctx, group_hnd)) {
+               printf("Could not close group\n");
+               break;
+            }
+
+            group_hnd = NULL;
+            break;
             
          case 'q':
             break;



More information about the samba-cvs mailing list