4 * User, system, and password routines for CUPS.
6 * Copyright 2007-2013 by Apple Inc.
7 * Copyright 1997-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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * cupsEncryption() - Get the current encryption settings.
20 * cupsGetPassword() - Get a password from the user.
21 * cupsGetPassword2() - Get a password from the user using the advanced
23 * cupsServer() - Return the hostname/address of the current
25 * cupsSetClientCertCB() - Set the client certificate callback.
26 * cupsSetCredentials() - Set the default credentials to be used for
27 * SSL/TLS connections.
28 * cupsSetEncryption() - Set the encryption preference.
29 * cupsSetPasswordCB() - Set the password callback for CUPS.
30 * cupsSetPasswordCB2() - Set the advanced password callback for CUPS.
31 * cupsSetServer() - Set the default server name and port.
32 * cupsSetServerCertCB() - Set the server certificate callback.
33 * cupsSetUser() - Set the default user name.
34 * cupsSetUserAgent() - Set the default HTTP User-Agent string.
35 * cupsUser() - Return the current user's name.
36 * cupsUserAgent() - Return the default HTTP User-Agent string.
37 * _cupsGetPassword() - Get a password from the user.
38 * _cupsGSSServiceName() - Get the GSS (Kerberos) service name.
39 * _cupsSetDefaults() - Set the default server, port, and encryption.
40 * cups_read_client_conf() - Read a client.conf file.
44 * Include necessary headers...
47 #include "cups-private.h"
55 # include <sys/utsname.h>
63 #define _CUPS_PASSCHAR '*' /* Character that is echoed for password */
70 static void cups_read_client_conf(cups_file_t
*fp
,
72 const char *cups_encryption
,
73 const char *cups_server
,
74 const char *cups_user
,
76 const char *cups_gssservicename
,
77 #endif /* HAVE_GSSAPI */
78 const char *cups_anyroot
,
79 const char *cups_expiredroot
,
80 const char *cups_expiredcerts
);
84 * 'cupsEncryption()' - Get the current encryption settings.
86 * The default encryption setting comes from the CUPS_ENCRYPTION
87 * environment variable, then the ~/.cups/client.conf file, and finally the
88 * /etc/cups/client.conf file. If not set, the default is
89 * @code HTTP_ENCRYPTION_IF_REQUESTED@.
91 * Note: The current encryption setting is tracked separately for each thread
92 * in a program. Multi-threaded programs that override the setting via the
93 * @link cupsSetEncryption@ function need to do so in each thread for the same
97 http_encryption_t
/* O - Encryption settings */
100 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
103 if (cg
->encryption
== (http_encryption_t
)-1)
106 return (cg
->encryption
);
111 * 'cupsGetPassword()' - Get a password from the user.
113 * Uses the current password callback function. Returns @code NULL@ if the
114 * user does not provide a password.
116 * Note: The current password callback function is tracked separately for each
117 * thread in a program. Multi-threaded programs that override the setting via
118 * the @link cupsSetPasswordCB@ or @link cupsSetPasswordCB2@ functions need to
119 * do so in each thread for the same function to be used.
122 const char * /* O - Password */
123 cupsGetPassword(const char *prompt
) /* I - Prompt string */
125 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
128 return ((cg
->password_cb
)(prompt
, NULL
, NULL
, NULL
, cg
->password_data
));
133 * 'cupsGetPassword2()' - Get a password from the user using the advanced
136 * Uses the current password callback function. Returns @code NULL@ if the
137 * user does not provide a password.
139 * Note: The current password callback function is tracked separately for each
140 * thread in a program. Multi-threaded programs that override the setting via
141 * the @link cupsSetPasswordCB@ or @link cupsSetPasswordCB2@ functions need to
142 * do so in each thread for the same function to be used.
144 * @since CUPS 1.4/OS X 10.6@
147 const char * /* O - Password */
148 cupsGetPassword2(const char *prompt
, /* I - Prompt string */
149 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
150 const char *method
, /* I - Request method ("GET", "POST", "PUT") */
151 const char *resource
) /* I - Resource path */
153 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
157 http
= _cupsConnect();
159 return ((cg
->password_cb
)(prompt
, http
, method
, resource
, cg
->password_data
));
164 * 'cupsServer()' - Return the hostname/address of the current server.
166 * The default server comes from the CUPS_SERVER environment variable, then the
167 * ~/.cups/client.conf file, and finally the /etc/cups/client.conf file. If not
168 * set, the default is the local system - either "localhost" or a domain socket
171 * The returned value can be a fully-qualified hostname, a numeric IPv4 or IPv6
172 * address, or a domain socket pathname.
174 * Note: The current server is tracked separately for each thread in a program.
175 * Multi-threaded programs that override the server via the
176 * @link cupsSetServer@ function need to do so in each thread for the same
180 const char * /* O - Server name */
183 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
194 * 'cupsSetClientCertCB()' - Set the client certificate callback.
196 * Pass @code NULL@ to restore the default callback.
198 * Note: The current certificate callback is tracked separately for each thread
199 * in a program. Multi-threaded programs that override the callback need to do
200 * so in each thread for the same callback to be used.
202 * @since CUPS 1.5/OS X 10.7@
207 cups_client_cert_cb_t cb
, /* I - Callback function */
208 void *user_data
) /* I - User data pointer */
210 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
213 cg
->client_cert_cb
= cb
;
214 cg
->client_cert_data
= user_data
;
219 * 'cupsSetCredentials()' - Set the default credentials to be used for SSL/TLS
222 * Note: The default credentials are tracked separately for each thread in a
223 * program. Multi-threaded programs that override the setting need to do so in
224 * each thread for the same setting to be used.
226 * @since CUPS 1.5/OS X 10.7@
229 int /* O - Status of call (0 = success) */
231 cups_array_t
*credentials
) /* I - Array of credentials */
233 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
236 if (cupsArrayCount(credentials
) < 1)
239 _httpFreeCredentials(cg
->tls_credentials
);
240 cg
->tls_credentials
= _httpCreateCredentials(credentials
);
242 return (cg
->tls_credentials
? 0 : -1);
247 * 'cupsSetEncryption()' - Set the encryption preference.
249 * The default encryption setting comes from the CUPS_ENCRYPTION
250 * environment variable, then the ~/.cups/client.conf file, and finally the
251 * /etc/cups/client.conf file. If not set, the default is
252 * @code HTTP_ENCRYPTION_IF_REQUESTED@.
254 * Note: The current encryption setting is tracked separately for each thread
255 * in a program. Multi-threaded programs that override the setting need to do
256 * so in each thread for the same setting to be used.
260 cupsSetEncryption(http_encryption_t e
) /* I - New encryption preference */
262 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
268 httpEncryption(cg
->http
, e
);
273 * 'cupsSetPasswordCB()' - Set the password callback for CUPS.
275 * Pass @code NULL@ to restore the default (console) password callback, which
276 * reads the password from the console. Programs should call either this
277 * function or @link cupsSetPasswordCB2@, as only one callback can be registered
278 * by a program per thread.
280 * Note: The current password callback is tracked separately for each thread
281 * in a program. Multi-threaded programs that override the callback need to do
282 * so in each thread for the same callback to be used.
286 cupsSetPasswordCB(cups_password_cb_t cb
)/* I - Callback function */
288 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
291 if (cb
== (cups_password_cb_t
)0)
292 cg
->password_cb
= (cups_password_cb2_t
)_cupsGetPassword
;
294 cg
->password_cb
= (cups_password_cb2_t
)cb
;
296 cg
->password_data
= NULL
;
301 * 'cupsSetPasswordCB2()' - Set the advanced password callback for CUPS.
303 * Pass @code NULL@ to restore the default (console) password callback, which
304 * reads the password from the console. Programs should call either this
305 * function or @link cupsSetPasswordCB2@, as only one callback can be registered
306 * by a program per thread.
308 * Note: The current password callback is tracked separately for each thread
309 * in a program. Multi-threaded programs that override the callback need to do
310 * so in each thread for the same callback to be used.
312 * @since CUPS 1.4/OS X 10.6@
317 cups_password_cb2_t cb
, /* I - Callback function */
318 void *user_data
) /* I - User data pointer */
320 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
323 if (cb
== (cups_password_cb2_t
)0)
324 cg
->password_cb
= (cups_password_cb2_t
)_cupsGetPassword
;
326 cg
->password_cb
= cb
;
328 cg
->password_data
= user_data
;
333 * 'cupsSetServer()' - Set the default server name and port.
335 * The "server" string can be a fully-qualified hostname, a numeric
336 * IPv4 or IPv6 address, or a domain socket pathname. Hostnames and numeric IP
337 * addresses can be optionally followed by a colon and port number to override
338 * the default port 631, e.g. "hostname:8631". Pass @code NULL@ to restore the
339 * default server name and port.
341 * Note: The current server is tracked separately for each thread in a program.
342 * Multi-threaded programs that override the server need to do so in each
343 * thread for the same server to be used.
347 cupsSetServer(const char *server
) /* I - Server name */
349 char *options
, /* Options */
350 *port
; /* Pointer to port */
351 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
356 strlcpy(cg
->server
, server
, sizeof(cg
->server
));
358 if (cg
->server
[0] != '/' && (options
= strrchr(cg
->server
, '/')) != NULL
)
362 if (!strcmp(options
, "version=1.0"))
363 cg
->server_version
= 10;
364 else if (!strcmp(options
, "version=1.1"))
365 cg
->server_version
= 11;
366 else if (!strcmp(options
, "version=2.0"))
367 cg
->server_version
= 20;
368 else if (!strcmp(options
, "version=2.1"))
369 cg
->server_version
= 21;
370 else if (!strcmp(options
, "version=2.2"))
371 cg
->server_version
= 22;
374 cg
->server_version
= 20;
376 if (cg
->server
[0] != '/' && (port
= strrchr(cg
->server
, ':')) != NULL
&&
377 !strchr(port
, ']') && isdigit(port
[1] & 255))
381 cg
->ipp_port
= atoi(port
);
384 if (cg
->server
[0] == '/')
385 strlcpy(cg
->servername
, "localhost", sizeof(cg
->servername
));
387 strlcpy(cg
->servername
, cg
->server
, sizeof(cg
->servername
));
391 cg
->server
[0] = '\0';
392 cg
->servername
[0] = '\0';
393 cg
->server_version
= 20;
405 * 'cupsSetServerCertCB()' - Set the server certificate callback.
407 * Pass @code NULL@ to restore the default callback.
409 * Note: The current credentials callback is tracked separately for each thread
410 * in a program. Multi-threaded programs that override the callback need to do
411 * so in each thread for the same callback to be used.
413 * @since CUPS 1.5/OS X 10.7@
418 cups_server_cert_cb_t cb
, /* I - Callback function */
419 void *user_data
) /* I - User data pointer */
421 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
424 cg
->server_cert_cb
= cb
;
425 cg
->server_cert_data
= user_data
;
430 * 'cupsSetUser()' - Set the default user name.
432 * Pass @code NULL@ to restore the default user name.
434 * Note: The current user name is tracked separately for each thread in a
435 * program. Multi-threaded programs that override the user name need to do so
436 * in each thread for the same user name to be used.
440 cupsSetUser(const char *user
) /* I - User name */
442 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
446 strlcpy(cg
->user
, user
, sizeof(cg
->user
));
453 * 'cupsSetUserAgent()' - Set the default HTTP User-Agent string.
455 * Setting the string to NULL forces the default value containing the CUPS
456 * version, IPP version, and operating system version and architecture.
458 * @since CUPS 1.7/OS X 10.9@
462 cupsSetUserAgent(const char *user_agent
)/* I - User-Agent string or @code NULL@ */
464 _cups_globals_t
*cg
= _cupsGlobals();
467 SYSTEM_INFO sysinfo
; /* System information */
468 OSVERSIONINFO version
; /* OS version info */
470 struct utsname name
; /* uname info */
476 strlcpy(cg
->user_agent
, user_agent
, sizeof(cg
->user_agent
));
481 version
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
482 GetVersionEx(&version
);
483 GetNativeSystemInfo(&sysinfo
);
485 snprintf(cg
->user_agent
, sizeof(cg
->user_agent
),
486 CUPS_MINIMAL
" (Windows %d.%d; %s) IPP/2.0",
487 version
.dwMajorVersion
, version
.dwMinorVersion
,
488 sysinfo
.wProcessorArchitecture
489 == PROCESSOR_ARCHITECTURE_AMD64
? "amd64" :
490 sysinfo
.wProcessorArchitecture
491 == PROCESSOR_ARCHITECTURE_ARM
? "arm" :
492 sysinfo
.wProcessorArchitecture
493 == PROCESSOR_ARCHITECTURE_IA64
? "ia64" :
494 sysinfo
.wProcessorArchitecture
495 == PROCESSOR_ARCHITECTURE_INTEL
? "intel" :
501 snprintf(cg
->user_agent
, sizeof(cg
->user_agent
),
502 CUPS_MINIMAL
" (%s %s; %s) IPP/2.0",
503 name
.sysname
, name
.release
, name
.machine
);
509 * 'cupsUser()' - Return the current user's name.
511 * Note: The current user name is tracked separately for each thread in a
512 * program. Multi-threaded programs that override the user name with the
513 * @link cupsSetUser@ function need to do so in each thread for the same user
517 const char * /* O - User name */
520 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
531 * 'cupsUserAgent()' - Return the default HTTP User-Agent string.
533 * @since CUPS 1.7/OS X 10.9@
536 const char * /* O - User-Agent string */
539 _cups_globals_t
*cg
= _cupsGlobals(); /* Thread globals */
542 if (!cg
->user_agent
[0])
543 cupsSetUserAgent(NULL
);
545 return (cg
->user_agent
);
550 * '_cupsGetPassword()' - Get a password from the user.
553 const char * /* O - Password or @code NULL@ if none */
554 _cupsGetPassword(const char *prompt
) /* I - Prompt string */
557 HANDLE tty
; /* Console handle */
558 DWORD mode
; /* Console mode */
559 char passch
, /* Current key press */
560 *passptr
, /* Pointer into password string */
561 *passend
; /* End of password string */
562 DWORD passbytes
; /* Bytes read */
563 _cups_globals_t
*cg
= _cupsGlobals();
568 * Disable input echo and set raw input...
571 if ((tty
= GetStdHandle(STD_INPUT_HANDLE
)) == INVALID_HANDLE_VALUE
)
574 if (!GetConsoleMode(tty
, &mode
))
577 if (!SetConsoleMode(tty
, 0))
581 * Display the prompt...
584 printf("%s ", prompt
);
588 * Read the password string from /dev/tty until we get interrupted or get a
589 * carriage return or newline...
592 passptr
= cg
->password
;
593 passend
= cg
->password
+ sizeof(cg
->password
) - 1;
595 while (ReadFile(tty
, &passch
, 1, &passbytes
, NULL
))
597 if (passch
== 0x0A || passch
== 0x0D)
605 else if (passch
== 0x08 || passch
== 0x7F)
608 * Backspace/delete (erase character)...
611 if (passptr
> cg
->password
)
614 fputs("\010 \010", stdout
);
619 else if (passch
== 0x15)
622 * CTRL+U (erase line)
625 if (passptr
> cg
->password
)
627 while (passptr
> cg
->password
)
630 fputs("\010 \010", stdout
);
636 else if (passch
== 0x03)
642 passptr
= cg
->password
;
645 else if ((passch
& 255) < 0x20 || passptr
>= passend
)
650 putchar(_CUPS_PASSCHAR
);
663 SetConsoleMode(tty
, mode
);
666 * Return the proper value...
669 if (passbytes
== 1 && passptr
> cg
->password
)
672 return (cg
->password
);
676 memset(cg
->password
, 0, sizeof(cg
->password
));
681 int tty
; /* /dev/tty - never read from stdin */
682 struct termios original
, /* Original input mode */
683 noecho
; /* No echo input mode */
684 char passch
, /* Current key press */
685 *passptr
, /* Pointer into password string */
686 *passend
; /* End of password string */
687 ssize_t passbytes
; /* Bytes read */
688 _cups_globals_t
*cg
= _cupsGlobals();
693 * Disable input echo and set raw input...
696 if ((tty
= open("/dev/tty", O_RDONLY
)) < 0)
699 if (tcgetattr(tty
, &original
))
706 noecho
.c_lflag
&= ~(ICANON
| ECHO
| ECHOE
| ISIG
);
708 if (tcsetattr(tty
, TCSAFLUSH
, &noecho
))
715 * Display the prompt...
718 printf("%s ", prompt
);
722 * Read the password string from /dev/tty until we get interrupted or get a
723 * carriage return or newline...
726 passptr
= cg
->password
;
727 passend
= cg
->password
+ sizeof(cg
->password
) - 1;
729 while ((passbytes
= read(tty
, &passch
, 1)) == 1)
731 if (passch
== noecho
.c_cc
[VEOL
] || passch
== noecho
.c_cc
[VEOL2
] ||
732 passch
== 0x0A || passch
== 0x0D)
740 else if (passch
== noecho
.c_cc
[VERASE
] ||
741 passch
== 0x08 || passch
== 0x7F)
744 * Backspace/delete (erase character)...
747 if (passptr
> cg
->password
)
750 fputs("\010 \010", stdout
);
755 else if (passch
== noecho
.c_cc
[VKILL
])
758 * CTRL+U (erase line)
761 if (passptr
> cg
->password
)
763 while (passptr
> cg
->password
)
766 fputs("\010 \010", stdout
);
772 else if (passch
== noecho
.c_cc
[VINTR
] || passch
== noecho
.c_cc
[VQUIT
] ||
773 passch
== noecho
.c_cc
[VEOF
])
776 * CTRL+C, CTRL+D, or CTRL+Z...
779 passptr
= cg
->password
;
782 else if ((passch
& 255) < 0x20 || passptr
>= passend
)
787 putchar(_CUPS_PASSCHAR
);
800 tcsetattr(tty
, TCSAFLUSH
, &original
);
804 * Return the proper value...
807 if (passbytes
== 1 && passptr
> cg
->password
)
810 return (cg
->password
);
814 memset(cg
->password
, 0, sizeof(cg
->password
));
823 * '_cupsGSSServiceName()' - Get the GSS (Kerberos) service name.
827 _cupsGSSServiceName(void)
829 _cups_globals_t
*cg
= _cupsGlobals(); /* Thread globals */
832 if (!cg
->gss_service_name
[0])
835 return (cg
->gss_service_name
);
837 #endif /* HAVE_GSSAPI */
841 * '_cupsSetDefaults()' - Set the default server, port, and encryption.
845 _cupsSetDefaults(void)
847 cups_file_t
*fp
; /* File */
848 const char *home
, /* Home directory of user */
849 *cups_encryption
, /* CUPS_ENCRYPTION env var */
850 *cups_server
, /* CUPS_SERVER env var */
851 *cups_user
, /* CUPS_USER/USER env var */
853 *cups_gssservicename
, /* CUPS_GSSSERVICENAME env var */
854 #endif /* HAVE_GSSAPI */
855 *cups_anyroot
, /* CUPS_ANYROOT env var */
856 *cups_expiredroot
, /* CUPS_EXPIREDROOT env var */
857 *cups_expiredcerts
; /* CUPS_EXPIREDCERTS env var */
858 char filename
[1024]; /* Filename */
859 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
862 DEBUG_puts("_cupsSetDefaults()");
865 * First collect environment variables...
868 cups_encryption
= getenv("CUPS_ENCRYPTION");
869 cups_server
= getenv("CUPS_SERVER");
871 cups_gssservicename
= getenv("CUPS_GSSSERVICENAME");
872 #endif /* HAVE_GSSAPI */
873 cups_anyroot
= getenv("CUPS_ANYROOT");
874 cups_expiredroot
= getenv("CUPS_EXPIREDROOT");
875 cups_expiredcerts
= getenv("CUPS_EXPIREDCERTS");
877 if ((cups_user
= getenv("CUPS_USER")) == NULL
)
878 cups_user
= getenv("USER");
881 * Then, if needed, read the ~/.cups/client.conf or /etc/cups/client.conf
882 * files to get the default values...
885 if (cg
->encryption
== (http_encryption_t
)-1 || !cg
->server
[0] ||
886 !cg
->user
[0] || !cg
->ipp_port
)
888 if ((home
= getenv("HOME")) != NULL
)
891 * Look for ~/.cups/client.conf...
894 snprintf(filename
, sizeof(filename
), "%s/.cups/client.conf", home
);
895 fp
= cupsFileOpen(filename
, "r");
903 * Look for CUPS_SERVERROOT/client.conf...
906 snprintf(filename
, sizeof(filename
), "%s/client.conf",
907 cg
->cups_serverroot
);
908 fp
= cupsFileOpen(filename
, "r");
912 * Read the configuration file and apply any environment variables; both
913 * functions handle NULL cups_file_t pointers...
916 cups_read_client_conf(fp
, cg
, cups_encryption
, cups_server
, cups_user
,
919 #endif /* HAVE_GSSAPI */
920 cups_anyroot
, cups_expiredroot
,
928 * 'cups_read_client_conf()' - Read a client.conf file.
932 cups_read_client_conf(
933 cups_file_t
*fp
, /* I - File to read */
934 _cups_globals_t
*cg
, /* I - Global data */
935 const char *cups_encryption
, /* I - CUPS_ENCRYPTION env var */
936 const char *cups_server
, /* I - CUPS_SERVER env var */
937 const char *cups_user
, /* I - CUPS_USER env var */
939 const char *cups_gssservicename
,
940 /* I - CUPS_GSSSERVICENAME env var */
941 #endif /* HAVE_GSSAPI */
942 const char *cups_anyroot
, /* I - CUPS_ANYROOT env var */
943 const char *cups_expiredroot
, /* I - CUPS_EXPIREDROOT env var */
944 const char *cups_expiredcerts
) /* I - CUPS_EXPIREDCERTS env var */
946 int linenum
; /* Current line number */
947 char line
[1024], /* Line from file */
948 *value
, /* Pointer into line */
949 encryption
[1024], /* Encryption value */
951 server_name
[1024], /* ServerName value */
952 #endif /* !__APPLE__ */
953 user
[256], /* User value */
954 any_root
[1024], /* AllowAnyRoot value */
955 expired_root
[1024], /* AllowExpiredRoot value */
956 expired_certs
[1024]; /* AllowExpiredCerts value */
958 char gss_service_name
[32]; /* GSSServiceName value */
959 #endif /* HAVE_GSSAPI */
963 * Read from the file...
967 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
969 if (!cups_encryption
&& cg
->encryption
== (http_encryption_t
)-1 &&
970 !_cups_strcasecmp(line
, "Encryption") && value
)
972 strlcpy(encryption
, value
, sizeof(encryption
));
973 cups_encryption
= encryption
;
977 * The Server directive is not supported on OS X due to app sandboxing
978 * restrictions, i.e. not all apps request network access.
980 else if (!cups_server
&& (!cg
->server
[0] || !cg
->ipp_port
) &&
981 !_cups_strcasecmp(line
, "ServerName") && value
)
983 strlcpy(server_name
, value
, sizeof(server_name
));
984 cups_server
= server_name
;
986 #endif /* !__APPLE__ */
987 else if (!cups_user
&& !_cups_strcasecmp(line
, "User") && value
)
989 strlcpy(user
, value
, sizeof(user
));
992 else if (!cups_anyroot
&& !_cups_strcasecmp(line
, "AllowAnyRoot") && value
)
994 strlcpy(any_root
, value
, sizeof(any_root
));
995 cups_anyroot
= any_root
;
997 else if (!cups_expiredroot
&& !_cups_strcasecmp(line
, "AllowExpiredRoot") &&
1000 strlcpy(expired_root
, value
, sizeof(expired_root
));
1001 cups_expiredroot
= expired_root
;
1003 else if (!cups_expiredcerts
&& !_cups_strcasecmp(line
, "AllowExpiredCerts") &&
1006 strlcpy(expired_certs
, value
, sizeof(expired_certs
));
1007 cups_expiredcerts
= expired_certs
;
1010 else if (!cups_gssservicename
&& !_cups_strcasecmp(line
, "GSSServiceName") &&
1013 strlcpy(gss_service_name
, value
, sizeof(gss_service_name
));
1014 cups_gssservicename
= gss_service_name
;
1016 #endif /* HAVE_GSSAPI */
1023 if (cg
->encryption
== (http_encryption_t
)-1 && cups_encryption
)
1025 if (!_cups_strcasecmp(cups_encryption
, "never"))
1026 cg
->encryption
= HTTP_ENCRYPTION_NEVER
;
1027 else if (!_cups_strcasecmp(cups_encryption
, "always"))
1028 cg
->encryption
= HTTP_ENCRYPTION_ALWAYS
;
1029 else if (!_cups_strcasecmp(cups_encryption
, "required"))
1030 cg
->encryption
= HTTP_ENCRYPTION_REQUIRED
;
1032 cg
->encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
1035 if ((!cg
->server
[0] || !cg
->ipp_port
) && cups_server
)
1036 cupsSetServer(cups_server
);
1040 #ifdef CUPS_DEFAULT_DOMAINSOCKET
1042 * If we are compiled with domain socket support, only use the
1043 * domain socket if it exists and has the right permissions...
1046 struct stat sockinfo
; /* Domain socket information */
1048 if (!stat(CUPS_DEFAULT_DOMAINSOCKET
, &sockinfo
) &&
1049 (sockinfo
.st_mode
& S_IRWXO
) == S_IRWXO
)
1050 cups_server
= CUPS_DEFAULT_DOMAINSOCKET
;
1052 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
1053 cups_server
= "localhost";
1055 cupsSetServer(cups_server
);
1060 const char *ipp_port
; /* IPP_PORT environment variable */
1062 if ((ipp_port
= getenv("IPP_PORT")) != NULL
)
1064 if ((cg
->ipp_port
= atoi(ipp_port
)) <= 0)
1065 cg
->ipp_port
= CUPS_DEFAULT_IPP_PORT
;
1068 cg
->ipp_port
= CUPS_DEFAULT_IPP_PORT
;
1074 strlcpy(cg
->user
, cups_user
, sizeof(cg
->user
));
1079 * Get the current user name from the OS...
1082 DWORD size
; /* Size of string */
1084 size
= sizeof(cg
->user
);
1085 if (!GetUserName(cg
->user
, &size
))
1088 * Get the user name corresponding to the current UID...
1091 struct passwd
*pwd
; /* User/password entry */
1094 if ((pwd
= getpwuid(getuid())) != NULL
)
1100 strlcpy(cg
->user
, pwd
->pw_name
, sizeof(cg
->user
));
1106 * Use the default "unknown" user name...
1109 strlcpy(cg
->user
, "unknown", sizeof(cg
->user
));
1115 if (!cups_gssservicename
)
1116 cups_gssservicename
= CUPS_DEFAULT_GSSSERVICENAME
;
1118 strlcpy(cg
->gss_service_name
, cups_gssservicename
,
1119 sizeof(cg
->gss_service_name
));
1120 #endif /* HAVE_GSSAPI */
1123 cg
->any_root
= !_cups_strcasecmp(cups_anyroot
, "yes") ||
1124 !_cups_strcasecmp(cups_anyroot
, "on") ||
1125 !_cups_strcasecmp(cups_anyroot
, "true");
1127 if (cups_expiredroot
)
1128 cg
->expired_root
= !_cups_strcasecmp(cups_expiredroot
, "yes") ||
1129 !_cups_strcasecmp(cups_expiredroot
, "on") ||
1130 !_cups_strcasecmp(cups_expiredroot
, "true");
1132 if (cups_expiredcerts
)
1133 cg
->expired_certs
= !_cups_strcasecmp(cups_expiredcerts
, "yes") ||
1134 !_cups_strcasecmp(cups_expiredcerts
, "on") ||
1135 !_cups_strcasecmp(cups_expiredcerts
, "true");