]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsaddsmb.c
2 * "$Id: cupsaddsmb.c 6649 2007-07-11 21:46:42Z mike $"
4 * "cupsaddsmb" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 2001-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * main() - Export printers on the command-line.
18 * export_dest() - Export a destination to SAMBA.
19 * usage() - Show program usage and exit...
23 * Include necessary headers...
28 #include <cups/string.h>
29 #include <cups/adminutil.h>
30 #include <cups/i18n.h>
31 #include <cups/debug.h>
43 const char *SAMBAUser
,
52 int export_dest(http_t
*http
, const char *dest
);
57 * 'main()' - Export printers on the command-line.
60 int /* O - Exit status */
61 main(int argc
, /* I - Number of command-line arguments */
62 char *argv
[]) /* I - Command-line arguments */
64 int i
, j
; /* Looping vars */
65 int status
; /* Status from export_dest() */
66 int export_all
; /* Export all printers? */
67 http_t
*http
; /* Connection to server */
68 int num_dests
; /* Number of printers */
69 cups_dest_t
*dests
; /* Printers */
75 * Parse command-line arguments...
80 SAMBAUser
= cupsUser();
84 for (i
= 1; i
< argc
; i
++)
85 if (!strcmp(argv
[i
], "-E"))
88 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
90 _cupsLangPrintf(stderr
,
91 _("%s: Sorry, no encryption support compiled in!\n"),
95 else if (!strcmp(argv
[i
], "-H"))
101 SAMBAServer
= argv
[i
];
103 else if (!strcmp(argv
[i
], "-U"))
105 char *sep
; /* Separator for password */
114 if ((sep
= strchr(argv
[i
], '%')) != NULL
)
117 * Nul-terminate the username at the first % and point the
118 * password at the rest...
126 else if (!strcmp(argv
[i
], "-a"))
128 else if (!strcmp(argv
[i
], "-h"))
134 cupsSetServer(argv
[i
]);
136 else if (!strcmp(argv
[i
], "-v"))
138 else if (argv
[i
][0] != '-')
143 * Connect to the server...
146 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
147 cupsEncryption())) == NULL
)
149 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), argv
[0]);
154 if (SAMBAServer
== NULL
)
155 SAMBAServer
= cupsServer();
157 if ((status
= export_dest(http
, argv
[i
])) != 0)
164 * Connect to the server...
167 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
168 cupsEncryption())) == NULL
)
170 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), argv
[0]);
175 * See if the user specified "-a"...
181 * Export all printers...
184 if (SAMBAServer
== NULL
)
185 SAMBAServer
= cupsServer();
187 num_dests
= cupsGetDests2(http
, &dests
);
189 for (j
= 0, status
= 0; j
< num_dests
; j
++)
190 if (!dests
[j
].instance
)
192 if ((status
= export_dest(http
, dests
[j
].name
)) != 0)
196 cupsFreeDests(num_dests
, dests
);
207 * 'export_dest()' - Export a destination to SAMBA.
210 int /* O - 0 on success, non-zero on error */
211 export_dest(http_t
*http
, /* I - Connection to server */
212 const char *dest
) /* I - Destination to export */
214 int status
; /* Status of export */
215 char ppdfile
[1024], /* PPD file for printer drivers */
216 prompt
[1024]; /* Password prompt */
220 * Get the Windows PPD file for the printer...
223 if (!cupsAdminCreateWindowsPPD(http
, dest
, ppdfile
, sizeof(ppdfile
)))
225 _cupsLangPrintf(stderr
,
226 _("cupsaddsmb: No PPD file for printer \"%s\" - "
228 dest
, cupsLastErrorString());
233 * Try to export it...
236 for (status
= 0; !status
;)
239 * Get the password, as needed...
244 snprintf(prompt
, sizeof(prompt
),
245 _cupsLangString(cupsLangDefault(),
246 _("Password for %s required to access %s via "
248 SAMBAUser
, SAMBAServer
);
250 if ((SAMBAPassword
= cupsGetPassword(prompt
)) == NULL
)
254 status
= cupsAdminExportSamba(dest
, ppdfile
, SAMBAServer
,
255 SAMBAUser
, SAMBAPassword
,
256 Verbosity
? stderr
: NULL
);
258 if (!status
&& cupsLastError() == IPP_NOT_FOUND
)
269 * 'usage()' - Show program usage and exit...
275 _cupsLangPuts(stdout
,
276 _("Usage: cupsaddsmb [options] printer1 ... printerN\n"
277 " cupsaddsmb [options] -a\n"
280 " -E Encrypt the connection to the server\n"
281 " -H samba-server Use the named SAMBA server\n"
282 " -U samba-user Authenticate using the named SAMBA user\n"
283 " -a Export all printers\n"
284 " -h cups-server Use the named CUPS server\n"
285 " -v Be verbose (show commands)\n"));
291 * End of "$Id: cupsaddsmb.c 6649 2007-07-11 21:46:42Z mike $".