added -P (for no prompt) and -A <authfile> options
authorGerald Carter <jerry@samba.org>
Tue, 29 Aug 2000 14:43:42 +0000 (14:43 +0000)
committerGerald Carter <jerry@samba.org>
Tue, 29 Aug 2000 14:43:42 +0000 (14:43 +0000)
jerry
(This used to be commit 2d95c38f7e65a0379cbaadd57b8eb41d830b5a6b)

source3/include/rpcclient.h
source3/lib/cmd_interp.c
source3/rpcclient/cmd_spoolss.c

index f32272421733cee2cba20f80dd48c19b256709fb..ec7690a98a4c2cd30738390686804a78c56863c0 100644 (file)
@@ -132,6 +132,7 @@ struct client_info
     struct nt_client_info dom;
 
     BOOL reuse;
+    BOOL show_prompt;
 };
 
 
index 84fb28049ab3cf61bc705602c2dd62a1d090ed38..0030710052518ca49bdd98d0ce659b63998cf919 100644 (file)
@@ -404,30 +404,31 @@ static uint32 process(struct client_info *info, char *cmd_str)
 #endif
                        pstring pline;
                        BOOL at_sym = False;
+                       
                        pline[0] = 0;
-                       safe_strcat(pline, "[", sizeof(pline) - 1);
-                       if (usr.ntc.domain[0] != 0)
+                       if (info->show_prompt)
                        {
-                               safe_strcat(pline, usr.ntc.domain,
-                                           sizeof(pline) - 1);
-                               safe_strcat(pline, "\\", sizeof(pline) - 1);
-                               at_sym = True;
-                       }
-                       if (usr.ntc.user_name[0] != 0)
-                       {
-                               safe_strcat(pline, usr.ntc.user_name,
+                               safe_strcat(pline, "[", sizeof(pline) - 1);
+                               if (usr.ntc.domain[0] != 0)
+                               {
+                                       safe_strcat(pline, usr.ntc.domain,
+                                                   sizeof(pline) - 1);
+                                       safe_strcat(pline, "\\", sizeof(pline) - 1);
+                                       at_sym = True;
+                               }
+                               if (usr.ntc.user_name[0] != 0)
+                               {
+                                       safe_strcat(pline, usr.ntc.user_name,
+                                                   sizeof(pline) - 1);
+                                       at_sym = True;
+                               }
+                               if (at_sym)
+                                       safe_strcat(pline, "@", sizeof(pline) - 1);
+                                               
+                               safe_strcat(pline, cli_info.dest_host,
                                            sizeof(pline) - 1);
-                               at_sym = True;
-                       }
-                       if (at_sym)
-                       {
-                               safe_strcat(pline, "@", sizeof(pline) - 1);
+                               safe_strcat(pline, "]$ ", sizeof(pline) - 1);
                        }
-
-                       safe_strcat(pline, cli_info.dest_host,
-                                   sizeof(pline) - 1);
-                       safe_strcat(pline, "]$ ", sizeof(pline) - 1);
-
 #ifndef HAVE_LIBREADLINE
 
                        /* display a prompt */
@@ -491,7 +492,7 @@ static void usage(char *pname)
        fprintf(out_hnd, "\nVersion %s\n", VERSION);
        fprintf(out_hnd, "\t-d debuglevel         set the debuglevel\n");
        fprintf(out_hnd,
-               "\t-S <\\>server         Server to connect to (\\. or . for localhost)\n");
+               "\t-S <\\>server         Server to connect to\n");
        fprintf(out_hnd,
                "\t-l log basename.      Basename for log/debug files\n");
        fprintf(out_hnd,
@@ -504,6 +505,10 @@ static void usage(char *pname)
                "\t-I dest IP            use this IP to connect to\n");
        fprintf(out_hnd,
                "\t-E                    write messages to stderr instead of stdout\n");
+       fprintf(out_hnd,
+               "\t-A filename           file from which to read the authentication credentials\n");
+       fprintf(out_hnd,
+               "\t-P                    hide prompt (used for shell scripts)\n");
        fprintf(out_hnd,
                "\t-U username           set the network username\n");
        fprintf(out_hnd,
@@ -942,7 +947,7 @@ static uint32 cmd_set(struct client_info *info, int argc, char *argv[])
        }
 
        while ((opt = getopt(argc, argv,
-                            "Rs:O:M:S:i:Nn:d:l:hI:EB:U:L:t:m:W:T:D:c:")) !=
+                            "PRs:O:M:S:i:Nn:d:l:hI:EB:U:L:t:m:W:T:D:c:A:")) !=
               EOF)
        {
                switch (opt)
@@ -995,6 +1000,63 @@ static uint32 cmd_set(struct client_info *info, int argc, char *argv[])
                                }
                                break;
                        }
