Make the name of the NTLMSSP client more consistant before we lock it in stone.
[ira/wip.git] / source3 / utils / net_rpc.c
index 890d4a012b131a07000dd97df05fe6d40ccab806..04a03307740b2959db25f5e215804342fa05b5e3 100644 (file)
@@ -84,7 +84,14 @@ static DOM_SID *net_get_remote_domain_sid(struct cli_state *cli)
        result = cli_lsa_query_info_policy(cli, mem_ctx, &pol, info_class, 
                                           domain_name, domain_sid);
        if (!NT_STATUS_IS_OK(result)) {
-               goto error;
+ error:
+               fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
+
+               if (!NT_STATUS_IS_OK(result)) {
+                       fprintf(stderr, "error: %s\n", nt_errstr(result));
+               }
+
+               exit(1);
        }
 
        cli_lsa_close(cli, mem_ctx, &pol);
@@ -92,15 +99,6 @@ static DOM_SID *net_get_remote_domain_sid(struct cli_state *cli)
        talloc_destroy(mem_ctx);
 
        return domain_sid;
-
- error:
-       fprintf(stderr, "could not obtain sid for domain %s\n", cli->domain);
-
-       if (!NT_STATUS_IS_OK(result)) {
-               fprintf(stderr, "error: %s\n", nt_errstr(result));
-       }
-
-       exit(1);
 }
 
 /**
@@ -918,6 +916,26 @@ rpc_group_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
        uint32 start_idx=0, max_entries=250, num_entries, i, loop_count = 0;
        struct acct_info *groups;
        DOM_SID global_sid_Builtin;
+       BOOL global = False;
+       BOOL local = False;
+       BOOL builtin = False;
+
+       if (argc == 0) {
+               global = True;
+               local = True;
+               builtin = True;
+       }
+
+       for (i=0; i<argc; i++) {
+               if (strequal(argv[i], "global"))
+                       global = True;
+
+               if (strequal(argv[i], "local"))
+                       local = True;
+
+               if (strequal(argv[i], "builtin"))
+                       builtin = True;
+       }
 
        string_to_sid(&global_sid_Builtin, "S-1-5-32");
 
@@ -951,6 +969,8 @@ rpc_group_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
                ZERO_STRUCT(info3);
                ctr.sam.info3 = &info3;
 
+               if (!global) break;
+
                get_query_dispinfo_params(
                        loop_count, &max_entries, &max_size);
 
@@ -969,12 +989,14 @@ rpc_group_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
                                printf("%-21.21s %-50.50s\n",
                                       group, desc);
                        else
-                               printf("%-21.21s\n", group);
+                               printf("%s\n", group);
                }
        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
        /* query domain aliases */
        start_idx = 0;
        do {
+               if (!local) break;
+
                result = cli_samr_enum_als_groups(cli, mem_ctx, &domain_pol,
                                                  &start_idx, max_entries,
                                                  &groups, &num_entries);
@@ -1008,7 +1030,7 @@ rpc_group_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
                                       groups[i].acct_name,
                                       description);
                        } else {
-                               printf("%-21.21s\n", groups[i].acct_name);
+                               printf("%s\n", groups[i].acct_name);
                        }
                }
        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
@@ -1024,6 +1046,8 @@ rpc_group_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
        /* query builtin aliases */
        start_idx = 0;
        do {
+               if (!builtin) break;
+
                result = cli_samr_enum_als_groups(cli, mem_ctx, &domain_pol,
                                                  &start_idx, max_entries,
                                                  &groups, &num_entries);
@@ -1057,7 +1081,7 @@ rpc_group_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
                                       groups[i].acct_name,
                                       description);
                        } else {
-                               printf("%-21.21s\n", groups[i].acct_name);
+                               printf("%s\n", groups[i].acct_name);
                        }
                }
        } while (NT_STATUS_EQUAL(result, STATUS_MORE_ENTRIES));
@@ -1066,6 +1090,111 @@ rpc_group_list_internals(const DOM_SID *domain_sid, struct cli_state *cli,
        return result;
 }
 
