r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need
[vlendec/samba-autobuild/.git] / source3 / libsmb / clirap2.c
index 12a3d63aff35542b1e81fe621e9434509cda9836..3c23310f66ce8837fd12867b4b9159ce82a03aba 100644 (file)
@@ -76,8 +76,6 @@
 /*                                                   */
 /*****************************************************/ 
 
-#define NO_SYSLOG
-
 #include "includes.h" 
 
 #define WORDSIZE 2
@@ -213,11 +211,20 @@ int cli_NetGroupAdd(struct cli_state *cli, RAP_GROUP_INFO_1 * grinfo )
            +WORDSIZE                    /* info level    */
            +WORDSIZE];                  /* reserved word */
 
-  char data[1024];
-    
   /* offset into data of free format strings.  Will be updated */
   /* by PUTSTRINGP macro and end up with total data length.    */
   int soffset = RAP_GROUPNAME_LEN + 1 + DWORDSIZE; 
+  char *data;
+  size_t data_size;
+
+  /* Allocate data. */
+  data_size = MAX(soffset + strlen(grinfo->comment) + 1, 1024);
+
+  data = SMB_MALLOC_ARRAY(char, data_size);
+  if (!data) {
+    DEBUG (1, ("Malloc fail\n"));
+    return -1;
+  }
 
   /* now send a SMBtrans command with api WGroupAdd */
   
@@ -255,6 +262,7 @@ int cli_NetGroupAdd(struct cli_state *cli, RAP_GROUP_INFO_1 * grinfo )
       DEBUG(4,("NetGroupAdd failed\n"));
     }
   
+  SAFE_FREE(data);
   SAFE_FREE(rparam);
   SAFE_FREE(rdata);
 
