2 * "$Id: usersys.c 8498 2009-04-13 17:03:15Z mike $"
4 * User, system, and password routines for CUPS.
6 * Copyright 2007-2012 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 * cupsSetEncryption() - Set the encryption preference.
27 * cupsSetPasswordCB() - Set the password callback for CUPS.
28 * cupsSetPasswordCB2() - Set the advanced password callback for CUPS.
29 * cupsSetServer() - Set the default server name and port.
30 * cupsSetServerCertCB() - Set the server certificate callback.
31 * cupsSetUser() - Set the default user name.
32 * cupsUser() - Return the current user's name.
33 * _cupsGetPassword() - Get a password from the user.
34 * _cupsGSSServiceName() - Get the GSS (Kerberos) service name.
35 * _cupsSetDefaults() - Set the default server, port, and encryption.
36 * cups_read_client_conf() - Read a client.conf file.
40 * Include necessary headers...
43 #include "cups-private.h"
58 #define _CUPS_PASSCHAR '*' /* Character that is echoed for password */
65 static void cups_read_client_conf(cups_file_t
*fp
,
67 const char *cups_encryption
,
68 const char *cups_server
,
69 const char *cups_user
,
71 const char *cups_gssservicename
,
72 #endif /* HAVE_GSSAPI */
73 const char *cups_anyroot
,
74 const char *cups_expiredroot
,
75 const char *cups_expiredcerts
);
79 * 'cupsEncryption()' - Get the current encryption settings.
81 * The default encryption setting comes from the CUPS_ENCRYPTION
82 * environment variable, then the ~/.cups/client.conf file, and finally the
83 * /etc/cups/client.conf file. If not set, the default is
84 * @code HTTP_ENCRYPT_IF_REQUESTED@.
86 * Note: The current encryption setting is tracked separately for each thread
87 * in a program. Multi-threaded programs that override the setting via the
88 * @link cupsSetEncryption@ function need to do so in each thread for the same
92 http_encryption_t
/* O - Encryption settings */
95 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
98 if (cg
->encryption
== (http_encryption_t
)-1)
101 return (cg
->encryption
);
106 * 'cupsGetPassword()' - Get a password from the user.
108 * Uses the current password callback function. Returns @code NULL@ if the
109 * user does not provide a password.
111 * Note: The current password callback function is tracked separately for each
112 * thread in a program. Multi-threaded programs that override the setting via
113 * the @link cupsSetPasswordCB@ or @link cupsSetPasswordCB2@ functions need to
114 * do so in each thread for the same function to be used.
117 const char * /* O - Password */
118 cupsGetPassword(const char *prompt
) /* I - Prompt string */
120 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
123 return ((cg
->password_cb
)(prompt
, NULL
, NULL
, NULL
, cg
->password_data
));
128 * 'cupsGetPassword2()' - Get a password from the user using the advanced
131 * Uses the current password callback function. Returns @code NULL@ if the
132 * user does not provide a password.
134 * Note: The current password callback function is tracked separately for each
135 * thread in a program. Multi-threaded programs that override the setting via
136 * the @link cupsSetPasswordCB@ or @link cupsSetPasswordCB2@ functions need to
137 * do so in each thread for the same function to be used.
139 * @since CUPS 1.4/OS X 10.6@
142 const char * /* O - Password */
143 cupsGetPassword2(const char *prompt
, /* I - Prompt string */
144 http_t
*http
, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
145 const char *method
, /* I - Request method ("GET", "POST", "PUT") */
146 const char *resource
) /* I - Resource path */
148 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
152 http
= _cupsConnect();
154 return ((cg
->password_cb
)(prompt
, http
, method
, resource
, cg
->password_data
));
159 * 'cupsServer()' - Return the hostname/address of the current server.
161 * The default server comes from the CUPS_SERVER environment variable, then the
162 * ~/.cups/client.conf file, and finally the /etc/cups/client.conf file. If not
163 * set, the default is the local system - either "localhost" or a domain socket
166 * The returned value can be a fully-qualified hostname, a numeric IPv4 or IPv6
167 * address, or a domain socket pathname.
169 * Note: The current server is tracked separately for each thread in a program.
170 * Multi-threaded programs that override the server via the
171 * @link cupsSetServer@ function need to do so in each thread for the same
175 const char * /* O - Server name */
178 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
189 * 'cupsSetClientCertCB()' - Set the client certificate callback.
191 * Pass @code NULL@ to restore the default callback.
193 * Note: The current certificate callback is tracked separately for each thread
194 * in a program. Multi-threaded programs that override the callback need to do
195 * so in each thread for the same callback to be used.
197 * @since CUPS 1.5/OS X 10.7@
202 cups_client_cert_cb_t cb
, /* I - Callback function */
203 void *user_data
) /* I - User data pointer */
205 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
208 cg
->client_cert_cb
= cb
;
209 cg
->client_cert_data
= user_data
;
214 * 'cupsSetCredentials()' - Set the default credentials to be used for SSL/TLS
217 * Note: The default credentials are tracked separately for each thread in a
218 * program. Multi-threaded programs that override the setting need to do so in
219 * each thread for the same setting to be used.
221 * @since CUPS 1.5/OS X 10.7@
224 int /* O - Status of call (0 = success) */
226 cups_array_t
*credentials
) /* I - Array of credentials */
228 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
231 if (cupsArrayCount(credentials
) < 1)
234 _httpFreeCredentials(cg
->tls_credentials
);
235 cg
->tls_credentials
= _httpCreateCredentials(credentials
);
237 return (cg
->tls_credentials
? 0 : -1);
242 * 'cupsSetEncryption()' - Set the encryption preference.
244 * The default encryption setting comes from the CUPS_ENCRYPTION
245 * environment variable, then the ~/.cups/client.conf file, and finally the
246 * /etc/cups/client.conf file. If not set, the default is
247 * @code HTTP_ENCRYPT_IF_REQUESTED@.
249 * Note: The current encryption setting is tracked separately for each thread
250 * in a program. Multi-threaded programs that override the setting need to do
251 * so in each thread for the same setting to be used.
255 cupsSetEncryption(http_encryption_t e
) /* I - New encryption preference */
257 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
263 httpEncryption(cg
->http
, e
);
268 * 'cupsSetPasswordCB()' - Set the password callback for CUPS.
270 * Pass @code NULL@ to restore the default (console) password callback, which
271 * reads the password from the console. Programs should call either this
272 * function or @link cupsSetPasswordCB2@, as only one callback can be registered
273 * by a program per thread.
275 * Note: The current password callback is tracked separately for each thread
276 * in a program. Multi-threaded programs that override the callback need to do
277 * so in each thread for the same callback to be used.
281 cupsSetPasswordCB(cups_password_cb_t cb
)/* I - Callback function */
283 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
286 if (cb
== (cups_password_cb_t
)0)
287 cg
->password_cb
= (cups_password_cb2_t
)_cupsGetPassword
;
289 cg
->password_cb
= (cups_password_cb2_t
)cb
;
291 cg
->password_data
= NULL
;
296 * 'cupsSetPasswordCB2()' - Set the advanced password callback for CUPS.
298 * Pass @code NULL@ to restore the default (console) password callback, which
299 * reads the password from the console. Programs should call either this
300 * function or @link cupsSetPasswordCB2@, as only one callback can be registered
301 * by a program per thread.
303 * Note: The current password callback is tracked separately for each thread
304 * in a program. Multi-threaded programs that override the callback need to do
305 * so in each thread for the same callback to be used.
307 * @since CUPS 1.4/OS X 10.6@
312 cups_password_cb2_t cb
, /* I - Callback function */
313 void *user_data
) /* I - User data pointer */
315 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
318 if (cb
== (cups_password_cb2_t
)0)
319 cg
->password_cb
= (cups_password_cb2_t
)_cupsGetPassword
;
321 cg
->password_cb
= cb
;
323 cg
->password_data
= user_data
;
328 * 'cupsSetServer()' - Set the default server name and port.
330 * The "server" string can be a fully-qualified hostname, a numeric
331 * IPv4 or IPv6 address, or a domain socket pathname. Hostnames and numeric IP
332 * addresses can be optionally followed by a colon and port number to override
333 * the default port 631, e.g. "hostname:8631". Pass @code NULL@ to restore the
334 * default server name and port.
336 * Note: The current server is tracked separately for each thread in a program.
337 * Multi-threaded programs that override the server need to do so in each
338 * thread for the same server to be used.
342 cupsSetServer(const char *server
) /* I - Server name */
344 char *port
; /* Pointer to port */
345 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
350 strlcpy(cg
->server
, server
, sizeof(cg
->server
));
352 if (cg
->server
[0] != '/' && (port
= strrchr(cg
->server
, ':')) != NULL
&&
353 !strchr(port
, ']') && isdigit(port
[1] & 255))
357 cg
->ipp_port
= atoi(port
);
360 if (cg
->server
[0] == '/')
361 strcpy(cg
->servername
, "localhost");
363 strlcpy(cg
->servername
, cg
->server
, sizeof(cg
->servername
));
367 cg
->server
[0] = '\0';
368 cg
->servername
[0] = '\0';
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 * 'cupsUser()' - Return the current user's name.
430 * Note: The current user name is tracked separately for each thread in a
431 * program. Multi-threaded programs that override the user name with the
432 * @link cupsSetUser@ function need to do so in each thread for the same user
436 const char * /* O - User name */
439 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
450 * '_cupsGetPassword()' - Get a password from the user.
453 const char * /* O - Password or @code NULL@ if none */
454 _cupsGetPassword(const char *prompt
) /* I - Prompt string */
457 HANDLE tty
; /* Console handle */
458 DWORD mode
; /* Console mode */
459 char passch
, /* Current key press */
460 *passptr
, /* Pointer into password string */
461 *passend
; /* End of password string */
462 DWORD passbytes
; /* Bytes read */
463 _cups_globals_t
*cg
= _cupsGlobals();
468 * Disable input echo and set raw input...
471 if ((tty
= GetStdHandle(STD_INPUT_HANDLE
)) == INVALID_HANDLE_VALUE
)
474 if (!GetConsoleMode(tty
, &mode
))
477 if (!SetConsoleMode(tty
, 0))
481 * Display the prompt...
484 printf("%s ", prompt
);
488 * Read the password string from /dev/tty until we get interrupted or get a
489 * carriage return or newline...
492 passptr
= cg
->password
;
493 passend
= cg
->password
+ sizeof(cg
->password
) - 1;
495 while (ReadFile(tty
, &passch
, 1, &passbytes
, NULL
))
497 if (passch
== 0x0A || passch
== 0x0D)
505 else if (passch
== 0x08 || passch
== 0x7F)
508 * Backspace/delete (erase character)...
511 if (passptr
> cg
->password
)
514 fputs("\010 \010", stdout
);
519 else if (passch
== 0x15)
522 * CTRL+U (erase line)
525 if (passptr
> cg
->password
)
527 while (passptr
> cg
->password
)
530 fputs("\010 \010", stdout
);
536 else if (passch
== 0x03)
542 passptr
= cg
->password
;
545 else if ((passch
& 255) < 0x20 || passptr
>= passend
)
550 putchar(_CUPS_PASSCHAR
);
563 SetConsoleMode(tty
, mode
);
566 * Return the proper value...
569 if (passbytes
== 1 && passptr
> cg
->password
)
572 return (cg
->password
);
576 memset(cg
->password
, 0, sizeof(cg
->password
));
581 int tty
; /* /dev/tty - never read from stdin */
582 struct termios original
, /* Original input mode */
583 noecho
; /* No echo input mode */
584 char passch
, /* Current key press */
585 *passptr
, /* Pointer into password string */
586 *passend
; /* End of password string */
587 ssize_t passbytes
; /* Bytes read */
588 _cups_globals_t
*cg
= _cupsGlobals();
593 * Disable input echo and set raw input...
596 if ((tty
= open("/dev/tty", O_RDONLY
)) < 0)
599 if (tcgetattr(tty
, &original
))
606 noecho
.c_lflag
&= ~(ICANON
| ECHO
| ECHOE
| ISIG
);
608 if (tcsetattr(tty
, TCSAFLUSH
, &noecho
))
615 * Display the prompt...
618 printf("%s ", prompt
);
622 * Read the password string from /dev/tty until we get interrupted or get a
623 * carriage return or newline...
626 passptr
= cg
->password
;
627 passend
= cg
->password
+ sizeof(cg
->password
) - 1;
629 while ((passbytes
= read(tty
, &passch
, 1)) == 1)
631 if (passch
== noecho
.c_cc
[VEOL
] || passch
== noecho
.c_cc
[VEOL2
] ||
632 passch
== 0x0A || passch
== 0x0D)
640 else if (passch
== noecho
.c_cc
[VERASE
] ||
641 passch
== 0x08 || passch
== 0x7F)
644 * Backspace/delete (erase character)...
647 if (passptr
> cg
->password
)
650 fputs("\010 \010", stdout
);
655 else if (passch
== noecho
.c_cc
[VKILL
])
658 * CTRL+U (erase line)
661 if (passptr
> cg
->password
)
663 while (passptr
> cg
->password
)
666 fputs("\010 \010", stdout
);
672 else if (passch
== noecho
.c_cc
[VINTR
] || passch
== noecho
.c_cc
[VQUIT
] ||
673 passch
== noecho
.c_cc
[VEOF
])
676 * CTRL+C, CTRL+D, or CTRL+Z...
679 passptr
= cg
->password
;
682 else if ((passch
& 255) < 0x20 || passptr
>= passend
)
687 putchar(_CUPS_PASSCHAR
);
700 tcsetattr(tty
, TCSAFLUSH
, &original
);
704 * Return the proper value...
707 if (passbytes
== 1 && passptr
> cg
->password
)
710 return (cg
->password
);
714 memset(cg
->password
, 0, sizeof(cg
->password
));
723 * '_cupsGSSServiceName()' - Get the GSS (Kerberos) service name.
727 _cupsGSSServiceName(void)
729 _cups_globals_t
*cg
= _cupsGlobals(); /* Thread globals */
732 if (!cg
->gss_service_name
[0])
735 return (cg
->gss_service_name
);
737 #endif /* HAVE_GSSAPI */
741 * '_cupsSetDefaults()' - Set the default server, port, and encryption.
745 _cupsSetDefaults(void)
747 cups_file_t
*fp
; /* File */
748 const char *home
, /* Home directory of user */
749 *cups_encryption
, /* CUPS_ENCRYPTION env var */
750 *cups_server
, /* CUPS_SERVER env var */
751 *cups_user
, /* CUPS_USER/USER env var */
753 *cups_gssservicename
, /* CUPS_GSSSERVICENAME env var */
754 #endif /* HAVE_GSSAPI */
755 *cups_anyroot
, /* CUPS_ANYROOT env var */
756 *cups_expiredroot
, /* CUPS_EXPIREDROOT env var */
757 *cups_expiredcerts
; /* CUPS_EXPIREDCERTS env var */
758 char filename
[1024]; /* Filename */
759 _cups_globals_t
*cg
= _cupsGlobals(); /* Pointer to library globals */
762 DEBUG_puts("_cupsSetDefaults()");
765 * First collect environment variables...
768 cups_encryption
= getenv("CUPS_ENCRYPTION");
769 cups_server
= getenv("CUPS_SERVER");
771 cups_gssservicename
= getenv("CUPS_GSSSERVICENAME");
772 #endif /* HAVE_GSSAPI */
773 cups_anyroot
= getenv("CUPS_ANYROOT");
774 cups_expiredroot
= getenv("CUPS_EXPIREDROOT");
775 cups_expiredcerts
= getenv("CUPS_EXPIREDCERTS");
777 if ((cups_user
= getenv("CUPS_USER")) == NULL
)
778 cups_user
= getenv("USER");
781 * Then, if needed, read the ~/.cups/client.conf or /etc/cups/client.conf
782 * files to get the default values...
785 if (cg
->encryption
== (http_encryption_t
)-1 || !cg
->server
[0] ||
786 !cg
->user
[0] || !cg
->ipp_port
)
788 if ((home
= getenv("HOME")) != NULL
)
791 * Look for ~/.cups/client.conf...
794 snprintf(filename
, sizeof(filename
), "%s/.cups/client.conf", home
);
795 fp
= cupsFileOpen(filename
, "r");
803 * Look for CUPS_SERVERROOT/client.conf...
806 snprintf(filename
, sizeof(filename
), "%s/client.conf",
807 cg
->cups_serverroot
);
808 fp
= cupsFileOpen(filename
, "r");
812 * Read the configuration file and apply any environment variables; both
813 * functions handle NULL cups_file_t pointers...
816 cups_read_client_conf(fp
, cg
, cups_encryption
, cups_server
, cups_user
,
819 #endif /* HAVE_GSSAPI */
820 cups_anyroot
, cups_expiredroot
,
828 * 'cups_read_client_conf()' - Read a client.conf file.
832 cups_read_client_conf(
833 cups_file_t
*fp
, /* I - File to read */
834 _cups_globals_t
*cg
, /* I - Global data */
835 const char *cups_encryption
, /* I - CUPS_ENCRYPTION env var */
836 const char *cups_server
, /* I - CUPS_SERVER env var */
837 const char *cups_user
, /* I - CUPS_USER env var */
839 const char *cups_gssservicename
,
840 /* I - CUPS_GSSSERVICENAME env var */
841 #endif /* HAVE_GSSAPI */
842 const char *cups_anyroot
, /* I - CUPS_ANYROOT env var */
843 const char *cups_expiredroot
, /* I - CUPS_EXPIREDROOT env var */
844 const char *cups_expiredcerts
) /* I - CUPS_EXPIREDCERTS env var */
846 int linenum
; /* Current line number */
847 char line
[1024], /* Line from file */
848 *value
, /* Pointer into line */
849 encryption
[1024], /* Encryption value */
851 server_name
[1024], /* ServerName value */
852 #endif /* !__APPLE__ */
853 user
[256], /* User value */
854 any_root
[1024], /* AllowAnyRoot value */
855 expired_root
[1024], /* AllowExpiredRoot value */
856 expired_certs
[1024]; /* AllowExpiredCerts value */
858 char gss_service_name
[32]; /* GSSServiceName value */
859 #endif /* HAVE_GSSAPI */
863 * Read from the file...
867 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
869 if (!cups_encryption
&& cg
->encryption
== (http_encryption_t
)-1 &&
870 !_cups_strcasecmp(line
, "Encryption") && value
)
872 strlcpy(encryption
, value
, sizeof(encryption
));
873 cups_encryption
= encryption
;
877 * The Server directive is not supported on OS X due to app sandboxing
878 * restrictions, i.e. not all apps request network access.
880 else if (!cups_server
&& (!cg
->server
[0] || !cg
->ipp_port
) &&
881 !_cups_strcasecmp(line
, "ServerName") && value
)
883 strlcpy(server_name
, value
, sizeof(server_name
));
884 cups_server
= server_name
;
886 #endif /* !__APPLE__ */
887 else if (!cups_user
&& !_cups_strcasecmp(line
, "User") && value
)
889 strlcpy(user
, value
, sizeof(user
));
892 else if (!cups_anyroot
&& !_cups_strcasecmp(line
, "AllowAnyRoot") && value
)
894 strlcpy(any_root
, value
, sizeof(any_root
));
895 cups_anyroot
= any_root
;
897 else if (!cups_expiredroot
&& !_cups_strcasecmp(line
, "AllowExpiredRoot") &&
900 strlcpy(expired_root
, value
, sizeof(expired_root
));
901 cups_expiredroot
= expired_root
;
903 else if (!cups_expiredcerts
&& !_cups_strcasecmp(line
, "AllowExpiredCerts") &&
906 strlcpy(expired_certs
, value
, sizeof(expired_certs
));
907 cups_expiredcerts
= expired_certs
;
910 else if (!cups_gssservicename
&& !_cups_strcasecmp(line
, "GSSServiceName") &&
913 strlcpy(gss_service_name
, value
, sizeof(gss_service_name
));
914 cups_gssservicename
= gss_service_name
;
916 #endif /* HAVE_GSSAPI */
923 if (cg
->encryption
== (http_encryption_t
)-1 && cups_encryption
)
925 if (!_cups_strcasecmp(cups_encryption
, "never"))
926 cg
->encryption
= HTTP_ENCRYPT_NEVER
;
927 else if (!_cups_strcasecmp(cups_encryption
, "always"))
928 cg
->encryption
= HTTP_ENCRYPT_ALWAYS
;
929 else if (!_cups_strcasecmp(cups_encryption
, "required"))
930 cg
->encryption
= HTTP_ENCRYPT_REQUIRED
;
932 cg
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
935 if ((!cg
->server
[0] || !cg
->ipp_port
) && cups_server
)
940 * Copy server name...
943 strlcpy(cg
->server
, cups_server
, sizeof(cg
->server
));
945 if (cg
->server
[0] != '/' && (value
= strrchr(cg
->server
, ':')) != NULL
&&
946 !strchr(value
, ']') && isdigit(value
[1] & 255))
951 if (cg
->server
[0] == '/')
952 strcpy(cg
->servername
, "localhost");
954 strlcpy(cg
->servername
, cg
->server
, sizeof(cg
->servername
));
956 else if (cups_server
[0] != '/' &&
957 (value
= strrchr(cups_server
, ':')) != NULL
&&
958 !strchr(value
, ']') && isdigit(value
[1] & 255))
963 if (!cg
->ipp_port
&& value
)
964 cg
->ipp_port
= atoi(value
);
969 #ifdef CUPS_DEFAULT_DOMAINSOCKET
971 * If we are compiled with domain socket support, only use the
972 * domain socket if it exists and has the right permissions...
975 struct stat sockinfo
; /* Domain socket information */
977 if (!stat(CUPS_DEFAULT_DOMAINSOCKET
, &sockinfo
) &&
978 (sockinfo
.st_mode
& S_IRWXO
) == S_IRWXO
)
979 cups_server
= CUPS_DEFAULT_DOMAINSOCKET
;
981 #endif /* CUPS_DEFAULT_DOMAINSOCKET */
982 cups_server
= "localhost";
984 cupsSetServer(cups_server
);
989 const char *ipp_port
; /* IPP_PORT environment variable */
991 if ((ipp_port
= getenv("IPP_PORT")) != NULL
)
993 if ((cg
->ipp_port
= atoi(ipp_port
)) <= 0)
994 cg
->ipp_port
= CUPS_DEFAULT_IPP_PORT
;
997 cg
->ipp_port
= CUPS_DEFAULT_IPP_PORT
;
1003 strlcpy(cg
->user
, cups_user
, sizeof(cg
->user
));
1008 * Get the current user name from the OS...
1011 DWORD size
; /* Size of string */
1013 size
= sizeof(cg
->user
);
1014 if (!GetUserName(cg
->user
, &size
))
1017 * Get the user name corresponding to the current UID...
1020 struct passwd
*pwd
; /* User/password entry */
1023 if ((pwd
= getpwuid(getuid())) != NULL
)
1029 strlcpy(cg
->user
, pwd
->pw_name
, sizeof(cg
->user
));
1035 * Use the default "unknown" user name...
1038 strcpy(cg
->user
, "unknown");
1044 if (!cups_gssservicename
)
1045 cups_gssservicename
= CUPS_DEFAULT_GSSSERVICENAME
;
1047 strlcpy(cg
->gss_service_name
, cups_gssservicename
,
1048 sizeof(cg
->gss_service_name
));
1049 #endif /* HAVE_GSSAPI */
1052 cg
->any_root
= !_cups_strcasecmp(cups_anyroot
, "yes") ||
1053 !_cups_strcasecmp(cups_anyroot
, "on") ||
1054 !_cups_strcasecmp(cups_anyroot
, "true");
1056 if (cups_expiredroot
)
1057 cg
->expired_root
= !_cups_strcasecmp(cups_expiredroot
, "yes") ||
1058 !_cups_strcasecmp(cups_expiredroot
, "on") ||
1059 !_cups_strcasecmp(cups_expiredroot
, "true");
1061 if (cups_expiredcerts
)
1062 cg
->expired_certs
= !_cups_strcasecmp(cups_expiredcerts
, "yes") ||
1063 !_cups_strcasecmp(cups_expiredcerts
, "on") ||
1064 !_cups_strcasecmp(cups_expiredcerts
, "true");
1069 * End of "$Id: usersys.c 8498 2009-04-13 17:03:15Z mike $".