]>
git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupsaddsmb.c
2 * "$Id: cupsaddsmb.c 5925 2006-09-05 19:43:11Z 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 */
84 * Parse command-line arguments...
89 SAMBAUser
= cupsUser();
93 for (i
= 1; i
< argc
; i
++)
94 if (!strcmp(argv
[i
], "-E"))
97 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
99 _cupsLangPrintf(stderr
,
100 _("%s: Sorry, no encryption support compiled in!\n"),
102 #endif /* HAVE_SSL */
104 else if (!strcmp(argv
[i
], "-H"))
110 SAMBAServer
= argv
[i
];
112 else if (!strcmp(argv
[i
], "-U"))
114 char *sep
; /* Separator for password */
123 if ((sep
= strchr(argv
[i
], '%')) != NULL
)
126 * Nul-terminate the username at the first % and point the
127 * password at the rest...
135 else if (!strcmp(argv
[i
], "-a"))
137 else if (!strcmp(argv
[i
], "-h"))
143 cupsSetServer(argv
[i
]);
145 else if (!strcmp(argv
[i
], "-v"))
147 else if (argv
[i
][0] != '-')
152 * Connect to the server...
155 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
156 cupsEncryption())) == NULL
)
158 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), argv
[0]);
163 if (SAMBAServer
== NULL
)
164 SAMBAServer
= cupsServer();
166 if ((status
= export_dest(http
, argv
[i
])) != 0)
173 * Connect to the server...
176 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
177 cupsEncryption())) == NULL
)
179 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), argv
[0]);
184 * See if the user specified "-a"...
190 * Export all printers...
193 if (SAMBAServer
== NULL
)
194 SAMBAServer
= cupsServer();
196 num_dests
= cupsGetDests2(http
, &dests
);
198 for (j
= 0, status
= 0; j
< num_dests
; j
++)
199 if (!dests
[j
].instance
)
201 if ((status
= export_dest(http
, dests
[j
].name
)) != 0)
205 cupsFreeDests(num_dests
, dests
);
216 * 'export_dest()' - Export a destination to SAMBA.
219 int /* O - 0 on success, non-zero on error */
220 export_dest(http_t
*http
, /* I - Connection to server */
221 const char *dest
) /* I - Destination to export */
223 int status
; /* Status of export */
224 char ppdfile
[1024], /* PPD file for printer drivers */
225 prompt
[1024]; /* Password prompt */
229 * Get the Windows PPD file for the printer...
232 if (!cupsAdminCreateWindowsPPD(http
, dest
, ppdfile
, sizeof(ppdfile
)))
234 _cupsLangPrintf(stderr
,
235 _("cupsaddsmb: No PPD file for printer \"%s\" - "
237 dest
, cupsLastErrorString());
242 * Try to export it...
245 for (status
= 0; !status
;)
248 * Get the password, as needed...
253 snprintf(prompt
, sizeof(prompt
),
254 _cupsLangString(cupsLangDefault(),
255 _("Password for %s required to access %s via "
257 SAMBAUser
, SAMBAServer
);
259 if ((SAMBAPassword
= cupsGetPassword(prompt
)) == NULL
)
263 status
= cupsAdminExportSamba(dest
, ppdfile
, SAMBAServer
,
264 SAMBAUser
, SAMBAPassword
,
265 Verbosity
? stderr
: NULL
);
275 * 'usage()' - Show program usage and exit...
281 _cupsLangPuts(stdout
,
282 _("Usage: cupsaddsmb [options] printer1 ... printerN\n"
283 " cupsaddsmb [options] -a\n"
286 " -E Encrypt the connection to the server\n"
287 " -H samba-server Use the named SAMBA server\n"
288 " -U samba-user Authenticate using the named SAMBA user\n"
289 " -a Export all printers\n"
290 " -h cups-server Use the named CUPS server\n"
291 " -v Be verbose (show commands)\n"));
297 * End of "$Id: cupsaddsmb.c 5925 2006-09-05 19:43:11Z mike $".