oops, accidentally committed clear-text password reading last week.
[tprouty/samba.git] / source / rpcclient / rpcclient.c
index 3166046c1912f10ecefaddeb08b4859476bf6c37..6001812616b2321f28bec02dbd564e0297b28567 100644 (file)
 #define REGISTER 0
 #endif
 
+extern pstring debugf;
 extern pstring scope;
+extern pstring global_myname;
 
 extern pstring user_socket_options;
 
 
-extern pstring debugf;
 extern int DEBUGLEVEL;
 
 
@@ -50,7 +51,7 @@ static void cmd_quit(struct client_info *info);
 static struct cli_state smbcli;
 struct cli_state *smb_cli = &smbcli;
 
-FILE *out_hnd = stdout;
+FILE *out_hnd;
 
 /****************************************************************************
 initialise smb client structure
@@ -59,6 +60,7 @@ void rpcclient_init(void)
 {
        bzero(smb_cli, sizeof(smb_cli));
        cli_initialise(smb_cli);
+       smb_cli->capabilities |= CAP_NT_SMBS | CAP_STATUS32;
 }
 
 /****************************************************************************
@@ -103,26 +105,40 @@ struct
   char *description;
 } commands[] = 
 {
-#if 0
-  {"ntlogin",    cmd_netlogon_login_test, "<username> NT Domain login test"},
-#endif
-  {"wksinfo",    cmd_wks_query_info,   "DCE/RPC - Workstation Query Info"},
-#if 0
-  {"srvinfo",    cmd_srv_query_info,   "DCE/RPC - Server Query Info"},
-  {"srvsessions",cmd_srv_enum_sess,    "DCE/RPC - List sessions on a server"},
-  {"srvshares",  cmd_srv_enum_shares,  "DCE/RPC - List shares on a server"},
-  {"srvconnections",cmd_srv_enum_conn, "DCE/RPC - List connections on a server"},
-  {"srvfiles",   cmd_srv_enum_files,   "DCE/RPC - List files on a server"},
-#endif
+  {"svcenum",    cmd_svc_enum,         "[-i] Lists Services Manager"},
+  {"regenum",    cmd_reg_enum,         "<keyname> Registry Enumeration (keys, values)"},
+  {"regdeletekey",cmd_reg_delete_key,  "<keyname> Registry Key Delete"},
+  {"regcreatekey",cmd_reg_create_key,  "<keyname> [keyclass] Registry Key Create"},
+  {"shutdown",cmd_reg_shutdown,  "[-m message] [-t timeout] [-r or --reboot] Server Shutdown"},
+  {"regquerykey",cmd_reg_query_key,    "<keyname> Registry Key Query"},
+  {"regdeleteval",cmd_reg_delete_val,  "<valname> Registry Value Delete"},
+  {"regcreateval",cmd_reg_create_val,  "<valname> <valtype> <value> Registry Key Create"},
+  {"reggetsec",  cmd_reg_get_key_sec,  "<keyname> Registry Key Security"},
+  {"regtestsec", cmd_reg_test_key_sec, "<keyname> Test Registry Key Security"},
+  {"ntlogin",    cmd_netlogon_login_test, "[username] [password] NT Domain login test"},
+  {"wksinfo",    cmd_wks_query_info,   "Workstation Query Info"},
+  {"srvinfo",    cmd_srv_query_info,   "Server Query Info"},
+  {"srvsessions",cmd_srv_enum_sess,    "List sessions on a server"},
+  {"srvshares",  cmd_srv_enum_shares,  "List shares on a server"},
+  {"srvconnections",cmd_srv_enum_conn, "List connections on a server"},
+  {"srvfiles",   cmd_srv_enum_files,   "List files on a server"},
   {"lsaquery",   cmd_lsa_query_info,   "Query Info Policy (domain member or server)"},
+  {"lookupsids", cmd_lsa_lookup_sids,  "Resolve names from SIDs"},
+  {"lookupnames",cmd_lsa_lookup_names,  "Resolve SIDs from names"},
+  {"lookupdomain",cmd_sam_lookup_domain, "Obtain SID for a local domain"},
   {"enumusers",  cmd_sam_enum_users,   "SAM User Database Query (experimental!)"},
+  {"addgroupmem",cmd_sam_add_groupmem,"<group rid> [member rid1] [member rid2] ... SAM Add Domain Group Member"},
+  {"addaliasmem",cmd_sam_add_aliasmem,"<alias rid> [member sid1] [member sid2] ... SAM Add Domain Alias Member"},
+  {"creategroup",cmd_sam_create_dom_group,"SAM Create Domain Group"},
+  {"createalias",cmd_sam_create_dom_alias,"SAM Create Domain Alias"},
+  {"delgroup",   cmd_sam_delete_dom_group,"SAM Delete Domain Group"},
+  {"delalias",   cmd_sam_delete_dom_alias,"SAM Delete Domain Alias"},
+  {"ntpass",     cmd_sam_ntchange_pwd, "NT SAM Password Change"},
   {"samuser",    cmd_sam_query_user,   "<username> SAM User Query (experimental!)"},
   {"samtest",    cmd_sam_test      ,   "SAM User Encrypted RPC test (experimental!)"},
   {"enumaliases",cmd_sam_enum_aliases, "SAM Aliases Database Query (experimental!)"},
-#if 0
   {"enumgroups", cmd_sam_enum_groups,  "SAM Group Database Query (experimental!)"},
-#endif
-  {"samgroups",  cmd_sam_query_groups, "SAM Group Database Query (experimental!)"},
+  {"samgroups",  cmd_sam_query_dominfo, "SAM Query Domain Info(experimental!)"},
   {"quit",       cmd_quit,        "logoff the server"},
   {"q",          cmd_quit,        "logoff the server"},
   {"exit",       cmd_quit,        "logoff the server"},
@@ -146,6 +162,7 @@ static void cmd_quit(struct client_info *info)
                smb_mem_write_status(dbf);
                smb_mem_write_errors(dbf);
                smb_mem_write_verbose(dbf);
+               dbgflush();
        }
 #endif
        exit(0);
@@ -215,7 +232,6 @@ wait for keyboard activity, swallowing network packets
 static void wait_keyboard(struct cli_state *cli)
 {
   fd_set fds;
-  int selrtn;
   struct timeval timeout;
   
   while (1) 
@@ -226,7 +242,7 @@ static void wait_keyboard(struct cli_state *cli)
 
       timeout.tv_sec = 20;
       timeout.tv_usec = 0;
-      selrtn = sys_select(MAX(cli->fd,fileno(stdin))+1,&fds,&timeout);
+      sys_select(MAX(cli->fd,fileno(stdin))+1,&fds,&timeout);
       
       if (FD_ISSET(fileno(stdin),&fds))
        return;
@@ -266,7 +282,6 @@ static void do_command(struct client_info *info, char *tok, char *line)
 ****************************************************************************/
 static BOOL process( struct client_info *info, char *cmd_str)
 {
-       extern FILE *dbf;
        pstring line;
        char *cmd = cmd_str;
 
@@ -358,11 +373,10 @@ usage on the program
 ****************************************************************************/
 static void usage(char *pname)
 {
-  fprintf(out_hnd, "Usage: %s service <password> [-p port] [-d debuglevel] [-l log] ",
+  fprintf(out_hnd, "Usage: %s service <password> [-d debuglevel] [-l log] ",
           pname);
 
   fprintf(out_hnd, "\nVersion %s\n",VERSION);
-  fprintf(out_hnd, "\t-p port               connect to the specified port\n");
   fprintf(out_hnd, "\t-d debuglevel         set the debuglevel\n");
   fprintf(out_hnd, "\t-l log basename.      Basename for log/debug files\n");
   fprintf(out_hnd, "\t-n netbios name.      Use this name as my netbios name\n");
@@ -389,8 +403,8 @@ enum client_action
 ****************************************************************************/
  int main(int argc,char *argv[])
 {
-       char *pname = argv[0];
-       int port = SMB_PORT;
+       BOOL interactive = True;
+
        int opt;
        extern FILE *dbf;
        extern char *optarg;
@@ -400,14 +414,15 @@ enum client_action
        char *p;
        BOOL got_pass = False;
        char *cmd_str="";
-       int myumask = 0755;
+       mode_t myumask = 0755;
        enum client_action cli_action = CLIENT_NONE;
-       int ret = 0;
 
        struct client_info cli_info;
 
        pstring password; /* local copy only, if one is entered */
-       pstring tmp;
+
+       out_hnd = stdout;
+       fstrcpy(debugf, argv[0]);
 
        rpcclient_init();
 
@@ -450,14 +465,10 @@ enum client_action
        pstrcpy(cli_info.share, "");
        pstrcpy(cli_info.service, "");
 
-       pstrcpy(cli_info.dom.level3_sid, "");
-       pstrcpy(cli_info.dom.level3_dom, "");
-       pstrcpy(cli_info.dom.level5_sid, "");
-       pstrcpy(cli_info.dom.level5_dom, "");
-
-       smb_cli->nt_pipe_fnum   = 0xffff;
-
-       setup_logging(pname, True);
+       ZERO_STRUCT(cli_info.dom.level3_sid);
+       ZERO_STRUCT(cli_info.dom.level5_sid);
+       fstrcpy(cli_info.dom.level3_dom, "");
+       fstrcpy(cli_info.dom.level5_dom, "");
 
        TimeInit();
        charset_initialise();
@@ -465,6 +476,11 @@ enum client_action
        myumask = umask(0);
        umask(myumask);
 
+       if (!get_myname(global_myname, NULL))
+       {
+               fprintf(stderr, "Failed to get my hostname.\n");
+       }
+
        if (getenv("USER"))
        {
                pstrcpy(smb_cli->user_name,getenv("USER"));
@@ -499,7 +515,7 @@ enum client_action
 
        if (argc < 2)
        {
-               usage(pname);
+               usage(argv[0]);
                exit(1);
        }
 
@@ -512,11 +528,11 @@ enum client_action
                argc--;
                argv++;
 
-               DEBUG(1,("service: %s\n", cli_info.service));
+               fprintf(out_hnd, "service: %s\n", cli_info.service);
 
                if (count_chars(cli_info.service,'\\') < 3)
                {
-                       usage(pname);
+                       usage(argv[0]);
                        printf("\n%s: Not enough '\\' characters in service\n", cli_info.service);
                        exit(1);
                }
@@ -542,13 +558,16 @@ enum client_action
                cli_action = CLIENT_SVC;
        }
 
-       while ((opt = getopt(argc, argv,"s:B:O:M:S:i:N:d:Pp:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
+       while ((opt = getopt(argc, argv,"s:B:O:M:S:i:N:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF)
        {
                switch (opt)
                {
                        case 'm':
                        {
-                               int max_protocol = interpret_protocol(optarg,max_protocol);
+                               /* FIXME ... max_protocol seems to be funny here */
+
+                               int max_protocol = 0;
+                               max_protocol = interpret_protocol(optarg,max_protocol);
                                fprintf(stderr, "max protocol not currently supported\n");
                                break;
                        }
@@ -615,6 +634,12 @@ enum client_action
                                break;
                        }
 
+                       case 'n':
+                       {
+                               fstrcpy(global_myname, optarg);
+                               break;
+                       }
+
                        case 'N':
                        {
                                got_pass = True;
@@ -633,13 +658,8 @@ enum client_action
                        case 'l':
                        {
                                slprintf(debugf, sizeof(debugf)-1,
-                                        "%s.client",optarg);
-                               break;
-                       }
-
-                       case 'p':
-                       {
-                               port = atoi(optarg);
+                                        "%s.client", optarg);
+                               interactive = False;
                                break;
                        }
 
@@ -652,7 +672,7 @@ enum client_action
 
                        case 'h':
                        {
-                               usage(pname);
+                               usage(argv[0]);
                                exit(0);
                                break;
                        }
@@ -671,25 +691,25 @@ enum client_action
 
                        default:
                        {
-                               usage(pname);
+                               usage(argv[0]);
                                exit(1);
                                break;
                        }
                }
        }
 
+       setup_logging(debugf, interactive);
+
        if (cli_action == CLIENT_NONE)
        {
-               usage(pname);
+               usage(argv[0]);
                exit(1);
        }
 
-       DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
+       strupper(global_myname);
+       fstrcpy(cli_info.myhostname, global_myname);
 
-       if (!get_myname(cli_info.myhostname, NULL))
-       {
-               fprintf(stderr, "Failed to get my hostname.\n");
-       }
+       DEBUG(3,("%s client started (version %s)\n",timestring(),VERSION));
 
        if (!lp_load(servicesf,True, False, False))
        {
@@ -721,7 +741,8 @@ enum client_action
                }
                else
                {
-                       pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */
+                       /* generate 16 byte hashes */
+                       pwd_make_lm_nt_16(&(smb_cli->pwd), password);
                }
        }
        else 
@@ -744,20 +765,17 @@ enum client_action
                exit(-1);
        }
 
-       ret = 0;
-
        switch (cli_action)
        {
                case CLIENT_IPC:
                {
-                       ret = process(&cli_info, cmd_str) ? 0 : 1;
+                       process(&cli_info, cmd_str);
                        break;
                }
 
                default:
                {
                        fprintf(stderr, "unknown client action requested\n");
-                       ret = 1;
                        break;
                }
        }