Fix bug #6155 - "force group" is no longer working as expected.
[ira/wip.git] / source3 / utils / net_rpc.c
index 0e91144d339d218e69c60d280d5d9fc3db42969b..c54d4794133950c0292ad48276071acce9931608 100644 (file)
@@ -181,8 +181,7 @@ int run_rpc_command(struct net_context *c,
                        }
                        if (!NT_STATUS_IS_OK(nt_status)) {
                                DEBUG(0, ("Could not initialise pipe %s. Error was %s\n",
-                                       cli_get_pipe_name_from_iface(
-                                               debug_ctx(), cli, interface),
+                                       get_pipe_name_from_iface(interface),
                                        nt_errstr(nt_status) ));
                                cli_shutdown(cli);
                                return -1;
@@ -504,13 +503,13 @@ NTSTATUS rpc_info_internals(struct net_context *c,
                                             2,
                                             &info);
        if (NT_STATUS_IS_OK(result)) {
-               d_printf("Domain Name: %s\n", info->info2.domain_name.string);
+               d_printf("Domain Name: %s\n", info->general.domain_name.string);
                d_printf("Domain SID: %s\n", sid_str);
                d_printf("Sequence number: %llu\n",
-                       (unsigned long long)info->info2.sequence_num);
-               d_printf("Num users: %u\n", info->info2.num_users);
-               d_printf("Num domain groups: %u\n", info->info2.num_groups);
-               d_printf("Num local groups: %u\n", info->info2.num_aliases);
+                       (unsigned long long)info->general.sequence_num);
+               d_printf("Num users: %u\n", info->general.num_users);
+               d_printf("Num domain groups: %u\n", info->general.num_groups);
+               d_printf("Num local groups: %u\n", info->general.num_aliases);
        }
 
  done:
@@ -749,7 +748,9 @@ static int rpc_user_password(struct net_context *c, int argc, const char **argv)
        if (argv[1]) {
                u1003.usri1003_password = argv[1];
        } else {
-               asprintf(&prompt, "Enter new password for %s:", argv[0]);
+               if (asprintf(&prompt, "Enter new password for %s:", argv[0]) == -1) {
+                       return -1;
+               }
                u1003.usri1003_password = getpass(prompt);
                SAFE_FREE(prompt);
        }
@@ -795,7 +796,7 @@ static int rpc_user_info(struct net_context *c, int argc, const char **argv)
        status = NetUserGetGroups(c->opt_host,
                                  argv[0],
                                  0,
-                                 (uint8_t **)&u0,
+                                 (uint8_t **)(void *)&u0,
                                  (uint32_t)-1,
                                  &entries_read,
                                  &total_entries);
