]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsaddsmb.c
4 * "cupsaddsmb" command for CUPS.
6 * Copyright 2007-2012 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...
26 #include <cups/cups-private.h>
27 #include <cups/adminutil.h>
38 const char *SAMBAUser
,
47 int export_dest(http_t
*http
, const char *dest
);
48 void usage(void) __attribute__((noreturn
));
52 * 'main()' - Export printers on the command-line.
55 int /* O - Exit status */
56 main(int argc
, /* I - Number of command-line arguments */
57 char *argv
[]) /* I - Command-line arguments */
59 int i
, j
; /* Looping vars */
60 int status
; /* Status from export_dest() */
61 int export_all
; /* Export all printers? */
62 http_t
*http
; /* Connection to server */
63 int num_dests
; /* Number of printers */
64 cups_dest_t
*dests
; /* Printers */
70 * Parse command-line arguments...
75 SAMBAUser
= cupsUser();
79 for (i
= 1; i
< argc
; i
++)
80 if (!strcmp(argv
[i
], "-E"))
83 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
85 _cupsLangPrintf(stderr
,
86 _("%s: Sorry, no encryption support."),
90 else if (!strcmp(argv
[i
], "-H"))
96 SAMBAServer
= argv
[i
];
98 else if (!strcmp(argv
[i
], "-U"))
100 char *sep
; /* Separator for password */
109 if ((sep
= strchr(argv
[i
], '%')) != NULL
)
112 * Nul-terminate the username at the first % and point the
113 * password at the rest...
121 else if (!strcmp(argv
[i
], "-a"))
123 else if (!strcmp(argv
[i
], "-h"))
129 cupsSetServer(argv
[i
]);
131 else if (!strcmp(argv
[i
], "-v"))
133 else if (argv
[i
][0] != '-')
138 * Connect to the server...
141 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
142 cupsEncryption())) == NULL
)
144 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server."),
150 if (SAMBAServer
== NULL
)
152 SAMBAServer
= cupsServer();
154 if (SAMBAServer
[0] == '/') /* Use localhost instead of domain socket */
155 SAMBAServer
= "localhost";
158 if ((status
= export_dest(http
, argv
[i
])) != 0)
165 * Connect to the server...
168 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
169 cupsEncryption())) == NULL
)
171 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server."), argv
[0]);
176 * See if the user specified "-a"...
182 * Export all printers...
185 if (SAMBAServer
== NULL
)
187 SAMBAServer
= cupsServer();
189 if (SAMBAServer
[0] == '/') /* Use localhost instead of domain socket */
190 SAMBAServer
= "localhost";
193 num_dests
= cupsGetDests2(http
, &dests
);
195 for (j
= 0, status
= 0; j
< num_dests
; j
++)
196 if (!dests
[j
].instance
)
198 if ((status
= export_dest(http
, dests
[j
].name
)) != 0)
202 cupsFreeDests(num_dests
, dests
);
213 * 'export_dest()' - Export a destination to SAMBA.
216 int /* O - 0 on success, non-zero on error */
217 export_dest(http_t
*http
, /* I - Connection to server */
218 const char *dest
) /* I - Destination to export */
220 int status
; /* Status of export */
221 char ppdfile
[1024], /* PPD file for printer drivers */
222 prompt
[1024]; /* Password prompt */
223 int tries
; /* Number of tries */
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\" - %s"),
234 dest
, cupsLastErrorString());
239 * Try to export it...
242 for (status
= 0, tries
= 0; !status
&& tries
< 3; tries
++)
245 * Get the password, as needed...
250 snprintf(prompt
, sizeof(prompt
),
251 _cupsLangString(cupsLangDefault(),
252 _("Password for %s required to access %s via "
254 SAMBAUser
, SAMBAServer
);
256 if ((SAMBAPassword
= cupsGetPassword(prompt
)) == NULL
)
260 status
= cupsAdminExportSamba(dest
, ppdfile
, SAMBAServer
,
261 SAMBAUser
, SAMBAPassword
,
262 Verbosity
? stderr
: NULL
);
264 if (!status
&& cupsLastError() == IPP_NOT_FOUND
)
275 * 'usage()' - Show program usage and exit...
281 _cupsLangPuts(stdout
, _("Usage: cupsaddsmb [options] printer1 ... printerN"));
282 _cupsLangPuts(stdout
, _(" cupsaddsmb [options] -a"));
283 _cupsLangPuts(stdout
, "");
284 _cupsLangPuts(stdout
, _("Options:"));
285 _cupsLangPuts(stdout
, _(" -E Encrypt the connection."));
286 _cupsLangPuts(stdout
, _(" -H samba-server Use the named SAMBA "
288 _cupsLangPuts(stdout
, _(" -U username Specify username."));
289 _cupsLangPuts(stdout
, _(" -a Export all printers."));
290 _cupsLangPuts(stdout
, _(" -h server[:port] Specify server address."));
291 _cupsLangPuts(stdout
, _(" -v Be verbose."));