]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsaddsmb.c
2 * "$Id: cupsaddsmb.c 5233 2006-03-06 03:39:28Z mike $"
4 * "cupsaddsmb" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2001-2006 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 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Export printers on the command-line.
27 * export_dest() - Export a destination to SAMBA.
28 * usage() - Show program usage and exit...
32 * Include necessary headers...
37 #include <cups/string.h>
38 #include <cups/adminutil.h>
39 #include <cups/i18n.h>
40 #include <cups/debug.h>
52 const char *SAMBAUser
,
61 int export_dest(http_t
*http
, const char *dest
);
66 * 'main()' - Export printers on the command-line.
69 int /* O - Exit status */
70 main(int argc
, /* I - Number of command-line arguments */
71 char *argv
[]) /* I - Command-line arguments */
73 int i
, j
; /* Looping vars */
74 int status
; /* Status from export_dest() */
75 int export_all
; /* Export all printers? */
76 http_t
*http
; /* Connection to server */
77 int num_dests
; /* Number of printers */
78 cups_dest_t
*dests
; /* Printers */
82 * Parse command-line arguments...
87 SAMBAUser
= cupsUser();
91 for (i
= 1; i
< argc
; i
++)
92 if (!strcmp(argv
[i
], "-E"))
95 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
97 _cupsLangPrintf(stderr
,
98 _("%s: Sorry, no encryption support compiled in!\n"),
100 #endif /* HAVE_SSL */
102 else if (!strcmp(argv
[i
], "-H"))
108 SAMBAServer
= argv
[i
];
110 else if (!strcmp(argv
[i
], "-U"))
112 char *sep
; /* Separator for password */
121 if ((sep
= strchr(argv
[i
], '%')) != NULL
)
124 * Nul-terminate the username at the first % and point the
125 * password at the rest...
133 else if (!strcmp(argv
[i
], "-a"))
135 else if (!strcmp(argv
[i
], "-h"))
141 cupsSetServer(argv
[i
]);
143 else if (!strcmp(argv
[i
], "-v"))
145 else if (argv
[i
][0] != '-')
150 * Connect to the server...
153 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
154 cupsEncryption())) == NULL
)
156 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), argv
[0]);
161 if (SAMBAServer
== NULL
)
162 SAMBAServer
= cupsServer();
164 if ((status
= export_dest(http
, argv
[i
])) != 0)
171 * Connect to the server...
174 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
175 cupsEncryption())) == NULL
)
177 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), argv
[0]);
182 * See if the user specified "-a"...
188 * Export all printers...
191 if (SAMBAServer
== NULL
)
192 SAMBAServer
= cupsServer();
194 num_dests
= cupsGetDests2(http
, &dests
);
196 for (j
= 0, status
= 0; j
< num_dests
; j
++)
197 if (!dests
[j
].instance
)
199 if ((status
= export_dest(http
, dests
[j
].name
)) != 0)
203 cupsFreeDests(num_dests
, dests
);
214 * 'export_dest()' - Export a destination to SAMBA.
217 int /* O - 0 on success, non-zero on error */
218 export_dest(http_t
*http
, /* I - Connection to server */
219 const char *dest
) /* I - Destination to export */
221 int status
; /* Status of export */
222 char ppdfile
[1024], /* PPD file for printer drivers */
223 prompt
[1024]; /* Password prompt */
227 * Get the Windows PPD file for the printer...
230 if (!cupsAdminCreateWindowsPPD(http
, dest
, ppdfile
, sizeof(ppdfile
)))
232 _cupsLangPrintf(stderr
,
233 _("cupsaddsmb: No PPD file for printer \"%s\" - "
235 dest
, cupsLastErrorString());
240 * Try to export it...
243 for (status
= 0; !status
;)
246 * Get the password, as needed...
251 snprintf(prompt
, sizeof(prompt
),
252 _("Password for %s required to access %s via SAMBA: "),
253 SAMBAUser
, SAMBAServer
);
255 if ((SAMBAPassword
= cupsGetPassword(prompt
)) == NULL
)
259 status
= cupsAdminExportSamba(dest
, ppdfile
, SAMBAServer
,
260 SAMBAUser
, SAMBAPassword
,
261 Verbosity
? stderr
: NULL
);
271 * 'usage()' - Show program usage and exit...
277 _cupsLangPuts(stdout
,
278 _("Usage: cupsaddsmb [options] printer1 ... printerN\n"
279 " cupsaddsmb [options] -a\n"
282 " -E Encrypt the connection to the server\n"
283 " -H samba-server Use the named SAMBA server\n"
284 " -U samba-user Authenticate using the named SAMBA user\n"
285 " -a Export all printers\n"
286 " -h cups-server Use the named CUPS server\n"
287 " -v Be verbose (show commands)\n"));
293 * End of "$Id: cupsaddsmb.c 5233 2006-03-06 03:39:28Z mike $".