]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/usersys.c
Merge changes from CUPS 1.5svn-r9323.
[thirdparty/cups.git] / cups / usersys.c
CommitLineData
ef416fc2 1/*
e07d4801 2 * "$Id: usersys.c 8498 2009-04-13 17:03:15Z mike $"
ef416fc2 3 *
5a6b583a 4 * User, system, and password routines for CUPS.
ef416fc2 5 *
5a6b583a 6 * Copyright 2007-2010 by Apple Inc.
ef416fc2 7 * Copyright 1997-2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
ef416fc2 14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
5a6b583a 19 * cupsEncryption() - Get the current encryption settings.
b423cd4c 20 * cupsGetPassword() - Get a password from the user.
5a6b583a
MS
21 * cupsGetPassword2() - Get a password from the user using the advanced
22 * password callback.
23 * cupsServer() - Return the hostname/address of the current
e07d4801 24 * server.
7cf5915e 25 * cupsSetClientCertCB() - Set the client certificate callback.
b423cd4c 26 * cupsSetEncryption() - Set the encryption preference.
27 * cupsSetPasswordCB() - Set the password callback for CUPS.
f11a948a 28 * cupsSetPasswordCB2() - Set the advanced password callback for CUPS.
5a6b583a 29 * cupsSetServer() - Set the default server name and port.
7cf5915e 30 * cupsSetServerCertCB() - Set the server certificate callback.
b423cd4c 31 * cupsSetUser() - Set the default user name.
e07d4801 32 * cupsUser() - Return the current user's name.
b423cd4c 33 * _cupsGetPassword() - Get a password from the user.
e07d4801
MS
34 * _cupsSetDefaults() - Set the default server, port, and encryption.
35 * cups_read_client_conf() - Read a client.conf file.
ef416fc2 36 */
37
38/*
39 * Include necessary headers...
40 */
41
71e16022 42#include "cups-private.h"
ef416fc2 43#include <stdlib.h>
e00b005a 44#include <sys/stat.h>
ef416fc2 45#ifdef WIN32
46# include <windows.h>
5a6b583a
MS
47#else
48# include <pwd.h>
ef416fc2 49#endif /* WIN32 */
50
51
b423cd4c 52/*
53 * Local functions...
54 */
55
e07d4801
MS
56static void cups_read_client_conf(cups_file_t *fp,
57 _cups_globals_t *cg,
58 const char *cups_encryption,
7cf5915e
MS
59 const char *cups_server,
60 const char *cups_anyroot,
61 const char *cups_expiredroot,
62 const char *cups_expiredcerts);
b423cd4c 63
64
ef416fc2 65/*
5a6b583a 66 * 'cupsEncryption()' - Get the current encryption settings.
ef416fc2 67 *
68 * The default encryption setting comes from the CUPS_ENCRYPTION
568fa3fa 69 * environment variable, then the ~/.cups/client.conf file, and finally the
ef416fc2 70 * /etc/cups/client.conf file. If not set, the default is
5a738aea 71 * @code HTTP_ENCRYPT_IF_REQUESTED@.
5a6b583a
MS
72 *
73 * Note: The current encryption setting is tracked separately for each thread
74 * in a program. Multi-threaded programs that override the setting via the
75 * @link cupsSetEncryption@ function need to do so in each thread for the same
76 * setting to be used.
ef416fc2 77 */
78
79http_encryption_t /* O - Encryption settings */
80cupsEncryption(void)
81{
ef416fc2 82 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
83
84
ef416fc2 85 if (cg->encryption == (http_encryption_t)-1)
e07d4801 86 _cupsSetDefaults();
ef416fc2 87
88 return (cg->encryption);
89}
90
91
92/*
93 * 'cupsGetPassword()' - Get a password from the user.
94 *
5a738aea 95 * Uses the current password callback function. Returns @code NULL@ if the
ecdc0628 96 * user does not provide a password.
5a6b583a
MS
97 *
98 * Note: The current password callback function is tracked separately for each
99 * thread in a program. Multi-threaded programs that override the setting via
100 * the @link cupsSetPasswordCB@ or @link cupsSetPasswordCB2@ functions need to
101 * do so in each thread for the same function to be used.
ef416fc2 102 */
103
104const char * /* O - Password */
105cupsGetPassword(const char *prompt) /* I - Prompt string */
106{
f11a948a
MS
107 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
108
109
110 return ((cg->password_cb)(prompt, NULL, NULL, NULL, cg->password_data));
111}
112
113
114/*
115 * 'cupsGetPassword2()' - Get a password from the user using the advanced
5a6b583a 116 * password callback.
f11a948a
MS
117 *
118 * Uses the current password callback function. Returns @code NULL@ if the
119 * user does not provide a password.
120 *
5a6b583a
MS
121 * Note: The current password callback function is tracked separately for each
122 * thread in a program. Multi-threaded programs that override the setting via
123 * the @link cupsSetPasswordCB@ or @link cupsSetPasswordCB2@ functions need to
124 * do so in each thread for the same function to be used.
125 *
178cb736 126 * @since CUPS 1.4/Mac OS X 10.6@
f11a948a
MS
127 */
128
129const char * /* O - Password */
130cupsGetPassword2(const char *prompt, /* I - Prompt string */
131 http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
132 const char *method, /* I - Request method ("GET", "POST", "PUT") */
133 const char *resource) /* I - Resource path */
134{
135 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
136
137
138 if (!http)
139 http = _cupsConnect();
140
141 return ((cg->password_cb)(prompt, http, method, resource, cg->password_data));
ef416fc2 142}
143
144
ef416fc2 145/*
5a6b583a
MS
146 * 'cupsServer()' - Return the hostname/address of the current server.
147 *
148 * The default server comes from the CUPS_SERVER environment variable, then the
149 * ~/.cups/client.conf file, and finally the /etc/cups/client.conf file. If not
150 * set, the default is the local system - either "localhost" or a domain socket
151 * path.
ef416fc2 152 *
5a6b583a
MS
153 * The returned value can be a fully-qualified hostname, a numeric IPv4 or IPv6
154 * address, or a domain socket pathname.
155 *
156 * Note: The current server is tracked separately for each thread in a program.
157 * Multi-threaded programs that override the server via the
158 * @link cupsSetServer@ function need to do so in each thread for the same
159 * server to be used.
ef416fc2 160 */
161
162const char * /* O - Server name */
163cupsServer(void)
164{
ef416fc2 165 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
166
167
ef416fc2 168 if (!cg->server[0])
e07d4801 169 _cupsSetDefaults();
ef416fc2 170
e07d4801
MS
171 return (cg->server);
172}
ef416fc2 173
d09495fa 174
7cf5915e
MS
175/*
176 * 'cupsSetClientCertCB()' - Set the client certificate callback.
177 *
178 * Pass @code NULL@ to restore the default callback.
179 *
180 * Note: The current certificate callback is tracked separately for each thread
181 * in a program. Multi-threaded programs that override the callback need to do
182 * so in each thread for the same callback to be used.
183 *
184 * @since CUPS 1.5@
185 */
186
187void
188cupsSetClientCertCB(
189 cups_client_cert_cb_t cb, /* I - Callback function */
190 void *user_data) /* I - User data pointer */
191{
192 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
193
194
195 cg->client_cert_cb = cb;
196 cg->client_cert_data = user_data;
197}
198
199
200/*
201 * 'cupsSetCredentials()' - Set the default credentials to be used for SSL/TLS
202 * connections.
203 *
204 * Note: The default credentials are tracked separately for each thread in a
205 * program. Multi-threaded programs that override the setting need to do so in
206 * each thread for the same setting to be used.
207 *
208 * @since CUPS 1.5@
209 */
210
211int /* O - Status of call (0 = success) */
212cupsSetCredentials(
213 cups_array_t *credentials) /* I - Array of credentials */
214{
215 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
216
217
218 if (cupsArrayCount(credentials) < 1)
219 return (-1);
220
221 _httpFreeCredentials(cg->tls_credentials);
222 cg->tls_credentials = _httpConvertCredentials(credentials);
223
224 return (cg->tls_credentials ? 0 : -1);
225}
226
227
e07d4801
MS
228/*
229 * 'cupsSetEncryption()' - Set the encryption preference.
5a6b583a
MS
230 *
231 * The default encryption setting comes from the CUPS_ENCRYPTION
232 * environment variable, then the ~/.cups/client.conf file, and finally the
233 * /etc/cups/client.conf file. If not set, the default is
234 * @code HTTP_ENCRYPT_IF_REQUESTED@.
235 *
236 * Note: The current encryption setting is tracked separately for each thread
237 * in a program. Multi-threaded programs that override the setting need to do
238 * so in each thread for the same setting to be used.
e07d4801 239 */
ef416fc2 240
e07d4801
MS
241void
242cupsSetEncryption(http_encryption_t e) /* I - New encryption preference */
243{
244 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
ef416fc2 245
ef416fc2 246
e07d4801 247 cg->encryption = e;
ef416fc2 248
e07d4801
MS
249 if (cg->http)
250 httpEncryption(cg->http, e);
ef416fc2 251}
252
253
254/*
255 * 'cupsSetPasswordCB()' - Set the password callback for CUPS.
256 *
5a6b583a
MS
257 * Pass @code NULL@ to restore the default (console) password callback, which
258 * reads the password from the console. Programs should call either this
259 * function or @link cupsSetPasswordCB2@, as only one callback can be registered
260 * by a program per thread.
261 *
262 * Note: The current password callback is tracked separately for each thread
263 * in a program. Multi-threaded programs that override the callback need to do
264 * so in each thread for the same callback to be used.
ef416fc2 265 */
266
267void
268cupsSetPasswordCB(cups_password_cb_t cb)/* I - Callback function */
269{
270 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
271
272
f11a948a
MS
273 if (cb == (cups_password_cb_t)0)
274 cg->password_cb = (cups_password_cb2_t)_cupsGetPassword;
275 else
276 cg->password_cb = (cups_password_cb2_t)cb;
277
278 cg->password_data = NULL;
279}
280
281
282/*
283 * 'cupsSetPasswordCB2()' - Set the advanced password callback for CUPS.
284 *
5a6b583a
MS
285 * Pass @code NULL@ to restore the default (console) password callback, which
286 * reads the password from the console. Programs should call either this
287 * function or @link cupsSetPasswordCB2@, as only one callback can be registered
288 * by a program per thread.
289 *
290 * Note: The current password callback is tracked separately for each thread
291 * in a program. Multi-threaded programs that override the callback need to do
292 * so in each thread for the same callback to be used.
f11a948a 293 *
178cb736 294 * @since CUPS 1.4/Mac OS X 10.6@
f11a948a
MS
295 */
296
297void
298cupsSetPasswordCB2(
299 cups_password_cb2_t cb, /* I - Callback function */
300 void *user_data) /* I - User data pointer */
301{
302 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
303
304
305 if (cb == (cups_password_cb2_t)0)
306 cg->password_cb = (cups_password_cb2_t)_cupsGetPassword;
ef416fc2 307 else
308 cg->password_cb = cb;
f11a948a
MS
309
310 cg->password_data = user_data;
ef416fc2 311}
312
313
314/*
5a6b583a 315 * 'cupsSetServer()' - Set the default server name and port.
ef416fc2 316 *
317 * The "server" string can be a fully-qualified hostname, a numeric
5a6b583a
MS
318 * IPv4 or IPv6 address, or a domain socket pathname. Hostnames and numeric IP
319 * addresses can be optionally followed by a colon and port number to override
320 * the default port 631, e.g. "hostname:8631". Pass @code NULL@ to restore the
321 * default server name and port.
322 *
323 * Note: The current server is tracked separately for each thread in a program.
324 * Multi-threaded programs that override the server need to do so in each
325 * thread for the same server to be used.
ef416fc2 326 */
327
328void
329cupsSetServer(const char *server) /* I - Server name */
330{
331 char *port; /* Pointer to port */
332 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
333
334
335 if (server)
336 {
337 strlcpy(cg->server, server, sizeof(cg->server));
338
339 if (cg->server[0] != '/' && (port = strrchr(cg->server, ':')) != NULL &&
340 !strchr(port, ']') && isdigit(port[1] & 255))
341 {
342 *port++ = '\0';
343
e07d4801 344 cg->ipp_port = atoi(port);
ef416fc2 345 }
346
347 if (cg->server[0] == '/')
348 strcpy(cg->servername, "localhost");
349 else
350 strlcpy(cg->servername, cg->server, sizeof(cg->servername));
351 }
352 else
353 {
354 cg->server[0] = '\0';
355 cg->servername[0] = '\0';
356 }
5a738aea
MS
357
358 if (cg->http)
359 {
360 httpClose(cg->http);
361 cg->http = NULL;
362 }
ef416fc2 363}
364
365
7cf5915e
MS
366/*
367 * 'cupsSetServerCertCB()' - Set the server certificate callback.
368 *
369 * Pass @code NULL@ to restore the default callback.
370 *
371 * Note: The current credentials callback is tracked separately for each thread
372 * in a program. Multi-threaded programs that override the callback need to do
373 * so in each thread for the same callback to be used.
374 *
375 * @since CUPS 1.5@
376 */
377
378void
379cupsSetServerCertCB(
380 cups_server_cert_cb_t cb, /* I - Callback function */
381 void *user_data) /* I - User data pointer */
382{
383 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
384
385
386 cg->server_cert_cb = cb;
387 cg->server_cert_data = user_data;
388}
389
390
ef416fc2 391/*
392 * 'cupsSetUser()' - Set the default user name.
393 *
5a738aea 394 * Pass @code NULL@ to restore the default user name.
5a6b583a
MS
395 *
396 * Note: The current user name is tracked separately for each thread in a
397 * program. Multi-threaded programs that override the user name need to do so
398 * in each thread for the same user name to be used.
ef416fc2 399 */
400
401void
402cupsSetUser(const char *user) /* I - User name */
403{
404 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
405
406
407 if (user)
408 strlcpy(cg->user, user, sizeof(cg->user));
409 else
410 cg->user[0] = '\0';
411}
412
413
ef416fc2 414/*
415 * 'cupsUser()' - Return the current user's name.
5a6b583a
MS
416 *
417 * Note: The current user name is tracked separately for each thread in a
418 * program. Multi-threaded programs that override the user name with the
419 * @link cupsSetUser@ function need to do so in each thread for the same user
420 * name to be used.
ef416fc2 421 */
422
423const char * /* O - User name */
424cupsUser(void)
425{
6d2f911b 426 const char *user; /* USER environment variable */
ef416fc2 427 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
428
429
430 if (!cg->user[0])
431 {
5a6b583a
MS
432#ifdef WIN32
433 /*
434 * Get the current user name from the OS...
435 */
ef416fc2 436
5a6b583a 437 DWORD size; /* Size of string */
ef416fc2 438
439 size = sizeof(cg->user);
440 if (!GetUserName(cg->user, &size))
ef416fc2 441#else
ef416fc2 442 /*
5a6b583a 443 * Get the user name corresponding to the current UID...
ef416fc2 444 */
445
5a6b583a 446 struct passwd *pwd; /* User/password entry */
ef416fc2 447
5a6b583a
MS
448 setpwent();
449 if ((pwd = getpwuid(getuid())) != NULL)
ef416fc2 450 {
451 /*
5a6b583a 452 * Found a match!
ef416fc2 453 */
454
ef416fc2 455 strlcpy(cg->user, pwd->pw_name, sizeof(cg->user));
456 }
5a6b583a
MS
457 else
458#endif /* WIN32 */
6d2f911b
MS
459 if ((user = getenv("USER")) != NULL)
460 {
461 /*
462 * Use the username from the "USER" environment variable...
463 */
464 strlcpy(cg->user, user, sizeof(cg->user));
465 }
466 else
5a6b583a
MS
467 {
468 /*
469 * Use the default "unknown" user name...
470 */
6d2f911b 471
5a6b583a
MS
472 strcpy(cg->user, "unknown");
473 }
ef416fc2 474 }
475
476 return (cg->user);
477}
478
479
480/*
481 * '_cupsGetPassword()' - Get a password from the user.
482 */
483
484const char * /* O - Password */
485_cupsGetPassword(const char *prompt) /* I - Prompt string */
486{
5a6b583a
MS
487#ifdef WIN32
488 /*
489 * Currently no console password support is provided on Windows.
490 */
491
492 return (NULL);
493
494#else
495 /*
7cf5915e
MS
496 * Use the standard getpass function to get a password from the console. An
497 * empty password is treated as canceling the authentication request.
5a6b583a
MS
498 */
499
7cf5915e
MS
500 const char *password = getpass(prompt);
501 /* Password string */
502
503 if (!password || !password[0])
504 return (NULL);
505 else
506 return (password);
ef416fc2 507#endif /* WIN32 */
5a6b583a 508}
ef416fc2 509
510
511/*
e07d4801 512 * '_cupsSetDefaults()' - Set the default server, port, and encryption.
b423cd4c 513 */
514
e07d4801
MS
515void
516_cupsSetDefaults(void)
b423cd4c 517{
518 cups_file_t *fp; /* File */
e07d4801
MS
519 const char *home, /* Home directory of user */
520 *cups_encryption, /* CUPS_ENCRYPTION env var */
7cf5915e
MS
521 *cups_server, /* CUPS_SERVER env var */
522 *cups_anyroot, /* CUPS_ANYROOT env var */
523 *cups_expiredroot, /* CUPS_EXPIREDROOT env var */
524 *cups_expiredcerts; /* CUPS_EXPIREDCERTS env var */
b423cd4c 525 char filename[1024]; /* Filename */
526 _cups_globals_t *cg = _cupsGlobals(); /* Pointer to library globals */
527
528
e07d4801
MS
529 DEBUG_puts("_cupsSetDefaults()");
530
531 /*
532 * First collect environment variables...
533 */
534
7cf5915e
MS
535 cups_encryption = getenv("CUPS_ENCRYPTION");
536 cups_server = getenv("CUPS_SERVER");
537 cups_anyroot = getenv("CUPS_ANYROOT");
538 cups_expiredroot = getenv("CUPS_EXPIREDROOT");
539 cups_expiredcerts = getenv("CUPS_EXPIREDCERTS");
e07d4801
MS
540
541 /*
542 * Then, if needed, the .cups/client.conf or .cupsrc file in the home
543 * directory...
544 */
545
546 if ((cg->encryption == (http_encryption_t)-1 || !cg->server[0] ||
547 !cg->ipp_port) && (home = getenv("HOME")) != NULL)
b423cd4c 548 {
549 /*
5a6b583a 550 * Look for ~/.cups/client.conf...
b423cd4c 551 */
552
553 snprintf(filename, sizeof(filename), "%s/.cups/client.conf", home);
5a6b583a 554 if ((fp = cupsFileOpen(filename, "r")) != NULL)
e07d4801 555 {
7cf5915e
MS
556 cups_read_client_conf(fp, cg, cups_encryption, cups_server,
557 cups_anyroot, cups_expiredroot,
558 cups_expiredcerts);
559
e07d4801
MS
560 cupsFileClose(fp);
561 }
562 }
563
564 if (cg->encryption == (http_encryption_t)-1 || !cg->server[0] ||
565 !cg->ipp_port)
566 {
567 /*
568 * Look for CUPS_SERVERROOT/client.conf...
569 */
570
571 snprintf(filename, sizeof(filename), "%s/client.conf", cg->cups_serverroot);
b423cd4c 572 if ((fp = cupsFileOpen(filename, "r")) != NULL)
d09495fa 573 {
7cf5915e
MS
574 cups_read_client_conf(fp, cg, cups_encryption, cups_server,
575 cups_anyroot, cups_expiredroot,
576 cups_expiredcerts);
e07d4801
MS
577 cupsFileClose(fp);
578 }
579 }
580
581 /*
582 * If we still have things that aren't set, use the compiled in defaults...
583 */
584
585 if (cg->encryption == (http_encryption_t)-1)
586 cg->encryption = HTTP_ENCRYPT_IF_REQUESTED;
587
588 if (!cg->server[0])
589 {
590 if (!cups_server)
591 {
592#ifdef CUPS_DEFAULT_DOMAINSOCKET
593 /*
594 * If we are compiled with domain socket support, only use the
595 * domain socket if it exists and has the right permissions...
596 */
597
598 struct stat sockinfo; /* Domain socket information */
599
600 if (!stat(CUPS_DEFAULT_DOMAINSOCKET, &sockinfo) &&
601 (sockinfo.st_mode & S_IRWXO) == S_IRWXO)
602 cups_server = CUPS_DEFAULT_DOMAINSOCKET;
603 else
604#endif /* CUPS_DEFAULT_DOMAINSOCKET */
605 cups_server = "localhost";
606 }
607
608 cupsSetServer(cups_server);
609 }
610
611 if (!cg->ipp_port)
612 {
613 const char *ipp_port; /* IPP_PORT environment variable */
6d2f911b 614 struct servent *service; /* Port number info */
e07d4801
MS
615
616
617 if ((ipp_port = getenv("IPP_PORT")) != NULL)
618 {
619 if ((cg->ipp_port = atoi(ipp_port)) <= 0)
620 cg->ipp_port = CUPS_DEFAULT_IPP_PORT;
d09495fa 621 }
e07d4801
MS
622 else if ((service = getservbyname("ipp", NULL)) == NULL ||
623 service->s_port <= 0)
624 cg->ipp_port = CUPS_DEFAULT_IPP_PORT;
625 else
626 cg->ipp_port = ntohs(service->s_port);
627 }
628}
629
630
631/*
632 * 'cups_read_client_conf()' - Read a client.conf file.
633 */
634
635static void
636cups_read_client_conf(
637 cups_file_t *fp, /* I - File to read */
638 _cups_globals_t *cg, /* I - Global data */
639 const char *cups_encryption, /* I - CUPS_ENCRYPTION env var */
7cf5915e
MS
640 const char *cups_server, /* I - CUPS_SERVER env var */
641 const char *cups_anyroot, /* I - CUPS_ANYROOT env var */
642 const char *cups_expiredroot, /* I - CUPS_EXPIREDROOT env var */
643 const char *cups_expiredcerts) /* I - CUPS_EXPIREDCERTS env var */
e07d4801
MS
644{
645 int linenum; /* Current line number */
646 char line[1024], /* Line from file */
647 *value, /* Pointer into line */
648 encryption[1024], /* Encryption value */
7cf5915e
MS
649 server_name[1024], /* ServerName value */
650 any_root[1024], /* AllowAnyRoot value */
651 expired_root[1024], /* AllowExpiredRoot value */
652 expired_certs[1024]; /* AllowExpiredCerts value */
e07d4801
MS
653
654
655 /*
656 * Read from the file...
657 */
658
659 linenum = 0;
660 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
661 {
662 if (!cups_encryption && cg->encryption == (http_encryption_t)-1 &&
663 !strcasecmp(line, "Encryption") && value)
664 {
665 strlcpy(encryption, value, sizeof(encryption));
666 cups_encryption = encryption;
667 }
668 else if (!cups_server && (!cg->server[0] || !cg->ipp_port) &&
669 !strcasecmp(line, "ServerName") && value)
670 {
671 strlcpy(server_name, value, sizeof(server_name));
672 cups_server = server_name;
673 }
7cf5915e
MS
674 else if (!cups_anyroot && !strcasecmp(line, "AllowAnyRoot") && value)
675 {
676 strlcpy(any_root, value, sizeof(any_root));
677 cups_anyroot = any_root;
678 }
679 else if (!cups_expiredroot && !strcasecmp(line, "AllowExpiredRoot") &&
680 value)
681 {
682 strlcpy(expired_root, value, sizeof(expired_root));
683 cups_expiredroot = expired_root;
684 }
685 else if (!cups_expiredcerts && !strcasecmp(line, "AllowExpiredCerts") &&
686 value)
687 {
688 strlcpy(expired_certs, value, sizeof(expired_certs));
689 cups_expiredcerts = expired_certs;
690 }
e07d4801
MS
691 }
692
693 /*
694 * Set values...
695 */
696
697 if (cg->encryption == (http_encryption_t)-1 && cups_encryption)
698 {
699 if (!strcasecmp(cups_encryption, "never"))
700 cg->encryption = HTTP_ENCRYPT_NEVER;
701 else if (!strcasecmp(cups_encryption, "always"))
702 cg->encryption = HTTP_ENCRYPT_ALWAYS;
703 else if (!strcasecmp(cups_encryption, "required"))
704 cg->encryption = HTTP_ENCRYPT_REQUIRED;
705 else
706 cg->encryption = HTTP_ENCRYPT_IF_REQUESTED;
b423cd4c 707 }
708
e07d4801
MS
709 if ((!cg->server[0] || !cg->ipp_port) && cups_server)
710 {
711 if (!cg->server[0])
712 {
713 /*
714 * Copy server name...
715 */
716
717 strlcpy(cg->server, cups_server, sizeof(cg->server));
718
719 if (cg->server[0] != '/' && (value = strrchr(cg->server, ':')) != NULL &&
720 !strchr(value, ']') && isdigit(value[1] & 255))
721 *value++ = '\0';
722 else
723 value = NULL;
724
725 if (cg->server[0] == '/')
726 strcpy(cg->servername, "localhost");
727 else
728 strlcpy(cg->servername, cg->server, sizeof(cg->servername));
729 }
730 else if (cups_server[0] != '/' &&
731 (value = strrchr(cups_server, ':')) != NULL &&
732 !strchr(value, ']') && isdigit(value[1] & 255))
733 value ++;
734 else
735 value = NULL;
736
737 if (!cg->ipp_port && value)
738 cg->ipp_port = atoi(value);
739 }
7cf5915e
MS
740
741 if (cups_anyroot)
742 cg->any_root = !strcasecmp(cups_anyroot, "yes") ||
743 !strcasecmp(cups_anyroot, "on") ||
744 !strcasecmp(cups_anyroot, "true");
745
746 if (cups_expiredroot)
747 cg->expired_root = !strcasecmp(cups_expiredroot, "yes") ||
748 !strcasecmp(cups_expiredroot, "on") ||
749 !strcasecmp(cups_expiredroot, "true");
750
751 if (cups_expiredcerts)
752 cg->expired_certs = !strcasecmp(cups_expiredcerts, "yes") ||
753 !strcasecmp(cups_expiredcerts, "on") ||
754 !strcasecmp(cups_expiredcerts, "true");
b423cd4c 755}
756
757
758/*
e07d4801 759 * End of "$Id: usersys.c 8498 2009-04-13 17:03:15Z mike $".
ef416fc2 760 */