]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsaddsmb.c
d4876a089126e55bc1445ebb6bba9edaadc1f27f
2 * "$Id: cupsaddsmb.c,v 1.3 2001/12/18 21:08:21 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 *subcmd
) /* I - Sub-command */
127 int status
; /* Status of command */
128 char temp
[4096]; /* Command/prompt string */
129 static const char *p
= NULL
; /* Password data */
135 snprintf(temp
, sizeof(temp
), "%s -N -U\'%s%%%s\' %s -c \'%s\'",
136 command
, cupsUser(), p
, args
, subcmd
);
138 snprintf(temp
, sizeof(temp
), "%s -N -U\'%s\' %s -c \'%s\'",
139 command
, cupsUser(), args
, subcmd
);
142 printf("Running command: %s\n", temp
);
145 strncat(temp
, " </dev/null >/dev/null 2>/dev/null", sizeof(temp
) - 1);
146 temp
[sizeof(temp
) - 1] = '\0';
150 printf("Running the following command:\n\n %s\n", temp
);
153 strncat(temp
, " >/dev/null 2>/dev/null", sizeof(temp
) - 1);
154 temp
[sizeof(temp
) - 1] = '\0';
157 if ((status
= system(temp
)) != 0)
162 snprintf(temp
, sizeof(temp
),
163 "Password for %s required to access %s via SAMBA: ",
164 cupsUser(), cupsServer());
166 if ((p
= cupsGetPassword(temp
)) == NULL
)
183 * 'export_dest()' - Export a destination to SAMBA.
186 int /* O - 0 on success, non-zero on error */
187 export_dest(const char *dest
) /* I - Destination to export */
189 int status
; /* Status of smbclient/rpcclient commands */
190 const char *ppdfile
; /* PPD file for printer drivers */
191 char command
[1024], /* Command to run */
192 subcmd
[1024]; /* Sub-command */
193 const char *datadir
; /* CUPS_DATADIR */
196 if ((datadir
= getenv("CUPS_DATADIR")) == NULL
)
197 datadir
= CUPS_DATADIR
;
199 /* Get the PPD file... */
200 if ((ppdfile
= cupsGetPPD(dest
)) == NULL
)
202 fprintf(stderr
, "Warning: No PPD file for printer \"%s\"!\n", dest
);
206 /* Do the smbclient commands needed for the Windows drivers... */
207 snprintf(command
, sizeof(command
), "smbclient //%s/print\\$", cupsServer());
209 snprintf(subcmd
, sizeof(subcmd
),
211 "put %s W32X86/%s.PPD;"
212 "put %s/drivers/ADOBEPS5.DLL W32X86/ADOBEPS5.DLL;"
213 "put %s/drivers/ADOBEPSU.DLL W32X86/ADOBEPSU.DLL;"
214 "put %s/drivers/ADOBEPSU.HLP W32X86/ADOBEPSU.HLP",
215 ppdfile
, dest
, datadir
, datadir
, datadir
);
217 if ((status
= do_samba_command(command
, "", subcmd
)) != 0)
219 fprintf(stderr
, "ERROR: Unable to copy Windows printer driver files (%d)!\n",
225 snprintf(subcmd
, sizeof(subcmd
),
227 "put %s WIN40/%s.PPD;"
228 "put %s/drivers/ADFONTS.MFM WIN40/ADFONTS.MFM;"
229 "put %s/drivers/ADOBEPS4.DRV WIN40/ADOBEPS4.DRV;"
230 "put %s/drivers/ADOBEPS4.HLP WIN40/ADOBEPS4.HLP;"
231 "put %s/drivers/DEFPRTR2.PPD WIN40/DEFPRTR2.PPD;"
232 "put %s/drivers/ICONLIB.DLL WIN40/ICONLIB.DLL;"
233 "put %s/drivers/PSMON.DLL WIN40/PSMON.DLL;",
234 ppdfile
, dest
, datadir
, datadir
, datadir
,
235 datadir
, datadir
, datadir
);
237 if ((status
= do_samba_command(command
, "", subcmd
)) != 0)
239 fprintf(stderr
, "ERROR: Unable to copy Windows printer driver files (%d)!\n",
247 /* Do the rpcclient commands needed for the Windows drivers... */
248 snprintf(subcmd
, sizeof(subcmd
),
249 "adddriver \"Windows NT x86\" \"%s:ADOBEPS5.DLL:%s.PPD:ADOBEPSU.DLL:ADOBEPSU.HLP:NULL:RAW:NULL\"",
252 if ((status
= do_samba_command("rpcclient", cupsServer(), subcmd
)) != 0)
254 fprintf(stderr
, "ERROR: Unable to install Windows printer driver files (%d)!\n",
259 snprintf(subcmd
, sizeof(subcmd
), "addprinter %s %s \"%s\" \"\"",
262 if ((status
= do_samba_command("rpcclient", cupsServer(), subcmd
)) != 0)
264 fprintf(stderr
, "ERROR: Unable to install Windows printer driver files (%d)!\n",
269 snprintf(subcmd
, sizeof(subcmd
),
270 "adddriver \"Windows 4.0\" \"%s:ADOBEPS4.DRV:%s.PPD:NULL:ADOBEPS4.HLP:PSMON.DLL:RAW:ADFONTS.MFM,DEFPRTR2.PPD,ICONLIB.DLL\"",
273 if ((status
= do_samba_command("rpcclient", cupsServer(), subcmd
)) != 0)
275 fprintf(stderr
, "ERROR: Unable to install Windows printer driver files (%d)!\n",
285 * End of "$Id: cupsaddsmb.c,v 1.3 2001/12/18 21:08:21 mike Exp $".