@@ -1392,7 +1393,7 @@ static NTSTATUS rpc_group_delete_internals(struct net_context *c,
        struct samr_RidTypeArray *rids = NULL;
        /* char **names; */
        int i;
-       /* DOM_GID *user_gids; */
+       /* struct samr_RidWithAttribute *user_gids; */
 
        struct samr_Ids group_rids, name_types;
        struct lsa_String lsa_acct_name;
@@ -2995,7 +2996,7 @@ static int rpc_share_list(struct net_context *c, int argc, const char **argv)
 
        status = NetShareEnum(c->opt_host,
                              level,
-                             (uint8_t **)&i1,
+                             (uint8_t **)(void *)&i1,
                              (uint32_t)-1,
                              &entries_read,
                              &total_entries,
@@ -3020,7 +3021,7 @@ static int rpc_share_list(struct net_context *c, int argc, const char **argv)
 
 static bool check_share_availability(struct cli_state *cli, const char *netname)
 {
-       if (!cli_send_tconX(cli, netname, "A:", "", 0)) {
+       if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, netname, "A:", "", 0))) {
                d_printf("skipping   [%s]: not a file share.\n", netname);
                return false;
        }
@@ -3126,14 +3127,14 @@ static NTSTATUS rpc_share_migrate_shares_internals(struct net_context *c,
                                                      &parm_error,
                                                      &result);
 
-                if (W_ERROR_V(result) == W_ERROR_V(WERR_ALREADY_EXISTS)) {
+                if (W_ERROR_V(result) == W_ERROR_V(WERR_FILE_EXISTS)) {
                        printf("           [%s] does already exist\n",
                                info502.name);
                        continue;
                }
 
                if (!NT_STATUS_IS_OK(nt_status) || !W_ERROR_IS_OK(result)) {
-                       printf("cannot add share: %s\n", dos_errstr(result));
+                       printf("cannot add share: %s\n", win_errstr(result));
                        goto done;
                }
 
@@ -3580,7 +3581,7 @@ static NTSTATUS rpc_share_migrate_security_internals(struct net_context *c,
                                                          &parm_error,
                                                          &result);
                if (!NT_STATUS_IS_OK(nt_status) || !W_ERROR_IS_OK(result)) {
-                       printf("cannot set share-acl: %s\n", dos_errstr(result));
+                       printf("cannot set share-acl: %s\n", win_errstr(result));
                        goto done;
                }
 
@@ -3956,17 +3957,6 @@ static void free_user_token(NT_USER_TOKEN *token)
        SAFE_FREE(token->user_sids);
 }
 
-static bool is_sid_in_token(NT_USER_TOKEN *token, DOM_SID *sid)
-{
-       int i;
-
-       for (i=0; i<token->num_sids; i++) {
-               if (sid_compare(sid, &token->user_sids[i]) == 0)
-                       return true;
-       }
-       return false;
-}
-
 static void add_sid_to_token(NT_USER_TOKEN *token, DOM_SID *sid)
 {
        if (is_sid_in_token(token, sid))
@@ -4073,7 +4063,11 @@ static bool get_user_sids(const char *domain, const char *user, NT_USER_TOKEN *t
                return false;
        }
 
-       string_to_sid(&user_sid, sid_str);
+       if (!string_to_sid(&user_sid, sid_str)) {
+               DEBUG(1,("Could not convert sid %s from string\n", sid_str));
+               return false;
+       }
+
        wbcFreeMemory(sid_str);
        sid_str = NULL;
 
@@ -4209,7 +4203,11 @@ static bool get_user_tokens_from_file(FILE *f,
                        /* We have a SID */
 
                        DOM_SID sid;
-                       string_to_sid(&sid, &line[1]);
+                       if(!string_to_sid(&sid, &line[1])) {
+                               DEBUG(1,("get_user_tokens_from_file: Could "
+                                       "not convert sid %s \n",&line[1]));
+                               return false;
+                       }
 
                        if (token == NULL) {
                                DEBUG(0, ("File does not begin with username"));
@@ -4282,7 +4280,7 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd,
 
        cnum = cli->cnum;
 
-       if (!cli_send_tconX(cli, netname, "A:", "", 0)) {
+       if (!NT_STATUS_IS_OK(cli_tcon_andx(cli, netname, "A:", "", 0))) {
                return;
        }
 
@@ -4296,16 +4294,15 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd,
                uint32 acc_granted;
 
                if (share_sd != NULL) {
-                       if (!se_access_check(share_sd, &tokens[i].token,
-                                            1, &acc_granted, &status)) {
+                       status = se_access_check(share_sd, &tokens[i].token,
+                                            1, &acc_granted);
+
+                       if (!NT_STATUS_IS_OK(status)) {
                                DEBUG(1, ("Could not check share_sd for "
                                          "user %s\n",
                                          tokens[i].name));
                                continue;
                        }
-
-                       if (!NT_STATUS_IS_OK(status))
-                               continue;
                }
 
                if (root_sd == NULL) {
@@ -4313,16 +4310,13 @@ static void show_userlist(struct rpc_pipe_client *pipe_hnd,
                        continue;
                }
 
-               if (!se_access_check(root_sd, &tokens[i].token,
-                                    1, &acc_granted, &status)) {
+               status = se_access_check(root_sd, &tokens[i].token,
+                                    1, &acc_granted);
+               if (!NT_STATUS_IS_OK(status)) {
                        DEBUG(1, ("Could not check root_sd for user %s\n",
                                  tokens[i].name));
                        continue;
                }
-
-               if (!NT_STATUS_IS_OK(status))
-                       continue;
-
                d_printf(" %s\n", tokens[i].name);
        }
 
@@ -4383,7 +4377,6 @@ static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c,
 {
        int ret;
        bool r;
-       ENUM_HND hnd;
        uint32 i;
        FILE *f;
 
@@ -4416,8 +4409,6 @@ static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c,
        for (i=0; i<num_tokens; i++)
                collect_alias_memberships(&tokens[i].token);
 
-       init_enum_hnd(&hnd, 0);
-
        share_list.num_shares = 0;
        share_list.shares = NULL;
 
@@ -4781,7 +4772,7 @@ static int rpc_file_user(struct net_context *c, int argc, const char **argv)
                             NULL,
                             username,
                             3,
-                            (uint8_t **)&i3,
+                            (uint8_t **)(void *)&i3,
                             preferred_len,
                             &entries_read,
                             &total_entries,
@@ -5012,8 +5003,7 @@ NTSTATUS rpc_init_shutdown_internals(struct net_context *c,
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
         const char *msg = "This machine will be shutdown shortly";
        uint32 timeout = 20;
-       struct initshutdown_String msg_string;
-       struct initshutdown_String_sub s;
+       struct lsa_StringLarge msg_string;
 
        if (c->opt_comment) {
                msg = c->opt_comment;
@@ -5022,8 +5012,7 @@ NTSTATUS rpc_init_shutdown_internals(struct net_context *c,
                timeout = c->opt_timeout;
        }
 
-       s.name = msg;
-       msg_string.name = &s;
+       msg_string.string = msg;
 
        /* create an entry */
        result = rpccli_initshutdown_Init(pipe_hnd, mem_ctx, NULL,
@@ -5067,16 +5056,14 @@ NTSTATUS rpc_reg_shutdown_internals(struct net_context *c,
 {
         const char *msg = "This machine will be shutdown shortly";
        uint32 timeout = 20;
-       struct initshutdown_String msg_string;
-       struct initshutdown_String_sub s;
+       struct lsa_StringLarge msg_string;
        NTSTATUS result;
        WERROR werr;
 
        if (c->opt_comment) {
                msg = c->opt_comment;
        }
-       s.name = msg;
-       msg_string.name = &s;
+       msg_string.string = msg;
 
        if (c->opt_timeout) {
                timeout = c->opt_timeout;
@@ -5094,7 +5081,7 @@ NTSTATUS rpc_reg_shutdown_internals(struct net_context *c,
                if ( W_ERROR_EQUAL(werr, WERR_MACHINE_LOCKED) )
                        d_fprintf(stderr, "\nMachine locked, use -f switch to force\n");
                else
-                       d_fprintf(stderr, "\nresult was: %s\n", dos_errstr(werr));
+                       d_fprintf(stderr, "\nresult was: %s\n", win_errstr(werr));
        }
 
        return result;
@@ -5242,37 +5229,18 @@ static NTSTATUS rpc_trustdom_add_internals(struct net_context *c,
        }
 
        {
-               NTTIME notime;
-               struct samr_LogonHours hours;
-               struct lsa_BinaryString parameters;
-               const int units_per_week = 168;
                struct samr_CryptPassword crypt_pwd;
 
-               ZERO_STRUCT(notime);
-               ZERO_STRUCT(hours);
-               ZERO_STRUCT(parameters);
-
-               hours.bits = talloc_array(mem_ctx, uint8_t, units_per_week);
-               if (!hours.bits) {
-                       result = NT_STATUS_NO_MEMORY;
-                       goto done;
-               }
-               hours.units_per_week = units_per_week;
-               memset(hours.bits, 0xFF, units_per_week);
+               ZERO_STRUCT(info.info23);
 
                init_samr_CryptPassword(argv[1],
                                        &cli->user_session_key,
                                        &crypt_pwd);
 
-               init_samr_user_info23(&info.info23,
-                                     notime, notime, notime,
-                                     notime, notime, notime,
-                                     NULL, NULL, NULL, NULL, NULL,
-                                     NULL, NULL, NULL, NULL, &parameters,
-                                     0, 0, ACB_DOMTRUST, SAMR_FIELD_ACCT_FLAGS,
-                                     hours,
-                                     0, 0, 0, 0, 0, 0, 0,
-                                     crypt_pwd.data, 24);
+               info.info23.info.fields_present = SAMR_FIELD_ACCT_FLAGS |
+                                                 SAMR_FIELD_NT_PASSWORD_PRESENT;
+               info.info23.info.acct_flags = ACB_DOMTRUST;
+               info.info23.password = crypt_pwd;
 
                result = rpccli_samr_SetUserInfo2(pipe_hnd, mem_ctx,
                                                  &user_pol,
@@ -5551,7 +5519,9 @@ static int rpc_trustdom_establish(struct net_context *c, int argc,
        strupper_m(domain_name);
 
        /* account name used at first is our domain's name with '$' */
-       asprintf(&acct_name, "%s$", lp_workgroup());
+       if (asprintf(&acct_name, "%s$", lp_workgroup()) == -1) {
+               return -1;
+       }
        strupper_m(acct_name);
 
        /*
@@ -6132,7 +6102,7 @@ static int rpc_trustdom_list(struct net_context *c, int argc, const char **argv)
        /* SamrConnect2 */
        nt_status = rpccli_samr_Connect2(pipe_hnd, mem_ctx,
                                         pipe_hnd->desthost,
-                                        SA_RIGHT_SAM_OPEN_DOMAIN,
+                                        SAMR_ACCESS_OPEN_DOMAIN,
                                         &connect_hnd);
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(0, ("Couldn't open SAMR policy handle. Error was %s\n",
@@ -6146,7 +6116,7 @@ static int rpc_trustdom_list(struct net_context *c, int argc, const char **argv)
           able to enumerate accounts*/
        nt_status = rpccli_samr_OpenDomain(pipe_hnd, mem_ctx,
                                           &connect_hnd,
-                                          SA_RIGHT_DOMAIN_ENUM_ACCOUNTS,
+                                          SAMR_DOMAIN_ACCESS_ENUM_ACCOUNTS,
                                           queried_dom_sid,
                                           &domain_hnd);
        if (!NT_STATUS_IS_OK(nt_status)) {
@@ -6344,7 +6314,8 @@ bool net_rpc_check(struct net_context *c, unsigned flags)
        if (!attempt_netbios_session_request(&cli, global_myname(),
                                             server_name, &server_ss))
                goto done;
-       if (!cli_negprot(cli))
+       status = cli_negprot(cli);
+       if (!NT_STATUS_IS_OK(status))
                goto done;
        if (cli->protocol < PROTOCOL_NT1)
                goto done;
@@ -6389,6 +6360,14 @@ static int rpc_vampire(struct net_context *c, int argc, const char **argv)
                        "net rpc vampire keytab\n"
                        "    Dump remote SAM database to Kerberos keytab file"
                },
+               {
+                       "passdb",
+                       rpc_vampire_passdb,
+                       NET_TRANSPORT_RPC,
+                       "Dump remote SAM database to passdb",
+                       "net rpc vampire passdb\n"
+                       "    Dump remote SAM database to passdb"
+               },
 
                {NULL, NULL, 0, NULL, NULL}
        };