s3: Remove unused "retry" from cli_full_connection
[nivanova/samba-autobuild/.git] / source3 / utils / smbcacls.c
index 11ced83bf67a1f8bd48d12f457eaea9145f2e384..2800ed982b66b7f518676efb83e5597862e634a3 100644 (file)
 */
 
 #include "includes.h"
+#include "popt_common.h"
 #include "../librpc/gen_ndr/ndr_lsa.h"
 #include "rpc_client/cli_lsarpc.h"
-
-extern bool AllowDebugChange;
+#include "../libcli/security/security.h"
 
 static int test_args;
 
@@ -68,7 +68,7 @@ static const struct perm_value standard_values[] = {
 /* Open cli connection and policy handle */
 
 static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli,
-                                  const DOM_SID *sid,
+                                  const struct dom_sid *sid,
                                   TALLOC_CTX *mem_ctx,
                                   enum lsa_SidType *type,
                                   char **domain, char **name)
@@ -121,14 +121,14 @@ static NTSTATUS cli_lsa_lookup_sid(struct cli_state *cli,
 static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
                                    const char *name,
                                    enum lsa_SidType *type,
-                                   DOM_SID *sid)
+                                   struct dom_sid *sid)
 {
        uint16 orig_cnum = cli->cnum;
        struct rpc_pipe_client *p;
        struct policy_handle handle;
        NTSTATUS status;
        TALLOC_CTX *frame = talloc_stackframe();
-       DOM_SID *sids;
+       struct dom_sid *sids;
        enum lsa_SidType *types;
 
        status = cli_tcon_andx(cli, "IPC$", "?????", "", 0);
@@ -167,7 +167,7 @@ static NTSTATUS cli_lsa_lookup_name(struct cli_state *cli,
 }
 
 /* convert a SID to a string, either numeric or username/group */
-static void SidToString(struct cli_state *cli, fstring str, const DOM_SID *sid)
+static void SidToString(struct cli_state *cli, fstring str, const struct dom_sid *sid)
 {
        char *domain = NULL;
        char *name = NULL;
@@ -196,12 +196,12 @@ static void SidToString(struct cli_state *cli, fstring str, const DOM_SID *sid)
 }
 
 /* convert a string to a SID, either numeric or username/group */
-static bool StringToSid(struct cli_state *cli, DOM_SID *sid, const char *str)
+static bool StringToSid(struct cli_state *cli, struct dom_sid *sid, const char *str)
 {
        enum lsa_SidType type;
 
-       if (strncmp(str, "S-", 2) == 0) {
-               return string_to_sid(sid, str);
+       if (string_to_sid(sid, str)) {
+               return true;
        }
 
        return NT_STATUS_IS_OK(cli_lsa_lookup_name(cli, str, &type, sid));
@@ -373,7 +373,7 @@ static bool parse_ace(struct cli_state *cli, struct security_ace *ace,
        unsigned int atype = 0;
        unsigned int aflags = 0;
        unsigned int amask = 0;
-       DOM_SID sid;
+       struct dom_sid sid;
        uint32_t mask;
        const struct perm_value *v;
        char *str = SMB_STRDUP(orig_str);
@@ -559,7 +559,7 @@ static struct security_descriptor *sec_desc_parse(TALLOC_CTX *ctx, struct cli_st
        char *tok;
        struct security_descriptor *ret = NULL;
        size_t sd_size;
-       DOM_SID *grp_sid=NULL, *owner_sid=NULL;
+       struct dom_sid *grp_sid=NULL, *owner_sid=NULL;
        struct security_acl *dacl=NULL;
        int revision=1;
 
@@ -574,7 +574,7 @@ static struct security_descriptor *sec_desc_parse(TALLOC_CTX *ctx, struct cli_st
                                printf("Only specify owner once\n");
                                goto done;
                        }
-                       owner_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
+                       owner_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
                        if (!owner_sid ||
                            !StringToSid(cli, owner_sid, tok+6)) {
                                printf("Failed to parse owner sid\n");
@@ -588,7 +588,7 @@ static struct security_descriptor *sec_desc_parse(TALLOC_CTX *ctx, struct cli_st
                                printf("Only specify group once\n");
                                goto done;
                        }
-                       grp_sid = SMB_CALLOC_ARRAY(DOM_SID, 1);
+                       grp_sid = SMB_CALLOC_ARRAY(struct dom_sid, 1);
                        if (!grp_sid ||
                            !StringToSid(cli, grp_sid, tok+6)) {
                                printf("Failed to parse group sid\n");
@@ -678,8 +678,9 @@ static uint16 get_fileinfo(struct cli_state *cli, const char *filename)
                printf("Failed to open %s: %s\n", filename, cli_errstr(cli));
        }
 
-       if (!cli_qfileinfo(cli, fnum, &mode, NULL, NULL, NULL,
-                                             NULL, NULL, NULL)) {
+       if (!NT_STATUS_IS_OK(cli_qfileinfo_basic(
+                                    cli, fnum, &mode, NULL, NULL, NULL,
+                                    NULL, NULL, NULL))) {
                printf("Failed to file info %s: %s\n", filename,
                                                        cli_errstr(cli));
         }
@@ -782,7 +783,7 @@ because the NT docs say this can't be done :-). JRA.
 static int owner_set(struct cli_state *cli, enum chown_mode change_mode, 
                        const char *filename, const char *new_username)
 {
-       DOM_SID sid;
+       struct dom_sid sid;
        struct security_descriptor *sd, *old;
        size_t sd_size;
 
@@ -834,8 +835,8 @@ static int ace_compare(struct security_ace *ace1, struct security_ace *ace2)
        if (ace1->type != ace2->type)
                return ace2->type - ace1->type;
 
-       if (sid_compare(&ace1->trustee, &ace2->trustee))
-               return sid_compare(&ace1->trustee, &ace2->trustee);
+       if (dom_sid_compare(&ace1->trustee, &ace2->trustee))
+               return dom_sid_compare(&ace1->trustee, &ace2->trustee);
 
        if (ace1->flags != ace2->flags)
                return ace1->flags - ace2->flags;
@@ -928,7 +929,7 @@ static int cacl_set(struct cli_state *cli, const char *filename,
                        bool found = False;
 
                        for (j=0;old->dacl && j<old->dacl->num_aces;j++) {
-                               if (sid_equal(&sd->dacl->aces[i].trustee,
+                               if (dom_sid_equal(&sd->dacl->aces[i].trustee,
                                              &old->dacl->aces[j].trustee)) {
                                        old->dacl->aces[j] = sd->dacl->aces[i];
                                        found = True;
@@ -1026,6 +1027,9 @@ static int inherit(struct cli_state *cli, const char *filename,
                        parent = get_secdesc(cli,parentname);
                        for (i=0;i<parent->dacl->num_aces;i++) {
                                struct security_ace *ace=&parent->dacl->aces[i];
+                               /* Add inherited flag to all aces */
+                               ace->flags=ace->flags|
+                                          SEC_ACE_FLAG_INHERITED_ACE;
                                if ((oldattr & aDIR) == aDIR) {
                                        if ((ace->flags & SEC_ACE_FLAG_CONTAINER_INHERIT) ==
                                            SEC_ACE_FLAG_CONTAINER_INHERIT) {
@@ -1034,6 +1038,8 @@ static int inherit(struct cli_state *cli, const char *filename,
                                } else {
                                        if ((ace->flags & SEC_ACE_FLAG_OBJECT_INHERIT) ==
                                            SEC_ACE_FLAG_OBJECT_INHERIT) {
+                                               /* clear flags for files */
+                                               ace->flags=0;
                                                add_ace(&old->dacl, ace);
                                        }
                                }
@@ -1131,8 +1137,7 @@ static struct cli_state *connect_one(struct user_auth_info *auth_info,
                                lp_workgroup(),
                                get_cmdline_auth_info_password(auth_info),
                                flags,
-                               get_cmdline_auth_info_signing_state(auth_info),
-                               NULL);
+                               get_cmdline_auth_info_signing_state(auth_info));
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0,("cli_full_connection failed! (%s)\n", nt_errstr(nt_status)));
                return NULL;
@@ -1193,13 +1198,9 @@ static struct cli_state *connect_one(struct user_auth_info *auth_info,
 
        load_case_tables();
 
-
        /* set default debug level to 1 regardless of what smb.conf sets */
-       setup_logging( "smbcacls", True );
-       DEBUGLEVEL_CLASS[DBGC_ALL] = 1;
-       dbf = x_stderr;
-       x_setbuf( x_stderr, NULL );
-       AllowDebugChange = false;
+       setup_logging( "smbcacls", DEBUG_STDERR);
+       lp_set_cmdline("log level", "1");
 
        setlinebuf(stdout);