r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation
[abartlet/samba.git/.git] / source3 / utils / smbcacls.c
index 4dc89aecb9de4fb5f7766c982b3969d8d34de5f6..048ec8dc3ef4cb768adf402ec101500e896bbb68 100644 (file)
@@ -325,7 +325,7 @@ static BOOL add_ace(SEC_ACL **the_acl, SEC_ACE *ace)
                return True;
        }
 
-       aces = calloc(1+(*the_acl)->num_aces,sizeof(SEC_ACE));
+       aces = SMB_CALLOC_ARRAY(SEC_ACE, 1+(*the_acl)->num_aces);
        memcpy(aces, (*the_acl)->ace, (*the_acl)->num_aces * sizeof(SEC_ACE));
        memcpy(aces+(*the_acl)->num_aces, ace, sizeof(SEC_ACE));
        new = make_sec_acl(ctx,(*the_acl)->revision,1+(*the_acl)->num_aces, aces);
@@ -353,7 +353,7 @@ static SEC_DESC *sec_desc_parse(char *str)
                }
 
                if (strncmp(tok,"OWNER:", 6) == 0) {
-                       owner_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+                       owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
                        if (!owner_sid ||
                            !StringToSid(owner_sid, tok+6)) {
                                printf("Failed to parse owner sid\n");
@@ -363,7 +363,7 @@ static SEC_DESC *sec_desc_parse(char *str)
                }
 
                if (strncmp(tok,"GROUP:", 6) == 0) {
-                       grp_sid = (DOM_SID *)calloc(1, sizeof(DOM_SID));
+                       grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
                        if (!grp_sid ||
                            !StringToSid(grp_sid, tok+6)) {
                                printf("Failed to parse group sid\n");
@@ -657,6 +657,14 @@ static int cacl_set(struct cli_state *cli, char *filename,
                        }
                }
 
+               if (sd->owner_sid) {
+                       old->owner_sid = sd->owner_sid;
+               }
+
+               if (sd->grp_sid) { 
+                       old->grp_sid = sd->grp_sid;
+               }
+
                break;
 
        case SMB_ACL_ADD:
@@ -674,7 +682,7 @@ static int cacl_set(struct cli_state *cli, char *filename,
        sort_acl(old->dacl);
 
        /* Create new security descriptor and set it */
-       sd = make_sec_desc(ctx,old->revision, old->type, NULL, NULL,
+       sd = make_sec_desc(ctx,old->revision, old->type, old->owner_sid, old->grp_sid,
                           NULL, old->dacl, &sd_size);
 
        fnum = cli_nt_create(cli, filename, WRITE_DAC_ACCESS);
@@ -761,7 +769,7 @@ static struct cli_state *connect_one(const char *share)
 
        ctx=talloc_init("main");
 
-       /* set default debug level to 0 regardless of what smb.conf sets */
+       /* set default debug level to 1 regardless of what smb.conf sets */
        setup_logging( "smbcacls", True );
        DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
        dbf = x_stderr;