4 * User, system, and password routines for CUPS.
6 * Copyright 2007-2014 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 * Include necessary headers...
22 #include "cups-private.h"
30 # include <sys/utsname.h>
38 #define _CUPS_PASSCHAR '*' /* Character that is echoed for password */
45 static void cups_read_client_conf(cups_file_t
*fp
,
47 const char *cups_encryption
,
48 const char *cups_server
,
49 const char *cups_user
,
51 const char *cups_gssservicename
,
52 #endif /* HAVE_GSSAPI */
53 const char *cups_anyroot
,
54 const char *cups_expiredcerts
,
55 const char *cups_validatecerts
);
59 * 'cupsEncryption()' - Get the current encryption settings.
61 * The default encryption setting comes from the CUPS_ENCRYPTION
62 * environment variable, then the ~/.cups/client.conf file, and finally the
63 * /etc/cups/client.conf file. If not set, the default is
64 * @code HTTP_ENCRYPTION_IF_REQUESTED@.
66 * Note: The current encryption setting is tracked separately for each thread
67 * in a program. Multi-threaded programs that override the setting via the
68 * @link cupsSetEncryption@ function need to do so in each thread for the same
72 http_encryption_t
/* O - Encryption settings */
75 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
78 if (cg
->encryption
== (http_encryption_t
)-1)
81 return (cg
->encryption
);
86 * 'cupsGetPassword()' - Get a password from the user.
88 * Uses the current password callback function. Returns @code NULL@ if the
89 * user does not provide a password.
91 * Note: The current password callback function is tracked separately for each
92 * thread in a program. Multi-threaded programs that override the setting via
93 * the @link cupsSetPasswordCB@ or @link cupsSetPasswordCB2@ functions need to
94 * do so in each thread for the same function to be used.
97 const char * /* O - Password */
98 cupsGetPassword(const char *prompt
) /* I - Prompt string */
100 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
103 return ((cg
->password_cb
)(prompt
, NULL
, NULL
, NULL
, cg
->password_data
));
108 * 'cupsGetPassword2()' - Get a password from the user using the advanced
111 * Uses the current password callback function. Returns @code NULL@ if the
112 * user does not provide a password.
114 * Note: The current password callback function is tracked separately for each
115 * thread in a program. Multi-threaded programs that override the setting via
116 * the @link cupsSetPasswordCB@ or @link cupsSetPasswordCB2@ functions need to
117 * do so in each thread for the same function to be used.
119 * @since CUPS 1.4/OS X 10.6@
122 const char * /* O - Password */
123 cupsGetPassword2(const char *prompt
, /* I - Prompt string */
124 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
125 const char *method
, /* I - Request method ("GET", "POST", "PUT") */
126 const char *resource
) /* I - Resource path */
128 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
132 http
= _cupsConnect();
134 return ((cg
->password_cb
)(prompt
, http
, method
, resource
, cg
->password_data
));
139 * 'cupsServer()' - Return the hostname/address of the current server.
141 * The default server comes from the CUPS_SERVER environment variable, then the
142 * ~/.cups/client.conf file, and finally the /etc/cups/client.conf file. If not
143 * set, the default is the local system - either "localhost" or a domain socket
146 * The returned value can be a fully-qualified hostname, a numeric IPv4 or IPv6
147 * address, or a domain socket pathname.
149 * Note: The current server is tracked separately for each thread in a program.
150 * Multi-threaded programs that override the server via the
151 * @link cupsSetServer@ function need to do so in each thread for the same
155 const char * /* O - Server name */
158 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
169 * 'cupsSetClientCertCB()' - Set the client certificate callback.
171 * Pass @code NULL@ to restore the default callback.
173 * Note: The current certificate callback is tracked separately for each thread
174 * in a program. Multi-threaded programs that override the callback need to do
175 * so in each thread for the same callback to be used.
177 * @since CUPS 1.5/OS X 10.7@
182 cups_client_cert_cb_t cb
, /* I - Callback function */
183 void *user_data
) /* I - User data pointer */
185 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
188 cg
->client_cert_cb
= cb
;
189 cg
->client_cert_data
= user_data
;
194 * 'cupsSetCredentials()' - Set the default credentials to be used for SSL/TLS
197 * Note: The default credentials are tracked separately for each thread in a
198 * program. Multi-threaded programs that override the setting need to do so in
199 * each thread for the same setting to be used.
201 * @since CUPS 1.5/OS X 10.7@
204 int /* O - Status of call (0 = success) */
206 cups_array_t
*credentials
) /* I - Array of credentials */
208 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
211 if (cupsArrayCount(credentials
) < 1)
214 _httpFreeCredentials(cg
->tls_credentials
);
215 cg
->tls_credentials
= _httpCreateCredentials(credentials
);
217 return (cg
->tls_credentials
? 0 : -1);
222 * 'cupsSetEncryption()' - Set the encryption preference.
224 * The default encryption setting comes from the CUPS_ENCRYPTION
225 * environment variable, then the ~/.cups/client.conf file, and finally the
226 * /etc/cups/client.conf file. If not set, the default is
227 * @code HTTP_ENCRYPTION_IF_REQUESTED@.
229 * Note: The current encryption setting is tracked separately for each thread
230 * in a program. Multi-threaded programs that override the setting need to do
231 * so in each thread for the same setting to be used.
235 cupsSetEncryption(http_encryption_t e
) /* I - New encryption preference */
237 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
243 httpEncryption(cg
->http
, e
);
248 * 'cupsSetPasswordCB()' - Set the password callback for CUPS.
250 * Pass @code NULL@ to restore the default (console) password callback, which
251 * reads the password from the console. Programs should call either this
252 * function or @link cupsSetPasswordCB2@, as only one callback can be registered
253 * by a program per thread.
255 * Note: The current password callback is tracked separately for each thread
256 * in a program. Multi-threaded programs that override the callback need to do
257 * so in each thread for the same callback to be used.
261 cupsSetPasswordCB(cups_password_cb_t cb
)/* I - Callback function */
263 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
266 if (cb
== (cups_password_cb_t
)0)
267 cg
->password_cb
= (cups_password_cb2_t
)_cupsGetPassword
;
269 cg
->password_cb
= (cups_password_cb2_t
)cb
;
271 cg
->password_data
= NULL
;
276 * 'cupsSetPasswordCB2()' - Set the advanced password callback for CUPS.
278 * Pass @code NULL@ to restore the default (console) password callback, which
279 * reads the password from the console. Programs should call either this
280 * function or @link cupsSetPasswordCB2@, as only one callback can be registered
281 * by a program per thread.
283 * Note: The current password callback is tracked separately for each thread
284 * in a program. Multi-threaded programs that override the callback need to do
285 * so in each thread for the same callback to be used.
287 * @since CUPS 1.4/OS X 10.6@
292 cups_password_cb2_t cb
, /* I - Callback function */
293 void *user_data
) /* I - User data pointer */
295 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
298 if (cb
== (cups_password_cb2_t
)0)
299 cg
->password_cb
= (cups_password_cb2_t
)_cupsGetPassword
;
301 cg
->password_cb
= cb
;
303 cg
->password_data
= user_data
;
308 * 'cupsSetServer()' - Set the default server name and port.
310 * The "server" string can be a fully-qualified hostname, a numeric
311 * IPv4 or IPv6 address, or a domain socket pathname. Hostnames and numeric IP
312 * addresses can be optionally followed by a colon and port number to override
313 * the default port 631, e.g. "hostname:8631". Pass @code NULL@ to restore the
314 * default server name and port.
316 * Note: The current server is tracked separately for each thread in a program.
317 * Multi-threaded programs that override the server need to do so in each
318 * thread for the same server to be used.
322 cupsSetServer(const char *server
) /* I - Server name */
324 char *options
, /* Options */
325 *port
; /* Pointer to port */
326 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
331 strlcpy(cg
->server
, server
, sizeof(cg
->server
));
333 if (cg
->server
[0] != '/' && (options
= strrchr(cg
->server
, '/')) != NULL
)
337 if (!strcmp(options
, "version=1.0"))
338 cg
->server_version
= 10;
339 else if (!strcmp(options
, "version=1.1"))
340 cg
->server_version
= 11;
341 else if (!strcmp(options
, "version=2.0"))
342 cg
->server_version
= 20;
343 else if (!strcmp(options
, "version=2.1"))
344 cg
->server_version
= 21;
345 else if (!strcmp(options
, "version=2.2"))
346 cg
->server_version
= 22;
349 cg
->server_version
= 20;
351 if (cg
->server
[0] != '/' && (port
= strrchr(cg
->server
, ':')) != NULL
&&
352 !strchr(port
, ']') && isdigit(port
[1] & 255))
356 cg
->ipp_port
= atoi(port
);
359 if (cg
->server
[0] == '/')
360 strlcpy(cg
->servername
, "localhost", sizeof(cg
->servername
));
362 strlcpy(cg
->servername
, cg
->server
, sizeof(cg
->servername
));
366 cg
->server
[0] = '\0';
367 cg
->servername
[0] = '\0';
368 cg
->server_version
= 20;
380 * 'cupsSetServerCertCB()' - Set the server certificate callback.
382 * Pass @code NULL@ to restore the default callback.
384 * Note: The current credentials callback is tracked separately for each thread
385 * in a program. Multi-threaded programs that override the callback need to do
386 * so in each thread for the same callback to be used.
388 * @since CUPS 1.5/OS X 10.7@
393 cups_server_cert_cb_t cb
, /* I - Callback function */
394 void *user_data
) /* I - User data pointer */
396 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
399 cg
->server_cert_cb
= cb
;
400 cg
->server_cert_data
= user_data
;
405 * 'cupsSetUser()' - Set the default user name.
407 * Pass @code NULL@ to restore the default user name.
409 * Note: The current user name is tracked separately for each thread in a
410 * program. Multi-threaded programs that override the user name need to do so
411 * in each thread for the same user name to be used.
415 cupsSetUser(const char *user
) /* I - User name */
417 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
421 strlcpy(cg
->user
, user
, sizeof(cg
->user
));
428 * 'cupsSetUserAgent()' - Set the default HTTP User-Agent string.
430 * Setting the string to NULL forces the default value containing the CUPS
431 * version, IPP version, and operating system version and architecture.
433 * @since CUPS 1.7/OS X 10.9@
437 cupsSetUserAgent(const char *user_agent
)/* I - User-Agent string or @code NULL@ */
439 _cups_globals_t
*cg
= _cupsGlobals();
442 SYSTEM_INFO sysinfo
; /* System information */
443 OSVERSIONINFO version
; /* OS version info */
445 struct utsname name
; /* uname info */
451 strlcpy(cg
->user_agent
, user_agent
, sizeof(cg
->user_agent
));
456 version
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
457 GetVersionEx(&version
);
458 GetNativeSystemInfo(&sysinfo
);
460 snprintf(cg
->user_agent
, sizeof(cg
->user_agent
),
461 CUPS_MINIMAL
" (Windows %d.%d; %s) IPP/2.0",
462 version
.dwMajorVersion
, version
.dwMinorVersion
,
463 sysinfo
.wProcessorArchitecture
464 == PROCESSOR_ARCHITECTURE_AMD64
? "amd64" :
465 sysinfo
.wProcessorArchitecture
466 == PROCESSOR_ARCHITECTURE_ARM
? "arm" :
467 sysinfo
.wProcessorArchitecture
468 == PROCESSOR_ARCHITECTURE_IA64
? "ia64" :
469 sysinfo
.wProcessorArchitecture
470 == PROCESSOR_ARCHITECTURE_INTEL
? "intel" :
476 snprintf(cg
->user_agent
, sizeof(cg
->user_agent
),
477 CUPS_MINIMAL
" (%s %s; %s) IPP/2.0",
478 name
.sysname
, name
.release
, name
.machine
);
484 * 'cupsUser()' - Return the current user's name.
486 * Note: The current user name is tracked separately for each thread in a
487 * program. Multi-threaded programs that override the user name with the
488 * @link cupsSetUser@ function need to do so in each thread for the same user
492 const char * /* O - User name */
495 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
506 * 'cupsUserAgent()' - Return the default HTTP User-Agent string.
508 * @since CUPS 1.7/OS X 10.9@
511 const char * /* O - User-Agent string */
514 _cups_globals_t
*cg
= _cupsGlobals(); /* Thread globals */
517 if (!cg
->user_agent
[0])
518 cupsSetUserAgent(NULL
);
520 return (cg
->user_agent
);
525 * '_cupsGetPassword()' - Get a password from the user.
528 const char * /* O - Password or @code NULL@ if none */
529 _cupsGetPassword(const char *prompt
) /* I - Prompt string */
532 HANDLE tty
; /* Console handle */
533 DWORD mode
; /* Console mode */
534 char passch
, /* Current key press */
535 *passptr
, /* Pointer into password string */
536 *passend
; /* End of password string */
537 DWORD passbytes
; /* Bytes read */
538 _cups_globals_t
*cg
= _cupsGlobals();
543 * Disable input echo and set raw input...
546 if ((tty
= GetStdHandle(STD_INPUT_HANDLE
)) == INVALID_HANDLE_VALUE
)
549 if (!GetConsoleMode(tty
, &mode
))
552 if (!SetConsoleMode(tty
, 0))
556 * Display the prompt...
559 printf("%s ", prompt
);
563 * Read the password string from /dev/tty until we get interrupted or get a
564 * carriage return or newline...
567 passptr
= cg
->password
;
568 passend
= cg
->password
+ sizeof(cg
->password
) - 1;
570 while (ReadFile(tty
, &passch
, 1, &passbytes
, NULL
))
572 if (passch
== 0x0A || passch
== 0x0D)
580 else if (passch
== 0x08 || passch
== 0x7F)
583 * Backspace/delete (erase character)...
586 if (passptr
> cg
->password
)
589 fputs("\010 \010", stdout
);
594 else if (passch
== 0x15)
597 * CTRL+U (erase line)
600 if (passptr
> cg
->password
)
602 while (passptr
> cg
->password
)
605 fputs("\010 \010", stdout
);
611 else if (passch
== 0x03)
617 passptr
= cg
->password
;
620 else if ((passch
& 255) < 0x20 || passptr
>= passend
)
625 putchar(_CUPS_PASSCHAR
);
638 SetConsoleMode(tty
, mode
);
641 * Return the proper value...
644 if (passbytes
== 1 && passptr
> cg
->password
)
647 return (cg
->password
);
651 memset(cg
->password
, 0, sizeof(cg
->password
));
656 int tty
; /* /dev/tty - never read from stdin */
657 struct termios original
, /* Original input mode */
658 noecho
; /* No echo input mode */
659 char passch
, /* Current key press */
660 *passptr
, /* Pointer into password string */
661 *passend
; /* End of password string */
662 ssize_t passbytes
; /* Bytes read */
663 _cups_globals_t
*cg
= _cupsGlobals();
668 * Disable input echo and set raw input...
671 if ((tty
= open("/dev/tty", O_RDONLY
)) < 0)
674 if (tcgetattr(tty
, &original
))
681 noecho
.c_lflag
&= (tcflag_t
)~(ICANON
| ECHO
| ECHOE
| ISIG
);
683 if (tcsetattr(tty
, TCSAFLUSH
, &noecho
))
690 * Display the prompt...
693 printf("%s ", prompt
);
697 * Read the password string from /dev/tty until we get interrupted or get a
698 * carriage return or newline...
701 passptr
= cg
->password
;
702 passend
= cg
->password
+ sizeof(cg
->password
) - 1;
704 while ((passbytes
= read(tty
, &passch
, 1)) == 1)
706 if (passch
== noecho
.c_cc
[VEOL
] ||
708 passch
== noecho
.c_cc
[VEOL2
] ||
710 passch
== 0x0A || passch
== 0x0D)
718 else if (passch
== noecho
.c_cc
[VERASE
] ||
719 passch
== 0x08 || passch
== 0x7F)
722 * Backspace/delete (erase character)...
725 if (passptr
> cg
->password
)
728 fputs("\010 \010", stdout
);
733 else if (passch
== noecho
.c_cc
[VKILL
])
736 * CTRL+U (erase line)
739 if (passptr
> cg
->password
)
741 while (passptr
> cg
->password
)
744 fputs("\010 \010", stdout
);
750 else if (passch
== noecho
.c_cc
[VINTR
] || passch
== noecho
.c_cc
[VQUIT
] ||
751 passch
== noecho
.c_cc
[VEOF
])
754 * CTRL+C, CTRL+D, or CTRL+Z...
757 passptr
= cg
->password
;
760 else if ((passch
& 255) < 0x20 || passptr
>= passend
)
765 putchar(_CUPS_PASSCHAR
);
778 tcsetattr(tty
, TCSAFLUSH
, &original
);
782 * Return the proper value...
785 if (passbytes
== 1 && passptr
> cg
->password
)
788 return (cg
->password
);
792 memset(cg
->password
, 0, sizeof(cg
->password
));
801 * '_cupsGSSServiceName()' - Get the GSS (Kerberos) service name.
805 _cupsGSSServiceName(void)
807 _cups_globals_t
*cg
= _cupsGlobals(); /* Thread globals */
810 if (!cg
->gss_service_name
[0])
813 return (cg
->gss_service_name
);
815 #endif /* HAVE_GSSAPI */
819 * '_cupsSetDefaults()' - Set the default server, port, and encryption.
823 _cupsSetDefaults(void)
825 cups_file_t
*fp
; /* File */
826 const char *home
, /* Home directory of user */
827 *cups_encryption
, /* CUPS_ENCRYPTION env var */
828 *cups_server
, /* CUPS_SERVER env var */
829 *cups_user
, /* CUPS_USER/USER env var */
831 *cups_gssservicename
, /* CUPS_GSSSERVICENAME env var */
832 #endif /* HAVE_GSSAPI */
833 *cups_anyroot
, /* CUPS_ANYROOT env var */
834 *cups_expiredcerts
, /* CUPS_EXPIREDCERTS env var */
835 *cups_validatecerts
; /* CUPS_VALIDATECERTS env var */
836 char filename
[1024]; /* Filename */
837 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
840 DEBUG_puts("_cupsSetDefaults()");
843 * First collect environment variables...
846 cups_encryption
= getenv("CUPS_ENCRYPTION");
847 cups_server
= getenv("CUPS_SERVER");
849 cups_gssservicename
= getenv("CUPS_GSSSERVICENAME");
850 #endif /* HAVE_GSSAPI */
851 cups_anyroot
= getenv("CUPS_ANYROOT");
852 cups_expiredcerts
= getenv("CUPS_EXPIREDCERTS");
853 cups_validatecerts
= getenv("CUPS_VALIDATECERTS");
855 if ((cups_user
= getenv("CUPS_USER")) == NULL
)
858 * Try the USER environment variable...
861 if ((cups_user
= getenv("USER")) != NULL
)
864 * Validate USER matches the current UID, otherwise don't allow it to
865 * override things... This makes sure that printing after doing su or
866 * sudo records the correct username.
869 struct passwd
*pw
; /* Account information */
871 if ((pw
= getpwnam(cups_user
)) == NULL
|| pw
->pw_uid
!= getuid())
877 * Then, if needed, read the ~/.cups/client.conf or /etc/cups/client.conf
878 * files to get the default values...
881 if (cg
->encryption
== (http_encryption_t
)-1 || !cg
->server
[0] ||
882 !cg
->user
[0] || !cg
->ipp_port
)
885 if ((geteuid() == getuid() || !getuid()) && getegid() == getgid() && (home
= getenv("HOME")) != NULL
)
886 # elif !defined(WIN32)
887 if (getuid() && (home
= getenv("HOME")) != NULL
)
889 if ((home
= getenv("HOME")) != NULL
)
890 # endif /* HAVE_GETEUID */
893 * Look for ~/.cups/client.conf...
896 snprintf(filename
, sizeof(filename
), "%s/.cups/client.conf", home
);
897 fp
= cupsFileOpen(filename
, "r");
905 * Look for CUPS_SERVERROOT/client.conf...
908 snprintf(filename
, sizeof(filename
), "%s/client.conf",
909 cg
->cups_serverroot
);
910 fp
= cupsFileOpen(filename
, "r");
914 * Read the configuration file and apply any environment variables; both
915 * functions handle NULL cups_file_t pointers...
918 cups_read_client_conf(fp
, cg
, cups_encryption
, cups_server
, cups_user
,
921 #endif /* HAVE_GSSAPI */
922 cups_anyroot
, cups_expiredcerts
, cups_validatecerts
);
929 * 'cups_read_client_conf()' - Read a client.conf file.
933 cups_read_client_conf(
934 cups_file_t
*fp
, /* I - File to read */
935 _cups_globals_t
*cg
, /* I - Global data */
936 const char *cups_encryption
, /* I - CUPS_ENCRYPTION env var */
937 const char *cups_server
, /* I - CUPS_SERVER env var */
938 const char *cups_user
, /* I - CUPS_USER env var */
940 const char *cups_gssservicename
,
941 /* I - CUPS_GSSSERVICENAME env var */
942 #endif /* HAVE_GSSAPI */
943 const char *cups_anyroot
, /* I - CUPS_ANYROOT env var */
944 const char *cups_expiredcerts
, /* I - CUPS_EXPIREDCERTS env var */
945 const char *cups_validatecerts
)/* I - CUPS_VALIDATECERTS env var */
947 int linenum
; /* Current line number */
948 char line
[1024], /* Line from file */
949 *value
, /* Pointer into line */
950 encryption
[1024], /* Encryption value */
952 server_name
[1024], /* ServerName value */
953 #endif /* !__APPLE__ */
954 user
[256], /* User value */
955 any_root
[1024], /* AllowAnyRoot value */
956 expired_certs
[1024], /* AllowExpiredCerts value */
957 validate_certs
[1024]; /* ValidateCerts value */
959 char gss_service_name
[32]; /* GSSServiceName value */
960 #endif /* HAVE_GSSAPI */
964 * Read from the file...
968 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
970 if (!cups_encryption
&& cg
->encryption
== (http_encryption_t
)-1 &&
971 !_cups_strcasecmp(line
, "Encryption") && value
)
973 strlcpy(encryption
, value
, sizeof(encryption
));
974 cups_encryption
= encryption
;
978 * The Server directive is not supported on OS X due to app sandboxing
979 * restrictions, i.e. not all apps request network access.
981 else if (!cups_server
&& (!cg
->server
[0] || !cg
->ipp_port
) &&
982 !_cups_strcasecmp(line
, "ServerName") && value
)
984 strlcpy(server_name
, value
, sizeof(server_name
));
985 cups_server
= server_name
;
987 #endif /* !__APPLE__ */
988 else if (!cups_user
&& !_cups_strcasecmp(line
, "User") && value
)
990 strlcpy(user
, value
, sizeof(user
));
993 else if (!cups_anyroot
&& !_cups_strcasecmp(line
, "AllowAnyRoot") && value
)
995 strlcpy(any_root
, value
, sizeof(any_root
));
996 cups_anyroot
= any_root
;
998 else if (!cups_expiredcerts
&& !_cups_strcasecmp(line
, "AllowExpiredCerts") &&
1001 strlcpy(expired_certs
, value
, sizeof(expired_certs
));
1002 cups_expiredcerts
= expired_certs
;
1004 else if (!cups_validatecerts
&& !_cups_strcasecmp(line
, "ValidateCerts") && value
)
1006 strlcpy(validate_certs
, value
, sizeof(validate_certs
));
1007 cups_validatecerts
= validate_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_expiredcerts
)
1128 cg
->expired_certs
= !_cups_strcasecmp(cups_expiredcerts
, "yes") ||
1129 !_cups_strcasecmp(cups_expiredcerts
, "on") ||
1130 !_cups_strcasecmp(cups_expiredcerts
, "true");
1132 if (cups_validatecerts
)
1133 cg
->validate_certs
= !_cups_strcasecmp(cups_validatecerts
, "yes") ||
1134 !_cups_strcasecmp(cups_validatecerts
, "on") ||
1135 !_cups_strcasecmp(cups_validatecerts
, "true");