r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
[tprouty/samba.git] / source / libsmb / clifile.c
index d3022069491d99ec8333987759c19d432133bee6..9d20ed3adcd268ca01629982c13b7bf3562aba5e 100644 (file)
@@ -167,6 +167,55 @@ static mode_t unix_filetype_from_wire(uint32 wire_type)
        }
 }
 
+/****************************************************************************
+ Do a POSIX getfacl (UNIX extensions).
+****************************************************************************/
+
+BOOL cli_unix_getfacl(struct cli_state *cli, const char *name, size_t *prb_size, char **retbuf)
+{
+       unsigned int param_len = 0;
+       unsigned int data_len = 0;
+       uint16 setup = TRANSACT2_QPATHINFO;
+       char param[sizeof(pstring)+6];
+       char *rparam=NULL, *rdata=NULL;
+       char *p;
+
+       p = param;
+       memset(p, 0, 6);
+       SSVAL(p, 0, SMB_QUERY_POSIX_ACL);
+       p += 6;
+       p += clistr_push(cli, p, name, sizeof(pstring)-6, STR_TERMINATE);
+       param_len = PTR_DIFF(p, param);
+
+       if (!cli_send_trans(cli, SMBtrans2,
+               NULL,                        /* name */
+               -1, 0,                       /* fid, flags */
+               &setup, 1, 0,                /* setup, length, max */
+               param, param_len, 2,         /* param, length, max */
+               NULL,  0, cli->max_xmit      /* data, length, max */
+               )) {
+                       return False;
+       }
+
+       if (!cli_receive_trans(cli, SMBtrans2,
+               &rparam, &param_len,
+               &rdata, &data_len)) {
+                       return False;
+       }
+
+       if (data_len < 6) {
+               SAFE_FREE(rdata);
+               SAFE_FREE(rparam);
+               return False;
+       }
+
+       SAFE_FREE(rparam);
+       *retbuf = rdata;
+       *prb_size = (size_t)data_len;
+
+       return True;
+}
+
 /****************************************************************************
  Stat a file (UNIX extensions).
 ****************************************************************************/
@@ -205,6 +254,12 @@ BOOL cli_unix_stat(struct cli_state *cli, const char *name, SMB_STRUCT_STAT *sbu
                        return False;
        }
 
+       if (data_len < 96) {
+               SAFE_FREE(rdata);
+               SAFE_FREE(rparam);
+               return False;
+       }
+
        sbuf->st_size = IVAL2_TO_SMB_BIG_UINT(rdata,0);     /* total size, in bytes */
        sbuf->st_blocks = IVAL2_TO_SMB_BIG_UINT(rdata,8);   /* number of blocks allocated */
        sbuf->st_blocks /= STAT_ST_BLOCKSIZE;
@@ -1296,7 +1351,7 @@ int cli_ctemp(struct cli_state *cli, const char *path, char **tmp_path)
                pstring path2;
                clistr_pull(cli, path2, p, 
                            sizeof(path2), len, STR_ASCII);
-               *tmp_path = strdup(path2);
+               *tmp_path = SMB_STRDUP(path2);
        }
 
        return SVAL(cli->inbuf,smb_vwv0);
@@ -1347,7 +1402,7 @@ static BOOL cli_set_ea(struct cli_state *cli, uint16 setup, char *param, unsigne
        size_t ea_namelen = strlen(ea_name);
 
        data_len = 4 + 4 + ea_namelen + 1 + ea_len;
-       data = malloc(data_len);
+       data = SMB_MALLOC(data_len);
        if (!data) {
                return False;
        }
@@ -1503,7 +1558,7 @@ static BOOL cli_get_ea_list(struct cli_state *cli,
                goto out;
        }
 
-       ea_list = (struct ea_struct *)talloc(ctx, num_eas*sizeof(struct ea_struct));
+       ea_list = TALLOC_ARRAY(ctx, struct ea_struct, num_eas);
        if (!ea_list) {
                goto out;
        }