]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsaddsmb.c
2 * "$Id: cupsaddsmb.c,v 1.2 2001/11/09 17:19:44 mike Exp $"
4 * "cupsaddsmb" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2001 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Export printers on the command-line.
27 * do_samba_command() - Do a SAMBA command, asking for a password as needed.
28 * export_dest() - Export a destination to SAMBA.
32 * Include necessary headers...
37 #include <cups/cups.h>
38 #include <cups/string.h>
53 int do_samba_command(const char *, const char *, const char *);
54 int export_dest(const char *);
58 * 'main()' - Export printers on the command-line.
61 int /* O - Exit status */
62 main(int argc
, /* I - Number of command-line arguments */
63 char *argv
[]) /* I - Command-line arguments */
65 int i
, j
; /* Looping vars */
66 int status
; /* Status from export_dest() */
67 int num_printers
; /* Number of printers */
68 char **printers
; /* Printers */
71 for (i
= 1; i
< argc
; i
++)
72 if (strcmp(argv
[i
], "-a") == 0)
74 num_printers
= cupsGetPrinters(&printers
);
76 for (j
= 0, status
= 0; j
< num_printers
; j
++)
77 if ((status
= export_dest(printers
[j
])) != 0)
80 for (j
= 0; j
< num_printers
; j
++)
89 else if (strcmp(argv
[i
], "-U") == 0)
94 puts("Usage: cupsaddsmb [-a] [-U user] [-v] [printer1 ... printerN]");
100 else if (strcmp(argv
[i
], "-v") == 0)
102 else if (argv
[i
][0] != '-')
104 if ((status
= export_dest(argv
[i
])) != 0)
109 puts("Usage: cupsaddsmb [-a] [-U user] [-v] [printer1 ... printerN]");
118 * 'do_samba_command()' - Do a SAMBA command, asking for
119 * a password as needed.
122 int /* O - Status of command */
123 do_samba_command(const char *command
, /* I - Command to run */
124 const char *args
, /* I - Argument(s) for command */
125 const char *filename
) /* I - File to use as input */
127 int status
; /* Status of command */
128 char temp
[1024]; /* Command/prompt string */
129 static const char *p
= NULL
; /* Password data */
135 snprintf(temp
, sizeof(temp
), "%s -N -U \'%s%%%s\' %s <%s",
136 command
, cupsUser(), p
, args
, filename
? filename
: "/dev/null");
138 snprintf(temp
, sizeof(temp
), "%s -N -U \'%s\' %s <%s",
139 command
, cupsUser(), args
, filename
? filename
: "/dev/null");
143 printf("Running the following command:\n\n %s\n", temp
);
150 puts("\nwith the following input:\n");
152 snprintf(cat
, sizeof(cat
), "cat %s", filename
);
158 strncat(temp
, " >/dev/null 2>/dev/null", sizeof(temp
) - 1);
159 temp
[sizeof(temp
) - 1] = '\0';
162 if ((status
= system(temp
)) != 0)
167 snprintf(temp
, sizeof(temp
),
168 "Password for %s required to access %s via SAMBA: ",
169 cupsUser(), cupsServer());
171 if ((p
= cupsGetPassword(temp
)) == NULL
)
188 * 'export_dest()' - Export a destination to SAMBA.
191 int /* O - 0 on success, non-zero on error */
192 export_dest(const char *dest
) /* I - Destination to export */
194 int status
; /* Status of smbclient/rpcclient commands */
195 FILE *fp
; /* File pointer for temp file */
196 char tempfile
[1024]; /* Temporary file for print commands */
197 const char *ppdfile
; /* PPD file for printer drivers */
198 char command
[1024]; /* Command to run */
199 const char *datadir
; /* CUPS_DATADIR */
202 /* Get a temporary file for our smbclient and rpcclient commands... */
203 cupsTempFile(tempfile
, sizeof(tempfile
));
205 if ((datadir
= getenv("CUPS_DATADIR")) == NULL
)
206 datadir
= CUPS_DATADIR
;
208 /* Get the PPD file... */
209 if ((ppdfile
= cupsGetPPD(dest
)) == NULL
)
211 fprintf(stderr
, "Warning: No PPD file for printer \"%s\"!\n", dest
);
215 /* Write the smbclient commands needed for the Windows drivers... */
216 if ((fp
= fopen(tempfile
, "w")) == NULL
)
218 fprintf(stderr
, "ERROR: Unable to create temporary file \"%s\" for export - %s\n",
219 tempfile
, strerror(errno
));
224 fputs("mkdir W32X86\n", fp
);
225 fprintf(fp
, "put %s W32X86/%s.PPD\n", ppdfile
, dest
);
226 fprintf(fp
, "put %s/drivers/ADOBEPS5.DLL W32X86/ADOBEPS5.DLL\n",
228 fprintf(fp
, "put %s/drivers/ADOBEPSU.DLL W32X86/ADOBEPSU.DLL\n",
230 fprintf(fp
, "put %s/drivers/ADOBEPSU.HLP W32X86/ADOBEPSU.HLP\n",
232 fputs("mkdir WIN40\n", fp
);
233 fprintf(fp
, "put %s WIN40/%s.PPD\n", ppdfile
, dest
);
234 fprintf(fp
, "put %s/drivers/ADFONTS.MFM WIN40/ADFONTS.MFM\n",
236 fprintf(fp
, "put %s/drivers/ADOBEPS4.DRV WIN40/ADOBEPS4.DRV\n",
238 fprintf(fp
, "put %s/drivers/ADOBEPS4.HLP WIN40/ADOBEPS4.HLP\n",
240 fprintf(fp
, "put %s/drivers/DEFPRTR2.PPD WIN40/DEFPRTR2.PPD\n",
242 fprintf(fp
, "put %s/drivers/ICONLIB.DLL WIN40/ICONLIB.DLL\n",
244 fprintf(fp
, "put %s/drivers/PSMON.DLL WIN40/PSMON.DLL\n",
250 /* Run the smbclient command to copy the Windows drivers... */
251 snprintf(command
, sizeof(command
), "smbclient //%s/print\\$", cupsServer());
253 if ((status
= do_samba_command(command
, "", tempfile
)) != 0)
255 fprintf(stderr
, "ERROR: Unable to copy Windows printer driver files (%d)!\n",
264 /* Write the rpcclient commands needed for the Windows drivers... */
265 if ((fp
= fopen(tempfile
, "w")) == NULL
)
267 fprintf(stderr
, "ERROR: Unable to create temporary file \"%s\" for export - %s\n",
268 tempfile
, strerror(errno
));
273 fprintf(fp
, "adddriver \"Windows NT x86\" "
274 "\"%s:ADOBEPS5.DLL:%s.PPD:ADOBEPSU.DLL:ADOBEPSU.HLP:"
277 fprintf(fp
, "addprinter %s %s \"%s\" \"\"\n", dest
, dest
, dest
);
280 * MRS: For some reason, SAMBA doesn't like to install Win9x drivers
281 * with aux files. They are currently commented out but further
282 * investigation is required...
285 fprintf(fp
, "adddriver \"Windows 4.0\" "
286 "\"%s:ADOBEPS4.DRV:%s.PPD:NULL:ADOBEPS4.HLP:"
287 "PSMON.DLL:RAW:NULL\"\n",
288 /*"PSMON.DLL:RAW:ADFONTS.MFM,DEFPRTR2.PPD,ICONLIB.DLL\"\n",*/
294 /* Run the rpcclient command to install the Windows drivers... */
295 if ((status
= do_samba_command("rpcclient", cupsServer(), tempfile
)) != 0)
297 fprintf(stderr
, "ERROR: Unable to install Windows printer driver files (%d)!\n",
310 * End of "$Id: cupsaddsmb.c,v 1.2 2001/11/09 17:19:44 mike Exp $".