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