+static int rpc_group_list(int argc, const char **argv)
+{
+       return run_rpc_command(NULL, PI_SAMR, 0,
+                              rpc_group_list_internals,
+                              argc, argv);
+}
+static NTSTATUS 
+rpc_group_members_internals(const DOM_SID *domain_sid, struct cli_state *cli,
+                           TALLOC_CTX *mem_ctx, int argc, const char **argv)
+{
+       NTSTATUS result;
+       POLICY_HND connect_pol, domain_pol, group_pol;
+       uint32 num_rids, *rids, *rid_types;
+       uint32 num_members, *group_rids, *group_attrs;
+       uint32 num_names;
+       char **names;
+       uint32 *name_types;
+       int i;
+
+       /* Get sam policy handle */
+       
+       result = cli_samr_connect(cli, mem_ctx, MAXIMUM_ALLOWED_ACCESS, 
+                                 &connect_pol);
+       if (!NT_STATUS_IS_OK(result)) {
+               goto done;
+       }
+       
+       /* Get domain policy handle */
+       
+       result = cli_samr_open_domain(cli, mem_ctx, &connect_pol,
+                                     MAXIMUM_ALLOWED_ACCESS,
+                                     domain_sid, &domain_pol);
+       if (!NT_STATUS_IS_OK(result)) {
+               goto done;
+       }
+
+       result = cli_samr_lookup_names(cli, mem_ctx, &domain_pol, 1000,
+                                      1, argv, &num_rids, &rids, &rid_types);
+
+       if (!NT_STATUS_IS_OK(result)) {
+               goto done;
+       }
+
+       if (num_rids != 1) {
+               d_printf("Could not find group %s\n", argv[0]);
+               goto done;
+       }
+
+       if (rid_types[0] != SID_NAME_DOM_GRP) {
+               d_printf("%s is not a domain group\n", argv[0]);
+               goto done;
+       }
+
+       result = cli_samr_open_group(cli, mem_ctx, &domain_pol,
+                                    MAXIMUM_ALLOWED_ACCESS,
+                                    rids[0], &group_pol);
+
+       if (!NT_STATUS_IS_OK(result))
+               goto done;
+
+       result = cli_samr_query_groupmem(cli, mem_ctx, &group_pol,
+                                        &num_members, &group_rids,
+                                        &group_attrs);
+
+       if (!NT_STATUS_IS_OK(result))
+               goto done;
+
+       do {
+               int this_time = 512;
+
+               if (num_members < this_time)
+                       this_time = num_members;
+
+               result = cli_samr_lookup_rids(cli, mem_ctx, &domain_pol, 1000,
+                                             this_time, group_rids,
+                                             &num_names, &names, &name_types);
+
+               if (!NT_STATUS_IS_OK(result))
+                       goto done;
+
+               for (i = 0; i < this_time; i++) {
+                       printf("%s\n", names[i]);
+               }
+
+               num_members -= this_time;
+               group_rids += 512;
+
+       } while (num_members > 0);
+
+ done:
+       return result;
+}
+
+static int rpc_group_members(int argc, const char **argv)
+{
+       if (argc != 1) {
+               return rpc_group_usage(argc, argv);
+       }
+
+       return run_rpc_command(NULL, PI_SAMR, 0,
+                              rpc_group_members_internals,
+                              argc, argv);
+}
+
 /** 
  * 'net rpc group' entrypoint.
  * @param argc  Standard main() style argc
@@ -1080,6 +1209,8 @@ int net_rpc_group(int argc, const char **argv)
                {"add", rpc_group_add},
                {"delete", rpc_group_delete},
 #endif
+               {"list", rpc_group_list},
+               {"members", rpc_group_members},
                {NULL, NULL}
        };
        
@@ -1463,7 +1594,7 @@ int net_rpc_file(int argc, const char **argv)
 
 
 /** 
- * ABORT the shutdown of a remote RPC Server
+ * ABORT the shutdown of a remote RPC Server over, initshutdown pipe
  *
  * All parameters are provided by the run_rpc_command function, except for
  * argc, argv which are passed through. 
@@ -1478,11 +1609,47 @@ int net_rpc_file(int argc, const char **argv)
  * @return Normal NTSTATUS return.
  **/
 
