2 Unix SMB/Netbios implementation.
6 Copyright (C) Gerald Carter 2001
7 Copyright (C) Tim Potter 2000
8 Copyright (C) Andrew Tridgell 1992-1999
9 Copyright (C) Luke Kenneth Casson Leighton 1996-1999
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 extern int DEBUGLEVEL;
30 extern pstring server;
31 extern pstring global_myname;
32 extern pstring username, password;
33 extern pstring workgroup;
41 struct table_node archi_table[]= {
43 {"Windows 4.0", "WIN40", 0 },
44 {"Windows NT x86", "W32X86", 2 },
45 {"Windows NT R4000", "W32MIPS", 2 },
46 {"Windows NT Alpha_AXP", "W32ALPHA", 2 },
47 {"Windows NT PowerPC", "W32PPC", 2 },
51 /****************************************************************************
52 function to do the mapping between the long architecture name and
54 ****************************************************************************/
55 BOOL get_short_archi(char *short_archi, char *long_archi)
59 DEBUG(107,("Getting architecture dependant directory\n"));
62 } while ( (archi_table[i].long_archi!=NULL ) &&
63 StrCaseCmp(long_archi, archi_table[i].long_archi) );
65 if (archi_table[i].long_archi==NULL) {
66 DEBUGADD(10,("Unknown architecture [%s] !\n", long_archi));
70 StrnCpy (short_archi, archi_table[i].short_archi, strlen(archi_table[i].short_archi));
72 DEBUGADD(108,("index: [%d]\n", i));
73 DEBUGADD(108,("long architecture: [%s]\n", long_archi));
74 DEBUGADD(108,("short architecture: [%s]\n", short_archi));
80 /**********************************************************************
81 * dummy function -- placeholder
83 static uint32 cmd_spoolss_not_implemented (struct cli_state *cli,
84 int argc, char **argv)
86 printf ("(*) This command is not currently implemented.\n");
87 return NT_STATUS_NO_PROBLEMO;
90 /****************************************************************************
91 display sec_ace structure
92 ****************************************************************************/
93 static void display_sec_ace(SEC_ACE *ace)
97 sid_to_string(sid_str, &ace->sid);
98 printf("\t\tSID: %s\n", sid_str);
100 printf("\t\ttype:[%d], flags:[0x%02x], mask:[0x%08x]\n",
101 ace->type, ace->flags, ace->info.mask);
104 /****************************************************************************
105 display sec_acl structure
106 ****************************************************************************/
107 static void display_sec_acl(SEC_ACL *acl)
109 if (acl->size != 0 && acl->num_aces != 0) {
112 printf("\t\tRevision:[%d]\n", acl->revision);
113 for (i = 0; i < acl->num_aces; i++) {
114 display_sec_ace(&acl->ace[i]);
119 /****************************************************************************
120 display sec_desc structure
121 ****************************************************************************/
122 static void display_sec_desc(SEC_DESC *sec)
126 printf("\tRevision:[%d]\n", sec->revision);
128 if (sec->off_owner_sid) {
129 sid_to_string(sid_str, sec->owner_sid);
130 printf("\tOwner SID: %s\n", sid_str);
133 if (sec->off_grp_sid) {
134 sid_to_string(sid_str, sec->grp_sid);
135 printf("\tGroup SID: %s\n", sid_str);
138 if (sec->off_sacl) display_sec_acl(sec->sacl);
139 if (sec->off_dacl) display_sec_acl(sec->dacl);
142 /***********************************************************************
143 * Get printer information
145 static uint32 cmd_spoolss_open_printer_ex(struct cli_state *cli, int argc, char **argv)
147 uint32 result = NT_STATUS_UNSUCCESSFUL;
149 fstring server, user;
153 printf("Usage: openprinter <printername>\n");
154 return NT_STATUS_NOPROBLEMO;
158 return NT_STATUS_UNSUCCESSFUL;
161 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
163 fstrcpy (user, cli->user_name);
164 fstrcpy (printername, argv[1]);
167 /* Initialise RPC connection */
168 if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
169 fprintf (stderr, "Could not initialize spoolss pipe!\n");
170 return NT_STATUS_UNSUCCESSFUL;
173 /* Open the printer handle */
174 result = cli_spoolss_open_printer_ex (cli, printername, "",
175 MAXIMUM_ALLOWED_ACCESS, server, user, &hnd);
177 if (result == NT_STATUS_NOPROBLEMO) {
178 printf ("Printer %s opened successfully\n", printername);
179 result = cli_spoolss_close_printer (cli, &hnd);
180 if (result != NT_STATUS_NOPROBLEMO) {
181 printf ("Error closing printer handle! (%s)\n", get_nt_error_msg(result));
185 cli_nt_session_close(cli);
191 /****************************************************************************
192 printer info level 0 display function
193 ****************************************************************************/
194 static void display_print_info_0(PRINTER_INFO_0 *i1)
199 unistr_to_ascii(name, i1->printername.buffer, sizeof(name) - 1);
200 unistr_to_ascii(the_server, i1->servername.buffer, sizeof(the_server) - 1);
202 printf("\tprintername:[%s]\n", name);
203 printf("\tservername:[%s]\n", the_server);
204 printf("\tcjobs:[0x%x]\n", i1->cjobs);
205 printf("\ttotal_jobs:[0x%x]\n", i1->total_jobs);
207 printf("\t:date: [%d]-[%d]-[%d] (%d)\n", i1->year, i1->month,
208 i1->day, i1->dayofweek);
209 printf("\t:time: [%d]-[%d]-[%d]-[%d]\n", i1->hour, i1->minute,
210 i1->second, i1->milliseconds);
212 printf("\tglobal_counter:[0x%x]\n", i1->global_counter);
213 printf("\ttotal_pages:[0x%x]\n", i1->total_pages);
215 printf("\tmajorversion:[0x%x]\n", i1->major_version);
216 printf("\tbuildversion:[0x%x]\n", i1->build_version);
218 printf("\tunknown7:[0x%x]\n", i1->unknown7);
219 printf("\tunknown8:[0x%x]\n", i1->unknown8);
220 printf("\tunknown9:[0x%x]\n", i1->unknown9);
221 printf("\tsession_counter:[0x%x]\n", i1->session_counter);
222 printf("\tunknown11:[0x%x]\n", i1->unknown11);
223 printf("\tprinter_errors:[0x%x]\n", i1->printer_errors);
224 printf("\tunknown13:[0x%x]\n", i1->unknown13);
225 printf("\tunknown14:[0x%x]\n", i1->unknown14);
226 printf("\tunknown15:[0x%x]\n", i1->unknown15);
227 printf("\tunknown16:[0x%x]\n", i1->unknown16);
228 printf("\tchange_id:[0x%x]\n", i1->change_id);
229 printf("\tunknown18:[0x%x]\n", i1->unknown18);
230 printf("\tstatus:[0x%x]\n", i1->status);
231 printf("\tunknown20:[0x%x]\n", i1->unknown20);
232 printf("\tc_setprinter:[0x%x]\n", i1->c_setprinter);
233 printf("\tunknown22:[0x%x]\n", i1->unknown22);
234 printf("\tunknown23:[0x%x]\n", i1->unknown23);
235 printf("\tunknown24:[0x%x]\n", i1->unknown24);
236 printf("\tunknown25:[0x%x]\n", i1->unknown25);
237 printf("\tunknown26:[0x%x]\n", i1->unknown26);
238 printf("\tunknown27:[0x%x]\n", i1->unknown27);
239 printf("\tunknown28:[0x%x]\n", i1->unknown28);
240 printf("\tunknown29:[0x%x]\n", i1->unknown29);
243 /****************************************************************************
244 printer info level 1 display function
245 ****************************************************************************/
246 static void display_print_info_1(PRINTER_INFO_1 *i1)
252 unistr_to_ascii(desc, i1->description.buffer, sizeof(desc) - 1);
253 unistr_to_ascii(name, i1->name .buffer, sizeof(name) - 1);
254 unistr_to_ascii(comm, i1->comment .buffer, sizeof(comm) - 1);
256 printf("\tflags:[0x%x]\n", i1->flags);
257 printf("\tname:[%s]\n", name);
258 printf("\tdescription:[%s]\n", desc);
259 printf("\tcomment:[%s]\n\n", comm);
262 /****************************************************************************
263 printer info level 2 display function
264 ****************************************************************************/
265 static void display_print_info_2(PRINTER_INFO_2 *i2)
275 fstring printprocessor;
279 unistr_to_ascii(servername, i2->servername.buffer,
280 sizeof(servername) - 1);
281 unistr_to_ascii(printername, i2->printername.buffer,
282 sizeof(printername) - 1);
283 unistr_to_ascii(sharename, i2->sharename.buffer,
284 sizeof(sharename) - 1);
285 unistr_to_ascii(portname, i2->portname.buffer, sizeof(portname) - 1);
286 unistr_to_ascii(drivername, i2->drivername.buffer,
287 sizeof(drivername) - 1);
288 unistr_to_ascii(comment, i2->comment.buffer, sizeof(comment) - 1);
289 unistr_to_ascii(location, i2->location.buffer, sizeof(location) - 1);
290 unistr_to_ascii(sepfile, i2->sepfile.buffer, sizeof(sepfile) - 1);
291 unistr_to_ascii(printprocessor, i2->printprocessor.buffer,
292 sizeof(printprocessor) - 1);
293 unistr_to_ascii(datatype, i2->datatype.buffer, sizeof(datatype) - 1);
294 unistr_to_ascii(parameters, i2->parameters.buffer,
295 sizeof(parameters) - 1);
297 printf("\tservername:[%s]\n", servername);
298 printf("\tprintername:[%s]\n", printername);
299 printf("\tsharename:[%s]\n", sharename);
300 printf("\tportname:[%s]\n", portname);
301 printf("\tdrivername:[%s]\n", drivername);
302 printf("\tcomment:[%s]\n", comment);
303 printf("\tlocation:[%s]\n", location);
304 printf("\tsepfile:[%s]\n", sepfile);
305 printf("\tprintprocessor:[%s]\n", printprocessor);
306 printf("\tdatatype:[%s]\n", datatype);
307 printf("\tparameters:[%s]\n", parameters);
308 printf("\tattributes:[0x%x]\n", i2->attributes);
309 printf("\tpriority:[0x%x]\n", i2->priority);
310 printf("\tdefaultpriority:[0x%x]\n", i2->defaultpriority);
311 printf("\tstarttime:[0x%x]\n", i2->starttime);
312 printf("\tuntiltime:[0x%x]\n", i2->untiltime);
313 printf("\tstatus:[0x%x]\n", i2->status);
314 printf("\tcjobs:[0x%x]\n", i2->cjobs);
315 printf("\taverageppm:[0x%x]\n", i2->averageppm);
317 if (i2->secdesc) display_sec_desc(i2->secdesc);
320 /****************************************************************************
321 printer info level 3 display function
322 ****************************************************************************/
323 static void display_print_info_3(PRINTER_INFO_3 *i3)
325 printf("\tflags:[0x%x]\n", i3->flags);
327 display_sec_desc(i3->secdesc);
330 /* Enumerate printers */
332 static uint32 cmd_spoolss_enum_printers(struct cli_state *cli, int argc, char **argv)
334 uint32 result = NT_STATUS_UNSUCCESSFUL,
336 PRINTER_INFO_CTR ctr;
342 printf("Usage: enumprinters [level]\n");
343 return NT_STATUS_NOPROBLEMO;
347 info_level = atoi(argv[1]);
350 /* Initialise RPC connection */
351 if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
352 fprintf (stderr, "Could not initialize spoolss pipe!\n");
353 return NT_STATUS_UNSUCCESSFUL;
356 /* Enumerate printers -- Should we enumerate types other
357 than PRINTER_ENUM_LOCAL? Maybe accept as a parameter? --jerry */
359 result = cli_spoolss_enum_printers(cli, PRINTER_ENUM_LOCAL,
360 info_level, &returned, &ctr);
362 if (result == NT_STATUS_NOPROBLEMO) {
365 for (i=0; i<returned; i++) {
366 display_print_info_0(&(ctr.printers_0[i]));
370 for (i=0; i<returned; i++) {
371 display_print_info_1(&(ctr.printers_1[i]));
375 for (i=0; i<returned; i++) {
376 display_print_info_2(&(ctr.printers_2[i]));
380 for (i=0; i<returned; i++) {
381 display_print_info_3(&(ctr.printers_3[i]));
385 printf("unknown info level %d\n", info_level);
390 cli_nt_session_close(cli);
395 /****************************************************************************
396 port info level 1 display function
397 ****************************************************************************/
398 static void display_port_info_1(PORT_INFO_1 *i1)
402 unistr_to_ascii(buffer, i1->port_name.buffer, sizeof(buffer)-1);
403 printf("\tPort Name:\t[%s]\n", buffer);
406 /****************************************************************************
407 port info level 2 display function
408 ****************************************************************************/
409 static void display_port_info_2(PORT_INFO_2 *i2)
413 unistr_to_ascii(buffer, i2->port_name.buffer, sizeof(buffer) - 1);
414 printf("\tPort Name:\t[%s]\n", buffer);
415 unistr_to_ascii(buffer, i2->monitor_name.buffer, sizeof(buffer) - 1);
416 printf("\tMonitor Name:\t[%s]\n", buffer);
417 unistr_to_ascii(buffer, i2->description.buffer, sizeof(buffer) - 1);
418 printf("\tDescription:\t[%s]\n", buffer);
419 printf("\tPort Type:\t[%d]\n", i2->port_type);
420 printf("\tReserved:\t[%d]\n", i2->reserved);
424 /* Enumerate ports */
426 static uint32 cmd_spoolss_enum_ports(struct cli_state *cli, int argc, char **argv)
428 uint32 result = NT_STATUS_UNSUCCESSFUL,
434 printf("Usage: enumports [level]\n");
435 return NT_STATUS_NOPROBLEMO;
439 info_level = atoi(argv[1]);
442 /* Initialise RPC connection */
443 if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
444 fprintf (stderr, "Could not initialize spoolss pipe!\n");
445 return NT_STATUS_UNSUCCESSFUL;
448 /* Enumerate ports */
451 result = cli_spoolss_enum_ports(cli, info_level, &returned, &ctr);
453 if (result == NT_STATUS_NOPROBLEMO) {
456 for (i = 0; i < returned; i++) {
457 switch (info_level) {
459 display_port_info_1(&ctr.port.info_1[i]);
462 display_port_info_2(&ctr.port.info_2[i]);
465 printf("unknown info level %d\n", info_level);
471 cli_nt_session_close(cli);
476 /***********************************************************************
477 * Get printer information
479 static uint32 cmd_spoolss_getprinter(struct cli_state *cli, int argc, char **argv)
484 BOOL opened_hnd = False;
485 PRINTER_INFO_CTR ctr;
490 if (argc == 1 || argc > 3) {
491 printf("Usage: %s printername [level]\n", argv[0]);
492 return NT_STATUS_NOPROBLEMO;
495 /* Initialise RPC connection */
496 if (!cli_nt_session_open (cli, PIPE_SPOOLSS)) {
497 fprintf (stderr, "Could not initialize spoolss pipe!\n");
498 return NT_STATUS_UNSUCCESSFUL;
501 /* Open a printer handle */
503 info_level = atoi(argv[2]);
506 slprintf (servername, sizeof(fstring)-1, "\\\\%s", cli->desthost);
507 strupper (servername);
508 slprintf (printername, sizeof(fstring)-1, "\\\\%s\\%s", servername, argv[1]);
509 fstrcpy (username, cli->user_name);
511 /* get a printer handle */
512 if ((result = cli_spoolss_open_printer_ex(
513 cli, printername, "", MAXIMUM_ALLOWED_ACCESS, servername,
514 username, &pol)) != NT_STATUS_NOPROBLEMO) {
520 /* Get printer info */
521 if ((result = cli_spoolss_getprinter(cli, &pol, info_level, &ctr))
522 != NT_STATUS_NOPROBLEMO) {
526 /* Display printer info */
528 switch (info_level) {
530 display_print_info_0(ctr.printers_0);
533 display_print_info_1(ctr.printers_1);
536 display_print_info_2(ctr.printers_2);
539 display_print_info_3(ctr.printers_3);
542 printf("unknown info level %d\n", info_level);
548 cli_spoolss_close_printer(cli, &pol);
550 cli_nt_session_close(cli);
555 /****************************************************************************
556 printer info level 0 display function
557 ****************************************************************************/
558 static void display_print_driver_1(DRIVER_INFO_1 *i1)
564 unistr_to_ascii(name, i1->name.buffer, sizeof(name)-1);
566 printf ("Printer Driver Info 1:\n");
567 printf ("\tDriver Name: [%s]\n\n", name);
572 /****************************************************************************
573 printer info level 1 display function
574 ****************************************************************************/
575 static void display_print_driver_2(DRIVER_INFO_2 *i1)
578 fstring architecture;
585 unistr_to_ascii(name, i1->name.buffer, sizeof(name)-1);
586 unistr_to_ascii(architecture, i1->architecture.buffer, sizeof(architecture)-1);
587 unistr_to_ascii(driverpath, i1->driverpath.buffer, sizeof(driverpath)-1);
588 unistr_to_ascii(datafile, i1->datafile.buffer, sizeof(datafile)-1);
589 unistr_to_ascii(configfile, i1->configfile.buffer, sizeof(configfile)-1);
591 printf ("Printer Driver Info 2:\n");
592 printf ("\tVersion: [%x]\n", i1->version);
593 printf ("\tDriver Name: [%s]\n", name);
594 printf ("\tArchitecture: [%s]\n", architecture);
595 printf ("\tDriver Path: [%s]\n", driverpath);
596 printf ("\tDatafile: [%s]\n", datafile);
597 printf ("\tConfigfile: [%s]\n\n", configfile);
602 /****************************************************************************
603 printer info level 2 display function
604 ****************************************************************************/
605 static void display_print_driver_3(DRIVER_INFO_3 *i1)
608 fstring architecture;
613 fstring dependentfiles;
615 fstring defaultdatatype;
623 unistr_to_ascii(name, i1->name.buffer, sizeof(name)-1);
624 unistr_to_ascii(architecture, i1->architecture.buffer, sizeof(architecture)-1);
625 unistr_to_ascii(driverpath, i1->driverpath.buffer, sizeof(driverpath)-1);
626 unistr_to_ascii(datafile, i1->datafile.buffer, sizeof(datafile)-1);
627 unistr_to_ascii(configfile, i1->configfile.buffer, sizeof(configfile)-1);
628 unistr_to_ascii(helpfile, i1->helpfile.buffer, sizeof(helpfile)-1);
630 unistr_to_ascii(monitorname, i1->monitorname.buffer, sizeof(monitorname)-1);
631 unistr_to_ascii(defaultdatatype, i1->defaultdatatype.buffer, sizeof(defaultdatatype)-1);
633 printf ("Printer Driver Info 3:\n");
634 printf ("\tVersion: [%x]\n", i1->version);
635 printf ("\tDriver Name: [%s]\n",name );
636 printf ("\tArchitecture: [%s]\n", architecture);
637 printf ("\tDriver Path: [%s]\n", driverpath);
638 printf ("\tDatafile: [%s]\n", datafile);
639 printf ("\tConfigfile: [%s]\n", configfile);
640 printf ("\tHelpfile: [%s]\n\n", helpfile);
644 unistr_to_ascii(dependentfiles, i1->dependentfiles+length, sizeof(dependentfiles)-1);
645 length+=strlen(dependentfiles)+1;
647 if (strlen(dependentfiles) > 0)
649 printf ("\tDependentfiles: [%s]\n", dependentfiles);
659 printf ("\tMonitorname: [%s]\n", monitorname);
660 printf ("\tDefaultdatatype: [%s]\n\n", defaultdatatype);
665 /***********************************************************************
666 * Get printer information
668 static uint32 cmd_spoolss_getdriver(struct cli_state *cli, int argc, char **argv)
673 BOOL opened_hnd = False;
674 PRINTER_DRIVER_CTR ctr;
680 if ((argc == 1) || (argc > 3))
682 printf("Usage: %s <printername> [level]\n", argv[0]);
683 return NT_STATUS_NOPROBLEMO;
686 /* Initialise RPC connection */
687 if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
689 fprintf (stderr, "Could not initialize spoolss pipe!\n");
690 return NT_STATUS_UNSUCCESSFUL;
693 /* get the arguments need to open the printer handle */
694 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
696 fstrcpy (user, cli->user_name);
697 fstrcpy (printername, argv[1]);
699 info_level = atoi(argv[2]);
701 /* Open a printer handle */
702 if ((result=cli_spoolss_open_printer_ex (cli, printername, "",
703 MAXIMUM_ALLOWED_ACCESS, server, user, &pol)) != NT_STATUS_NO_PROBLEMO)
705 printf ("Error opening printer handle for %s!\n", printername);
711 /* loop through and print driver info level for each architecture */
712 for (i=0; archi_table[i].long_archi!=NULL; i++)
714 result = cli_spoolss_getprinterdriver (cli, &pol, info_level,
715 archi_table[i].long_archi, &ctr);
719 case NT_STATUS_NO_PROBLEMO:
722 case ERROR_UNKNOWN_PRINTER_DRIVER:
726 printf ("Error getting driver for %s [%s] - %s\n", printername,
727 archi_table[i].long_archi, get_nt_error_msg(result));
732 printf ("\n[%s]\n", archi_table[i].long_archi);
737 display_print_driver_1 (ctr.info1);
740 display_print_driver_2 (ctr.info2);
743 display_print_driver_3 (ctr.info3);
746 printf("unknown info level %d\n", info_level);
756 cli_spoolss_close_printer (cli, &pol);
757 cli_nt_session_close (cli);
759 if (result==ERROR_UNKNOWN_PRINTER_DRIVER)
760 return NT_STATUS_NO_PROBLEMO;
766 /***********************************************************************
767 * Get printer information
769 static uint32 cmd_spoolss_enum_drivers(struct cli_state *cli, int argc, char **argv)
773 PRINTER_DRIVER_CTR ctr;
780 printf("Usage: enumdrivers [level]\n");
781 return NT_STATUS_NOPROBLEMO;
784 /* Initialise RPC connection */
785 if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
787 fprintf (stderr, "Could not initialize spoolss pipe!\n");
788 return NT_STATUS_UNSUCCESSFUL;
791 /* get the arguments need to open the printer handle */
792 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
795 info_level = atoi(argv[1]);
798 /* loop through and print driver info level for each architecture */
799 for (i=0; archi_table[i].long_archi!=NULL; i++)
802 result = cli_spoolss_enumprinterdrivers (cli, info_level,
803 archi_table[i].long_archi, &returned, &ctr);
809 if (result != NT_STATUS_NO_PROBLEMO)
811 printf ("Error getting driver for environment [%s] - %s\n",
812 archi_table[i].long_archi, get_nt_error_msg(result));
816 printf ("\n[%s]\n", archi_table[i].long_archi);
821 for (j=0; j < returned; j++) {
822 display_print_driver_1 (&(ctr.info1[j]));
826 for (j=0; j < returned; j++) {
827 display_print_driver_2 (&(ctr.info2[j]));
831 for (j=0; j < returned; j++) {
832 display_print_driver_3 (&(ctr.info3[j]));
836 printf("unknown info level %d\n", info_level);
843 cli_nt_session_close (cli);
845 if (result==ERROR_UNKNOWN_PRINTER_DRIVER)
846 return NT_STATUS_NO_PROBLEMO;
852 /****************************************************************************
853 printer info level 1 display function
854 ****************************************************************************/
855 static void display_printdriverdir_1(DRIVER_DIRECTORY_1 *i1)
861 unistr_to_ascii(name, i1->name.buffer, sizeof(name)-1);
863 printf ("\tDirectory Name:[%s]\n", name);
866 /***********************************************************************
867 * Get printer driver directory information
869 static uint32 cmd_spoolss_getdriverdir(struct cli_state *cli, int argc, char **argv)
873 DRIVER_DIRECTORY_CTR ctr;
877 printf("Usage: %s [environment]\n", argv[0]);
878 return NT_STATUS_NOPROBLEMO;
881 /* Initialise RPC connection */
882 if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
884 fprintf (stderr, "Could not initialize spoolss pipe!\n");
885 return NT_STATUS_UNSUCCESSFUL;
888 /* get the arguments need to open the printer handle */
890 fstrcpy (env, argv[1]);
892 fstrcpy (env, "Windows NT x86");
894 /* Get the directory. Only use Info level 1 */
895 if ((result = cli_spoolss_getprinterdriverdir (cli, 1, env, &ctr))
896 != NT_STATUS_NO_PROBLEMO)
902 display_printdriverdir_1 (ctr.info1);
905 cli_nt_session_close (cli);
911 /*******************************************************************************
912 set the version and environment fields of a DRIVER_INFO_3 struct
913 ******************************************************************************/
914 void set_drv_info_3_env (DRIVER_INFO_3 *info, const char *arch)
919 for (i=0; archi_table[i].long_archi != NULL; i++)
921 if (strcmp(arch, archi_table[i].short_archi) == 0)
923 info->version = archi_table[i].version;
924 init_unistr (&info->architecture, archi_table[i].long_archi);
929 if (archi_table[i].long_archi == NULL)
931 DEBUG(0, ("set_drv_info_3_env: Unknown arch [%s]\n", arch));
938 /**************************************************************************
939 wrapper for strtok to get the next parameter from a delimited list.
940 Needed to handle the empty parameter string denoted by "NULL"
941 *************************************************************************/
942 static char* get_driver_3_param (char* str, char* delim, UNISTR* dest)
946 /* get the next token */
947 ptr = strtok(str, delim);
949 /* a string of 'NULL' is used to represent an empty
950 parameter because two consecutive delimiters
951 will not return an empty string. See man strtok(3)
953 if (StrCaseCmp(ptr, "NULL") == 0)
957 init_unistr(dest, ptr);
962 /********************************************************************************
963 fill in the members of a DRIVER_INFO_3 struct using a character
964 string in the form of
965 <Long Printer Name>:<Driver File Name>:<Data File Name>:\
966 <Config File Name>:<Help File Name>:<Language Monitor Name>:\
967 <Default Data Type>:<Comma Separated list of Files>
968 *******************************************************************************/
969 static BOOL init_drv_info_3_members (DRIVER_INFO_3 *info, char *args)
974 /* fill in the UNISTR fields */
975 str = get_driver_3_param (args, ":", &info->name);
976 str = get_driver_3_param (NULL, ":", &info->driverpath);
977 str = get_driver_3_param (NULL, ":", &info->datafile);
978 str = get_driver_3_param (NULL, ":", &info->configfile);
979 str = get_driver_3_param (NULL, ":", &info->helpfile);
980 str = get_driver_3_param (NULL, ":", &info->monitorname);
981 str = get_driver_3_param (NULL, ":", &info->defaultdatatype);
983 /* <Comma Separated List of Dependent Files> */
984 str2 = get_driver_3_param (NULL, ":", NULL); /* save the beginning of the string */
987 /* begin to strip out each filename */
988 str = strtok(str, ",");
992 /* keep a cumlative count of the str lengths */
993 len += strlen(str)+1;
994 str = strtok(NULL, ",");
997 /* allocate the space; add one extra slot for a terminating NULL.
998 Each filename is NULL terminated and the end contains a double
1000 if ((info->dependentfiles=(uint16*)malloc((len+1)*sizeof(uint16))) == NULL)
1002 DEBUG(0,("init_drv_info_3_members: Unable to malloc memory for dependenfiles\n"));
1005 for (i=0; i<len; i++)
1007 info->dependentfiles[i] = (uint16)str2[i];
1009 info->dependentfiles[len] = '\0';
1015 static uint32 cmd_spoolss_addprinterdriver (struct cli_state *cli, int argc, char **argv)
1019 PRINTER_DRIVER_CTR ctr;
1020 DRIVER_INFO_3 info3;
1022 fstring driver_name;
1024 /* parse the command arguements */
1027 printf ("Usage: %s <Environment>\\\n", argv[0]);
1028 printf ("\t<Long Printer Name>:<Driver File Name>:<Data File Name>:\\\n");
1029 printf ("\t<Config File Name>:<Help File Name>:<Language Monitor Name>:\\\n");
1030 printf ("\t<Default Data Type>:<Comma Separated list of Files>\n");
1032 return NT_STATUS_NOPROBLEMO;
1035 /* Initialise RPC connection */
1036 if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
1038 fprintf (stderr, "Could not initialize spoolss pipe!\n");
1039 return NT_STATUS_UNSUCCESSFUL;
1043 /* Fill in the DRIVER_INFO_3 struct */
1045 if (!get_short_archi(arch, argv[1]))
1047 printf ("Error Unknown architechture [%s]\n", argv[1]);
1048 return NT_STATUS_INVALID_PARAMETER;
1051 set_drv_info_3_env(&info3, arch);
1053 if (!init_drv_info_3_members(&info3, argv[2]))
1055 printf ("Error Invalid parameter list - %s.\n", argv[2]);
1056 return NT_STATUS_INVALID_PARAMETER;
1060 /* Get the directory. Only use Info level 1 */
1062 if ((result = cli_spoolss_addprinterdriver (cli, level, &ctr))
1063 != NT_STATUS_NO_PROBLEMO)
1068 unistr_to_ascii (driver_name, info3.name.buffer, sizeof(driver_name)-1);
1069 printf ("Printer Driver %s successfully installed.\n", driver_name);
1072 cli_nt_session_close (cli);
1079 static uint32 cmd_spoolss_addprinterex (struct cli_state *cli, int argc, char **argv)
1083 PRINTER_INFO_CTR ctr;
1084 PRINTER_INFO_2 info2;
1087 /* parse the command arguements */
1090 printf ("Usage: %s <name> <shared name> <driver> <port>\n", argv[0]);
1091 return NT_STATUS_NOPROBLEMO;
1094 slprintf (server, sizeof(fstring)-1, "\\\\%s", cli->desthost);
1097 /* Initialise RPC connection */
1098 if (!cli_nt_session_open (cli, PIPE_SPOOLSS))
1100 fprintf (stderr, "Could not initialize spoolss pipe!\n");
1101 return NT_STATUS_UNSUCCESSFUL;
1105 /* Fill in the DRIVER_INFO_3 struct */
1108 init_unistr( &info2.servername, server);
1110 init_unistr( &info2.printername, argv[1]);
1111 init_unistr( &info2.sharename, argv[2]);
1112 init_unistr( &info2.drivername, argv[3]);
1113 init_unistr( &info2.portname, argv[4]);
1114 init_unistr( &info2.comment, "Created by rpcclient");
1115 init_unistr( &info2.printprocessor, "winprint");
1116 init_unistr( &info2.datatype, "RAW");
1117 info2.devmode = NULL;
1118 info2.secdesc = NULL;
1119 info2.attributes = PRINTER_ATTRIBUTE_SHARED;
1121 info2.defaultpriority = 0;
1122 info2.starttime = 0;
1123 info2.untiltime = 0;
1125 /* These three fields must not be used by AddPrinter()
1126 as defined in the MS Platform SDK documentation..
1130 info2.averageppm = 0;
1135 /* Get the directory. Only use Info level 1 */
1136 ctr.printers_2 = &info2;
1137 if ((result = cli_spoolss_addprinterex (cli, level, &ctr))
1138 != NT_STATUS_NO_PROBLEMO)
1143 printf ("Printer %s successfully installed.\n", argv[1]);
1146 cli_nt_session_close (cli);
1153 /* List of commands exported by this module */
1154 struct cmd_set spoolss_commands[] = {
1156 { "SPOOLSS", NULL, "" },
1157 { "adddriver", cmd_spoolss_addprinterdriver, "Add a print driver" },
1158 { "addprinter", cmd_spoolss_addprinterex, "Add a printer" },
1159 { "enumdata", cmd_spoolss_not_implemented, "Enumerate printer data (*)" },
1160 { "enumjobs", cmd_spoolss_not_implemented, "Enumerate print jobs (*)" },
1161 { "enumports", cmd_spoolss_enum_ports, "Enumerate printer ports" },
1162 { "enumdrivers", cmd_spoolss_enum_drivers, "Enumerate installed printer drivers" },
1163 { "enumprinters", cmd_spoolss_enum_printers, "Enumerate printers" },
1164 { "getdata", cmd_spoolss_not_implemented, "Get print driver data (*)" },
1165 { "getdriver", cmd_spoolss_getdriver, "Get print driver information" },
1166 { "getdriverdir", cmd_spoolss_getdriverdir, "Get print driver upload directory" },
1167 { "getprinter", cmd_spoolss_getprinter, "Get printer info" },
1168 { "openprinter", cmd_spoolss_open_printer_ex, "Open printer handle" },
1169 { NULL, NULL, NULL }