more updates. several spoolss commands added as placeholders
authorGerald Carter <jerry@samba.org>
Thu, 15 Mar 2001 02:15:05 +0000 (02:15 +0000)
committerGerald Carter <jerry@samba.org>
Thu, 15 Mar 2001 02:15:05 +0000 (02:15 +0000)
to be filled in one at a time.

source/libsmb/cli_spoolss.c
source/rpcclient/cmd_lsarpc.c
source/rpcclient/cmd_samr.c
source/rpcclient/cmd_spoolss.c
source/rpcclient/rpcclient.c

index af12f102d7619ec36feadc905c7b3efc947596bd..26ab99419ae1237f1ab412ee07741a9c4058d2ed 100644 (file)
@@ -136,7 +136,7 @@ uint32 cli_spoolss_open_printer_ex(struct cli_state *cli, char *printername,
 
 /* Close a printer handle */
 
-uint32 cli_spoolss_closeprinter(struct cli_state *cli, POLICY_HND *pol)
+uint32 cli_spoolss_close_printer(struct cli_state *cli, POLICY_HND *pol)
 {
        prs_struct qbuf, rbuf;
        SPOOL_Q_CLOSEPRINTER q;
index 3ae0b1e11d686be1fc2a48874c3802a3e9cf5b18..77b61c8a2fc8f30fafefd643a0de4f80c99ad26f 100644 (file)
@@ -297,6 +297,7 @@ static uint32 cmd_lsa_enum_trust_dom(struct cli_state *cli, int argc, char **arg
 /* List of commands exported by this module */
 
 struct cmd_set lsarpc_commands[] = {
+       { "LSARPC",     NULL,                           "" },
        { "lsaquery",   cmd_lsa_query_info_policy,      "Query info policy" },
        { "lookupsids", cmd_lsa_lookup_sids,            "Convert SIDs to names" },
        { "lookupnames",cmd_lsa_lookup_names,           "Convert names to SIDs" },
index c7bed1368e9751c5f3d3aecb5b4412918e5756f0..3772714cda3e5f886168905afff5e75e793e6dc5 100644 (file)
@@ -432,6 +432,7 @@ static uint32 cmd_samr_query_groupmem(struct cli_state *cli, int argc, char **ar
 /* List of commands exported by this module */
 
 struct cmd_set samr_commands[] = {
+       { "SAMR",               NULL,                           "" },
        { "queryuser",          cmd_samr_query_user,            "Query user info" },
        { "querygroup",         cmd_samr_query_group,           "Query group info" },
        { "queryusergroups",    cmd_samr_query_usergroups,      "Query user groups" },
index c7989d6882b17ea7aa01b8f964f51c85ee896025..8db769a8bd9cf41bb3255712ebc650cbfff2724f 100644 (file)
@@ -31,6 +31,16 @@ extern pstring global_myname;
 extern pstring username, password;
 extern pstring workgroup;
 
+/**********************************************************************
+ * dummy function  -- placeholder
+  */
+static uint32 cmd_spoolss_not_implemented (struct cli_state *cli, 
+                                          int argc, char **argv)
+{
+       printf ("(*) This command is not currently implemented.\n");
+       return NT_STATUS_NO_PROBLEMO;
+}
+
 /****************************************************************************
  display sec_ace structure
  ****************************************************************************/
@@ -83,6 +93,55 @@ static void display_sec_desc(SEC_DESC *sec)
        if (sec->off_dacl) display_sec_acl(sec->dacl);
 }
 
+/***********************************************************************
+ * Get printer information
+ */
+static uint32 cmd_spoolss_open_printer_ex(struct cli_state *cli, int argc, char **argv)
+{
+       uint32          result = NT_STATUS_UNSUCCESSFUL; 
+       pstring         printername;
+       fstring         server, user;
+       POLICY_HND      hnd;
+       
+       if (argc != 2) {
+               printf("Usage: openprinter <printername>\n");
+               return NT_STATUS_NOPROBLEMO;
+       }
+       
+       if (!cli)
+               return NT_STATUS_UNSUCCESSFUL;
+               
+
+       slprintf (server, sizeof(fstring), "\\\\%s", cli->desthost);
+       strupper (server);
+       fstrcpy  (user, cli->user_name);
+       fstrcpy  (printername, argv[1]);
+
+               
+       /* Initialise RPC connection */
+       if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
+               fprintf (stderr, "Could not initialize spoolss pipe!\n");
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       /* Enumerate printers */
+       result = cli_spoolss_open_printer_ex (cli, printername, "", 
+                               PRINTER_ACCESS_USE, server, user, &hnd);
+
+       if (result == NT_STATUS_NOPROBLEMO) {
+               printf ("Printer %s opened successfully\n", printername);
+               result = cli_spoolss_close_printer (cli, &hnd);
+               if (result != NT_STATUS_NOPROBLEMO) {
+                       printf ("Error closing printer handle! (%s)\n", get_nt_error_msg(result));
+               }
+       }
+
+       cli_nt_session_close(cli);
+
+       return result;
+}
+
+
 /****************************************************************************
 printer info level 0 display function
 ****************************************************************************/
@@ -245,7 +304,8 @@ static uint32 cmd_spoolss_enum_printers(struct cli_state *cli, int argc, char **
                return NT_STATUS_UNSUCCESSFUL;
        }
 
-       /* Enumerate printers */
+       /* Enumerate printers  -- Should we enumerate types other 
+          than PRINTER_ENUM_LOCAL?  Maybe accept as a parameter?  --jerry */
        ZERO_STRUCT(ctr);
        result = cli_spoolss_enum_printers(cli, PRINTER_ENUM_LOCAL, 
                                           info_level, &returned, &ctr);
@@ -355,8 +415,9 @@ static uint32 cmd_spoolss_enum_ports(struct cli_state *cli, int argc, char **arg
        return result;
 }
 
-/* Get printer information */
-
+/***********************************************************************
+ * Get printer information
+ */
 static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **argv)
 {
        POLICY_HND pol;
@@ -382,8 +443,7 @@ static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **arg
                info_level = atoi(argv[2]);
        }
 
-       slprintf(printer_name, sizeof(fstring), "\\\\%s\\%s",
-                server, argv[1]);
+       slprintf(printer_name, sizeof(fstring), "\\\\%s\\%s", server, argv[1]);
 
        slprintf(station_name, sizeof(fstring), "\\\\%s", global_myname);
 
@@ -422,7 +482,8 @@ static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **arg
        }
 
  done: 
-       if (opened_hnd) cli_spoolss_closeprinter(cli, &pol);
+       if (opened_hnd) 
+               cli_spoolss_close_printer(cli, &pol);
 
        cli_nt_session_close(cli);
 
@@ -430,12 +491,19 @@ static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **arg
 }
 
 /* List of commands exported by this module */
-
 struct cmd_set spoolss_commands[] = {
 
-       { "enumprinters",       cmd_spoolss_enum_printers,      "Enumerate printers" },
+       { "SPOOLSS",            NULL,                           "" },
+       { "adddriver",          cmd_spoolss_not_implemented,    "Add a print driver (*)" },
+       { "addprinter",         cmd_spoolss_not_implemented,    "Add a printer (*)" },
+       { "enumdata",           cmd_spoolss_not_implemented,    "Enumerate printer data (*)" },
+       { "enumjobs",           cmd_spoolss_not_implemented,    "Enumerate print jobs (*)" },
        { "enumports",          cmd_spoolss_enum_ports,         "Enumerate printer ports" },
+       { "enumprinters",       cmd_spoolss_enum_printers,      "Enumerate printers" },
+       { "getdata",            cmd_spoolss_not_implemented,    "Get print driver data (*)" },
+       { "getdriver",          cmd_spoolss_not_implemented,    "Get print driver information (*)" },
+       { "getdriverdir",       cmd_spoolss_not_implemented,    "Get print driver upload directory (*)" },
        { "getprinter",         cmd_spoolss_getprinter,         "Get printer info" },
-
+       { "openprinter",        cmd_spoolss_open_printer_ex,    "Open printer handle" },
        { NULL, NULL, NULL }
 };
index 7cdd73a592755263f4d77ba2cf907a8cf8409303..1b434dd696d4beb8243775e945e1fe0d72b9eb02 100644 (file)
@@ -116,7 +116,7 @@ static uint32 cmd_help(struct cli_state *cli, int argc, char **argv)
                struct cmd_set *temp_set = temp_list->cmd_set;
 
                while(temp_set->name) {
-                       printf("%s\t%s\n", temp_set->name,
+                       printf("%15s\t\t%s\n", temp_set->name,
                               temp_set->description);
                        temp_set++;
                }
@@ -149,14 +149,22 @@ static uint32 cmd_quit(struct cli_state *cli, int argc, char **argv)
 /* Build in rpcclient commands */
 
 static struct cmd_set rpcclient_commands[] = {
+       { "GENERAL OPTIONS",    NULL,   "" },
        { "help",       cmd_help,       "Print list of commands" },
+       { "?",          cmd_help,       "Print list of commands" },
        { "debuglevel", cmd_debuglevel, "Set debug level" },
+       { "exit",       cmd_quit,       "Exit program" },
        { "quit",       cmd_quit,       "Exit program" },
-       { "?",          cmd_help,       "Print list of commands" },
 
        { NULL, NULL, NULL }
 };
 
+static struct cmd_set separator_command[] = {
+       { "---------------", NULL,      "----------------------" },
+       { NULL, NULL, NULL }
+};
+
+
 void add_command_set(struct cmd_set *cmd_set)
 {
        struct cmd_list *entry;
@@ -213,11 +221,16 @@ static uint32 do_cmd(struct cli_state *cli, struct cmd_set *cmd_entry, char *cmd
        }
 
        /* Call the function */
+       if (cmd_entry->fn) {
+               result = cmd_entry->fn(cli, argc, argv);
+       }
+       else {
+               fprintf (stderr, "Invalid command\n");
+               result = NT_STATUS_INVALID_PARAMETER;
+       }
 
-       result = cmd_entry->fn(cli, argc, argv);
-                               
+                                               
        /* Cleanup */
-
        for (i = 0; i < argc; i++) {
                free(argv[i]);
        }
@@ -445,7 +458,7 @@ static void usage(char *pname)
         */
        if (!got_pass) {
                init_rpcclient_creds (&creds, username, workgroup, "");
-               pwd_read(&creds.pwd, "Password : ", lp_encrypted_passwords());
+               pwd_read(&creds.pwd, "Enter Password: ", lp_encrypted_passwords());
        }
        else {
                init_rpcclient_creds (&creds, username, workgroup, password);
@@ -464,9 +477,13 @@ static void usage(char *pname)
 
        /* Load command lists */
        add_command_set(rpcclient_commands);
+       add_command_set(separator_command);
        add_command_set(spoolss_commands);
+       add_command_set(separator_command);
        add_command_set(lsarpc_commands);
+       add_command_set(separator_command);
        add_command_set(samr_commands);
+       add_command_set(separator_command);
 
 
        /* Do anything specified with -c */