]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsaddsmb.c
2 * "cupsaddsmb" command for CUPS.
4 * Copyright 2007-2012 by Apple Inc.
5 * Copyright 2001-2006 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
15 * Include necessary headers...
18 #include <cups/cups-private.h>
19 #include <cups/adminutil.h>
30 const char *SAMBAUser
,
39 int export_dest(http_t
*http
, const char *dest
);
40 void usage(void) __attribute__((noreturn
));
44 * 'main()' - Export printers on the command-line.
47 int /* O - Exit status */
48 main(int argc
, /* I - Number of command-line arguments */
49 char *argv
[]) /* I - Command-line arguments */
51 int i
, j
; /* Looping vars */
52 int status
; /* Status from export_dest() */
53 int export_all
; /* Export all printers? */
54 http_t
*http
; /* Connection to server */
55 int num_dests
; /* Number of printers */
56 cups_dest_t
*dests
; /* Printers */
62 * Parse command-line arguments...
67 SAMBAUser
= cupsUser();
71 for (i
= 1; i
< argc
; i
++)
72 if (!strcmp(argv
[i
], "-E"))
75 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
77 _cupsLangPrintf(stderr
,
78 _("%s: Sorry, no encryption support."),
82 else if (!strcmp(argv
[i
], "-H"))
88 SAMBAServer
= argv
[i
];
90 else if (!strcmp(argv
[i
], "-U"))
92 char *sep
; /* Separator for password */
101 if ((sep
= strchr(argv
[i
], '%')) != NULL
)
104 * Nul-terminate the username at the first % and point the
105 * password at the rest...
113 else if (!strcmp(argv
[i
], "-a"))
115 else if (!strcmp(argv
[i
], "-h"))
121 cupsSetServer(argv
[i
]);
123 else if (!strcmp(argv
[i
], "-v"))
125 else if (argv
[i
][0] != '-')
130 * Connect to the server...
133 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
134 cupsEncryption())) == NULL
)
136 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server."),
142 if (SAMBAServer
== NULL
)
144 SAMBAServer
= cupsServer();
146 if (SAMBAServer
[0] == '/') /* Use localhost instead of domain socket */
147 SAMBAServer
= "localhost";
150 if ((status
= export_dest(http
, argv
[i
])) != 0)
157 * Connect to the server...
160 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
161 cupsEncryption())) == NULL
)
163 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server."), argv
[0]);
168 * See if the user specified "-a"...
174 * Export all printers...
177 if (SAMBAServer
== NULL
)
179 SAMBAServer
= cupsServer();
181 if (SAMBAServer
[0] == '/') /* Use localhost instead of domain socket */
182 SAMBAServer
= "localhost";
185 num_dests
= cupsGetDests2(http
, &dests
);
187 for (j
= 0, status
= 0; j
< num_dests
; j
++)
188 if (!dests
[j
].instance
)
190 if ((status
= export_dest(http
, dests
[j
].name
)) != 0)
194 cupsFreeDests(num_dests
, dests
);
205 * 'export_dest()' - Export a destination to SAMBA.
208 int /* O - 0 on success, non-zero on error */
209 export_dest(http_t
*http
, /* I - Connection to server */
210 const char *dest
) /* I - Destination to export */
212 int status
; /* Status of export */
213 char ppdfile
[1024], /* PPD file for printer drivers */
214 prompt
[1024]; /* Password prompt */
215 int tries
; /* Number of tries */
219 * Get the Windows PPD file for the printer...
222 if (!cupsAdminCreateWindowsPPD(http
, dest
, ppdfile
, sizeof(ppdfile
)))
224 _cupsLangPrintf(stderr
,
225 _("cupsaddsmb: No PPD file for printer \"%s\" - %s"),
226 dest
, cupsLastErrorString());
231 * Try to export it...
234 for (status
= 0, tries
= 0; !status
&& tries
< 3; tries
++)
237 * Get the password, as needed...
242 snprintf(prompt
, sizeof(prompt
),
243 _cupsLangString(cupsLangDefault(),
244 _("Password for %s required to access %s via "
246 SAMBAUser
, SAMBAServer
);
248 if ((SAMBAPassword
= cupsGetPassword(prompt
)) == NULL
)
252 status
= cupsAdminExportSamba(dest
, ppdfile
, SAMBAServer
,
253 SAMBAUser
, SAMBAPassword
,
254 Verbosity
? stderr
: NULL
);
256 if (!status
&& cupsLastError() == IPP_NOT_FOUND
)
267 * 'usage()' - Show program usage and exit...
273 _cupsLangPuts(stdout
, _("Usage: cupsaddsmb [options] printer1 ... printerN"));
274 _cupsLangPuts(stdout
, _(" cupsaddsmb [options] -a"));
275 _cupsLangPuts(stdout
, "");
276 _cupsLangPuts(stdout
, _("Options:"));
277 _cupsLangPuts(stdout
, _(" -E Encrypt the connection."));
278 _cupsLangPuts(stdout
, _(" -H samba-server Use the named SAMBA "
280 _cupsLangPuts(stdout
, _(" -U username Specify username."));
281 _cupsLangPuts(stdout
, _(" -a Export all printers."));
282 _cupsLangPuts(stdout
, _(" -h server[:port] Specify server address."));
283 _cupsLangPuts(stdout
, _(" -v Be verbose."));