]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsaddsmb.c
2 * "$Id: cupsaddsmb.c 7033 2007-10-19 02:11:28Z mike $"
4 * "cupsaddsmb" command for CUPS.
6 * Copyright 2007-2010 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
);
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 compiled in\n"),
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\n"), argv
[0]);
149 if (SAMBAServer
== NULL
)
151 SAMBAServer
= cupsServer();
153 if (SAMBAServer
[0] == '/') /* Use localhost instead of domain socket */
154 SAMBAServer
= "localhost";
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
)
186 SAMBAServer
= cupsServer();
188 if (SAMBAServer
[0] == '/') /* Use localhost instead of domain socket */
189 SAMBAServer
= "localhost";
192 num_dests
= cupsGetDests2(http
, &dests
);
194 for (j
= 0, status
= 0; j
< num_dests
; j
++)
195 if (!dests
[j
].instance
)
197 if ((status
= export_dest(http
, dests
[j
].name
)) != 0)
201 cupsFreeDests(num_dests
, dests
);
212 * 'export_dest()' - Export a destination to SAMBA.
215 int /* O - 0 on success, non-zero on error */
216 export_dest(http_t
*http
, /* I - Connection to server */
217 const char *dest
) /* I - Destination to export */
219 int status
; /* Status of export */
220 char ppdfile
[1024], /* PPD file for printer drivers */
221 prompt
[1024]; /* Password prompt */
225 * Get the Windows PPD file for the printer...
228 if (!cupsAdminCreateWindowsPPD(http
, dest
, ppdfile
, sizeof(ppdfile
)))
230 _cupsLangPrintf(stderr
,
231 _("cupsaddsmb: No PPD file for printer \"%s\" - "
233 dest
, cupsLastErrorString());
238 * Try to export it...
241 for (status
= 0; !status
;)
244 * Get the password, as needed...
249 snprintf(prompt
, sizeof(prompt
),
250 _cupsLangString(cupsLangDefault(),
251 _("Password for %s required to access %s via "
253 SAMBAUser
, SAMBAServer
);
255 if ((SAMBAPassword
= cupsGetPassword(prompt
)) == NULL
)
259 status
= cupsAdminExportSamba(dest
, ppdfile
, SAMBAServer
,
260 SAMBAUser
, SAMBAPassword
,
261 Verbosity
? stderr
: NULL
);
263 if (!status
&& cupsLastError() == IPP_NOT_FOUND
)
274 * 'usage()' - Show program usage and exit...
280 _cupsLangPuts(stdout
,
281 _("Usage: cupsaddsmb [options] printer1 ... printerN\n"
282 " cupsaddsmb [options] -a\n"
285 " -E Encrypt the connection to the server\n"
286 " -H samba-server Use the named SAMBA server\n"
287 " -U samba-user Authenticate using the named SAMBA user\n"
288 " -a Export all printers\n"
289 " -h cups-server Use the named CUPS server\n"
290 " -v Be verbose (show commands)\n"));
296 * End of "$Id: cupsaddsmb.c 7033 2007-10-19 02:11:28Z mike $".