+                       case 'A':
+                       {
+                               FILE *auth;
+                               fstring buf;
+                               uint16 len = 0;
+                               char *ptr, *val, *param;
+                               
+                               if ((auth=sys_fopen(optarg, "r")) == NULL)
+                               {
+                                       /* fail if we can't open the credentials file */
+                                       DEBUG(0,("ERROR: Unable to open credentials file!\n"));
+                                       exit (-1);
+                               }
+                                
+                               while (!feof(auth))
+                               {  
+                                       /* get a line from the file */
+                                       if (!fgets (buf, sizeof(buf), auth))
+                                               continue;
+                                       len = strlen(buf);
+                                       
+                                       if ((len) && (buf[len-1]=='\n'))
+                                       {
+                                               buf[len-1] = '\0';
+                                               len--;
+                                       }       
+                                       if (len == 0)
+                                               continue;
+                                       
+                                       /* break up the line into parameter & value.
+                                          will need to eat a little whitespace possibly */
+                                       param = buf;
+                                       if (!(ptr = strchr (buf, '=')))
+                                               continue;
+                                       val = ptr+1;
+                                       *ptr = '\0';
+                                       
+                                       /* eat leading white space */
+                                       while ((*val!='\0') && ((*val==' ') || (*val=='\t')))
+                                               val++;
+                                       
+                                       if (strwicmp("password", param) == 0)
+                                       {
+                                               pstrcpy(password, val);
+                                               cmd_set_options |= CMD_PASS;
+                                       }
+                                       else if (strwicmp("username", param) == 0)
+                                       {
+                                               pstrcpy(usr.ntc.user_name, val);
+                                               cmd_set_options |= CMD_USER;
+                                       }
+                                               
+                                       memset(buf, 0, sizeof(buf));
+                               }
+                               fclose(auth);
+                               break;
+                       }
 
                        case 'W':
                        {
@@ -1002,6 +1064,12 @@ static uint32 cmd_set(struct client_info *info, int argc, char *argv[])
                                pstrcpy(usr.ntc.domain, optarg);
                                break;
                        }
+                       
+                       case 'P':
+                       { /* optarg == prompt string ? */
+                               info->show_prompt = False;
+                               break;
+                       }
 
                        case 'E':
                        {
@@ -1268,6 +1336,8 @@ int command_main(int argc, char *argv[])
        pstrcpy(cli_info.myhostname, "");
        pstrcpy(cli_info.dest_host, "");
        cli_info.dest_ip.s_addr = 0;
+       
+       cli_info.show_prompt = True;
 
        ZERO_STRUCT(cli_info.dom.level3_sid);
        ZERO_STRUCT(cli_info.dom.level5_sid);
index ba6d55cebe86a4b75beb0ed18cb5ca63de36302f..b3e755466383440a173aa17724a6dfc07378d2f6 100644 (file)
@@ -95,49 +95,47 @@ uint32 cmd_spoolss_enum_printers(struct client_info *info, int argc, char *argv[
        strupper(srv_name);
        
        flags=PRINTER_ENUM_LOCAL;
-
+       report (out_hnd, "Flags = PRINTER_ENUM_LOCAL\n");
        if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
                DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
        else
                report(out_hnd, "FAILED\n");
                
                
-#if 0  /* JERRY */
        flags=PRINTER_ENUM_NAME;
-
+       report (out_hnd, "Flags = PRINTER_ENUM_NAME\n");        
        if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
                DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
        else
                report(out_hnd, "FAILED\n");
 
        flags=PRINTER_ENUM_SHARED|PRINTER_ENUM_NAME;
-
+       report (out_hnd, "Flags = PRINTER_ENUM_SHARED|PRINTER_ENUM_NAME\n");
        if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
                DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
        else
                report(out_hnd, "FAILED\n");
 
        flags=PRINTER_ENUM_CONNECTIONS;
-
+       report (out_hnd, "Flags = PRINTER_ENUM_CONNECTIONS\n"); 
        if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
                DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
        else
                report(out_hnd, "FAILED\n");
                
        flags=PRINTER_ENUM_NETWORK;
-
+       report (out_hnd, "Flags = PRINTER_ENUM_NETWORK\n");
        if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
                DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
        else
                report(out_hnd, "FAILED\n");
                
        flags=PRINTER_ENUM_REMOTE;
-
+       report (out_hnd, "Flags = PRINTER_ENUM_REMOTE\n");
        if (msrpc_spoolss_enum_printers(srv_name, flags, level, ctr))
                DEBUG(5,("cmd_spoolss_enum_printer: query succeeded\n"));
        else
                report(out_hnd, "FAILED\n");
-#endif
 
        return NT_STATUS_NOPROBLEMO;
 }
@@ -646,11 +644,8 @@ uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[]
        init_unistr( &print_info_2.portname,    port_name);
        init_unistr( &print_info_2.drivername,  driver_name);
        init_unistr( &print_info_2.comment,     "Created by rpcclient");
-       /* init_unistr( &print_info_2.location, "");
-       init_unistr( &print_info_2.sepfile,     ""); */
        init_unistr( &print_info_2.printprocessor, "winprint");
        init_unistr( &print_info_2.datatype,    "RAW");
-       /* init_unistr( &print_info_2.parameters,       ""); */
        print_info_2.devmode = NULL;
        print_info_2.secdesc = NULL;
        print_info_2.attributes         = PRINTER_ATTRIBUTE_SHARED;
@@ -658,9 +653,13 @@ uint32 cmd_spoolss_addprinterex(struct client_info *info, int argc, char *argv[]
        print_info_2.defaultpriority    = 0;
        print_info_2.starttime          = 0;
        print_info_2.untiltime          = 0;
+       
+       /* These three fields must not be used by AddPrinter() 
+          as defined in the MS Platform SDK documentation..  --jerry
        print_info_2.status             = 0;
        print_info_2.cjobs              = 0;
        print_info_2.averageppm         = 0;
+       */
 
 
        /* if successful, spoolss_addprinterex() should return True and hnd