@@ -329,6 +337,69 @@ int cli_RNetGroupEnum(struct cli_state *cli, void (*fn)(const char *, const char
   return res;
 }
 
+int cli_RNetGroupEnum0(struct cli_state *cli,
+                      void (*fn)(const char *, void *),
+                      void *state)
+{
+  char param[WORDSIZE                     /* api number    */
+           +sizeof(RAP_NetGroupEnum_REQ) /* parm string   */
+           +sizeof(RAP_GROUP_INFO_L0)    /* return string */
+           +WORDSIZE                     /* info level    */
+           +WORDSIZE];                   /* buffer size   */
+  char *p;
+  char *rparam = NULL;
+  char *rdata = NULL; 
+  unsigned int rprcnt, rdrcnt;
+  int res = -1;
+  
+  
+  memset(param, '\0', sizeof(param));
+  p = make_header(param, RAP_WGroupEnum,
+                 RAP_NetGroupEnum_REQ, RAP_GROUP_INFO_L0);
+  PUTWORD(p,0); /* Info level 0 */ /* Hmmm. I *very* much suspect this
+                                     is the resume count, at least
+                                     that's what smbd believes... */
+  PUTWORD(p,0xFFE0); /* Return buffer size */
+
+  if (cli_api(cli,
+             param, PTR_DIFF(p,param),8,
+             NULL, 0, 0xFFE0 /* data area size */,
+             &rparam, &rprcnt,
+             &rdata, &rdrcnt)) {
+    res = GETRES(rparam);
+    cli->rap_error = res;
+    if(cli->rap_error == 234) 
+        DEBUG(1,("Not all group names were returned (such as those longer than 21 characters)\n"));
+    else if (cli->rap_error != 0) {
+      DEBUG(1,("NetGroupEnum gave error %d\n", cli->rap_error));
+    }
+  }
+
+  if (rdata) {
+    if (res == 0 || res == ERRmoredata) {
+      int i, count;
+
+      p = rparam + WORDSIZE + WORDSIZE; /* skip result and converter */
+      GETWORD(p, count);
+
+      for (i=0,p=rdata;i<count;i++) {
+           char groupname[RAP_GROUPNAME_LEN];
+           GETSTRINGF(p, groupname, RAP_GROUPNAME_LEN);
+           fn(groupname, cli);
+      }        
+    } else {
+      DEBUG(4,("NetGroupEnum res=%d\n", res));
+    }
+  } else {
+    DEBUG(4,("NetGroupEnum no data returned\n"));
+  }
+    
+  SAFE_FREE(rparam);
+  SAFE_FREE(rdata);
+
+  return res;
+}
+
 int cli_NetGroupDelUser(struct cli_state * cli, const char *group_name, const char *user_name)
 {
   char *rparam = NULL;
@@ -479,10 +550,9 @@ int cli_NetGroupGetUsers(struct cli_state * cli, const char *group_name, void (*
   }
   if (rdata) {
     if (res == 0 || res == ERRmoredata) {
-      int i, converter, count;
+      int i, count;
       fstring username;
-      p = rparam +WORDSIZE;
-      GETWORD(p, converter);
+      p = rparam + WORDSIZE + WORDSIZE;
       GETWORD(p, count);
 
       for (i=0,p=rdata; i<count; i++) {
@@ -534,10 +604,9 @@ int cli_NetUserGetGroups(struct cli_state * cli, const char *user_name, void (*f
   }
   if (rdata) {
     if (res == 0 || res == ERRmoredata) {
-      int i, converter, count;
+      int i, count;
       fstring groupname;
-      p = rparam +WORDSIZE;
-      GETWORD(p, converter);
+      p = rparam + WORDSIZE + WORDSIZE;
       GETWORD(p, count);
 
       for (i=0,p=rdata; i<count; i++) {
@@ -736,7 +805,6 @@ int cli_RNetUserEnum(struct cli_state *cli, void (*fn)(const char *, const char
       char username[RAP_USERNAME_LEN];
       char userpw[RAP_UPASSWD_LEN];
       pstring comment, homedir, logonscript;
-      int pwage, priv, flags;
 
       p = rparam + WORDSIZE; /* skip result */
       GETWORD(p, converter);
@@ -746,11 +814,11 @@ int cli_RNetUserEnum(struct cli_state *cli, void (*fn)(const char *, const char
         GETSTRINGF(p, username, RAP_USERNAME_LEN);
         p++; /* pad byte */
         GETSTRINGF(p, userpw, RAP_UPASSWD_LEN);
-        GETDWORD(p, pwage); /* password age */
-        GETWORD(p, priv); /* 0=guest, 1=user, 2=admin */
+        p += DWORDSIZE; /* skip password age */
+        p += WORDSIZE;  /* skip priv: 0=guest, 1=user, 2=admin */
         GETSTRINGP(p, homedir, rdata, converter);
         GETSTRINGP(p, comment, rdata, converter);
-        GETWORD(p, flags);
+        p += WORDSIZE;  /* skip flags */
         GETSTRINGP(p, logonscript, rdata, converter);
 
         fn(username, comment, homedir, logonscript, cli);
@@ -768,6 +836,65 @@ int cli_RNetUserEnum(struct cli_state *cli, void (*fn)(const char *, const char
   return res;
 }
 
+int cli_RNetUserEnum0(struct cli_state *cli,
+                     void (*fn)(const char *, void *),
+                     void *state)
+{
+  char param[WORDSIZE                 /* api number    */
+           +sizeof(RAP_NetUserEnum_REQ) /* parm string   */
+           +sizeof(RAP_USER_INFO_L0)    /* return string */
+           +WORDSIZE                 /* info level    */
+           +WORDSIZE];               /* buffer size   */
+  char *p;
+  char *rparam = NULL;
+  char *rdata = NULL; 
+  unsigned int rprcnt, rdrcnt;
+  int res = -1;
+  
+
+  memset(param, '\0', sizeof(param));
+  p = make_header(param, RAP_WUserEnum,
+                 RAP_NetUserEnum_REQ, RAP_USER_INFO_L0);
+  PUTWORD(p,0); /* Info level 1 */
+  PUTWORD(p,0xFF00); /* Return buffer size */
+
+/* BB Fix handling of large numbers of users to be returned */
+  if (cli_api(cli,
+             param, PTR_DIFF(p,param),8,
+             NULL, 0, CLI_BUFFER_SIZE,
+             &rparam, &rprcnt,
+             &rdata, &rdrcnt)) {
+    res = GETRES(rparam);
+    cli->rap_error = res;
+    if (cli->rap_error != 0) {
+      DEBUG(1,("NetUserEnum gave error %d\n", cli->rap_error));
+    }
+  }
+  if (rdata) {
+    if (res == 0 || res == ERRmoredata) {
+      int i, count;
+      char username[RAP_USERNAME_LEN];
+
+      p = rparam + WORDSIZE + WORDSIZE; /* skip result and converter */
+      GETWORD(p, count);
+
+      for (i=0,p=rdata;i<count;i++) {
+        GETSTRINGF(p, username, RAP_USERNAME_LEN);
+        fn(username, cli);
+      }
+    } else {
+      DEBUG(4,("NetUserEnum res=%d\n", res));
+    }
+  } else {
+    DEBUG(4,("NetUserEnum no data returned\n"));
+  }
+    
+  SAFE_FREE(rparam);
+  SAFE_FREE(rdata);
+
+  return res;
+}
+
 /****************************************************************************
  call a NetFileClose2 - close open file on another session to server
 ****************************************************************************/
@@ -1349,10 +1476,9 @@ BOOL cli_ns_check_server_type(struct cli_state *cli, char *workgroup, uint32 sty
     cli->rap_error = res;
 
     if (res == 0 || res == ERRmoredata) {
-      int i, converter, count;
+      int i, count;
 
-      p = rparam + WORDSIZE;
-      GETWORD(p, converter);
+      p = rparam + WORDSIZE + WORDSIZE;
       GETWORD(p, count);
 
       p = rdata;
@@ -1674,10 +1800,9 @@ int cli_RNetServiceEnum(struct cli_state *cli, void (*fn)(const char *, const ch
 
   if (rdata) {
     if (res == 0 || res == ERRmoredata) {
-      int i, converter, count;
+      int i, count;
 
-      p = rparam + WORDSIZE; /* skip result */
-      GETWORD(p, converter);
+      p = rparam + WORDSIZE + WORDSIZE; /* skip result and converter */
       GETWORD(p, count);
 
       for (i=0,p=rdata;i<count;i++) {
@@ -1819,14 +1944,14 @@ int cli_NetSessionGetInfo(struct cli_state *cli, const char *workstation, void (
     res = GETRES(rparam);
     
     if (res == 0 || res == ERRmoredata) {
-      int rsize, converter;
+      int converter;
       pstring wsname, username, clitype_name;
       uint16  num_conns, num_opens, num_users;
       unsigned int    sess_time, idle_time, user_flags;
 
       p = rparam + WORDSIZE;
       GETWORD(p, converter);
-      GETWORD(p, rsize);
+      p += WORDSIZE;            /* skip rsize */
 
       p = rdata;
       GETSTRINGP(p, wsname, rdata, converter);