-static NTSTATUS rpc_shutdown_abort_internals(const DOM_SID *domain_sid, struct cli_state *cli, TALLOC_CTX *mem_ctx, 
+static NTSTATUS rpc_shutdown_abort_internals(const DOM_SID *domain_sid, 
+                                            struct cli_state *cli, 
+                                            TALLOC_CTX *mem_ctx, 
                                             int argc, const char **argv) 
 {
        NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
        
+       result = cli_shutdown_abort(cli, mem_ctx);
+       
+       if (NT_STATUS_IS_OK(result))
+               DEBUG(5,("cmd_shutdown_abort: query succeeded\n"));
+       else
+               DEBUG(5,("cmd_shutdown_abort: query failed\n"));
+       
+       return result;
+}
+
+
+/** 
+ * ABORT the shutdown of a remote RPC Server,  over winreg pipe
+ *
+ * All parameters are provided by the run_rpc_command function, except for
+ * argc, argv which are passed through. 
+ *
+ * @param domain_sid The domain sid aquired from the remote server
+ * @param cli A cli_state connected to the server.
+ * @param mem_ctx Talloc context, destoyed on compleation of the function.
+ * @param argc  Standard main() style argc
+ * @param argv  Standard main() style argv.  Initial components are already
+ *              stripped
+ *
+ * @return Normal NTSTATUS return.
+ **/
+
+static NTSTATUS rpc_reg_shutdown_abort_internals(const DOM_SID *domain_sid, 
+                                                struct cli_state *cli, 
+                                                TALLOC_CTX *mem_ctx, 
+                                                int argc, const char **argv) 
+{
+       NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+       
        result = cli_reg_abort_shutdown(cli, mem_ctx);
        
        if (NT_STATUS_IS_OK(result))
@@ -1493,7 +1660,6 @@ static NTSTATUS rpc_shutdown_abort_internals(const DOM_SID *domain_sid, struct c
        return result;
 }
 
-
 /** 
  * ABORT the Shut down of a remote RPC server
  *
@@ -1506,7 +1672,17 @@ static NTSTATUS rpc_shutdown_abort_internals(const DOM_SID *domain_sid, struct c
 
 static int rpc_shutdown_abort(int argc, const char **argv) 
 {
-       return run_rpc_command(NULL, PI_WINREG, 0, rpc_shutdown_abort_internals,
+       int rc = run_rpc_command(NULL, PI_SHUTDOWN, 0, 
+                                rpc_shutdown_abort_internals,
+                                argc, argv);
+
+       if (rc == 0)
+               return rc;
+
+       DEBUG(1, ("initshutdown pipe didn't work, trying winreg pipe\n"));
+
+       return run_rpc_command(NULL, PI_WINREG, 0, 
+                              rpc_reg_shutdown_abort_internals,
                               argc, argv);
 }
 
@@ -1684,7 +1860,7 @@ static NTSTATUS rpc_trustdom_add_internals(const DOM_SID *domain_sid, struct cli
                ctr.info.id24 = &p24;
 
                result = cli_samr_set_userinfo(cli, mem_ctx, &user_pol, 24,
-                                              cli->user_session_key, &ctr);
+                                              &cli->user_session_key, &ctr);
 
                if (!NT_STATUS_IS_OK(result)) {
                        DEBUG(0,("Could not set trust account password: %s\n",
@@ -1709,8 +1885,13 @@ static NTSTATUS rpc_trustdom_add_internals(const DOM_SID *domain_sid, struct cli
 
 static int rpc_trustdom_add(int argc, const char **argv)
 {
-       return run_rpc_command(NULL, PI_SAMR, 0, rpc_trustdom_add_internals,
-                              argc, argv);
+       if (argc > 0) {
+               return run_rpc_command(NULL, PI_SAMR, 0, rpc_trustdom_add_internals,
+                                      argc, argv);
+       } else {
+               d_printf("Usage: net rpc trustdom add <domain>\n");
+               return -1;
+       }
 }
 
 
@@ -1726,6 +1907,7 @@ static int rpc_trustdom_add(int argc, const char **argv)
 static int rpc_trustdom_del(int argc, const char **argv)
 {
        d_printf("Sorry, not yet implemented.\n");
+       d_printf("Use 'smbpasswd -x -i' instead.\n");
        return -1;
 }
 
@@ -1782,7 +1964,7 @@ static int rpc_trustdom_establish(int argc, const char **argv)
 
        /* find the domain controller */
        if (!net_find_pdc(&server_ip, pdc_name, domain_name)) {
-               DEBUG(0, ("Coulnd find domain controller for domain %s\n", domain_name));
+               DEBUG(0, ("Couldn't find domain controller for domain %s\n", domain_name));
                return -1;
        }
 
@@ -1972,7 +2154,7 @@ static NTSTATUS rpc_query_domain_sid(const DOM_SID *domain_sid, struct cli_state
        sid_to_string(str_sid, domain_sid);
        d_printf("%s\n", str_sid);
        return NT_STATUS_OK;
-};
+}
 
 
 static int rpc_trustdom_list(int argc, const char **argv)
@@ -1988,8 +2170,8 @@ static int rpc_trustdom_list(int argc, const char **argv)
        POLICY_HND connect_hnd;
        
        /* trusted domains listing variables */
-       int enum_ctx = 0;
-       int num_domains, i, pad_len, col_len = 20;
+       unsigned int num_domains, enum_ctx = 0;
+       int i, pad_len, col_len = 20;
        DOM_SID *domain_sids;
        char **trusted_dom_names;
        fstring pdc_name, dummy;