2 * "$Id: auth.c 6947 2007-09-12 21:09:49Z mike $"
4 * Authorization routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * This file contains Kerberos support code, copyright 2006 by
12 * These coded instructions, statements, and computer programs are the
13 * property of Apple Inc. and are protected by Federal copyright
14 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
15 * which should have been included with this file. If this file is
16 * file is missing or damaged, see the license at "http://www.cups.org/".
20 * cupsdAddLocation() - Add a location for authorization.
21 * cupsdAddName() - Add a name to a location...
22 * cupsdAllowHost() - Add a host name that is allowed to access the
24 * cupsdAllowIP() - Add an IP address or network that is allowed to
25 * access the location.
26 * cupsdAuthorize() - Validate any authorization credentials.
27 * cupsdCheckAccess() - Check whether the given address is allowed to
29 * cupsdCheckAuth() - Check authorization masks.
30 * cupsdCheckGroup() - Check for a user's group membership.
31 * cupsdCopyLocation() - Make a copy of a location...
32 * cupsdDeleteAllLocations() - Free all memory used for location
34 * cupsdDeleteLocation() - Free all memory used by a location.
35 * cupsdDenyHost() - Add a host name that is not allowed to access
37 * cupsdDenyIP() - Add an IP address or network that is not
38 * allowed to access the location.
39 * cupsdFindBest() - Find the location entry that best matches the
41 * cupsdFindLocation() - Find the named location.
42 * cupsdIsAuthorized() - Check to see if the user is authorized...
43 * add_allow() - Add an allow mask to the location.
44 * add_deny() - Add a deny mask to the location.
45 * check_authref() - Check if an authorization services reference
46 * has the supplied right.
47 * compare_locations() - Compare two locations.
48 * cups_crypt() - Encrypt the password using the DES or MD5
49 * algorithms, as needed.
50 * get_gss_creds() - Obtain GSS credentials.
51 * get_md5_password() - Get an MD5 password.
52 * pam_func() - PAM conversation function.
53 * to64() - Base64-encode an integer value...
57 * Include necessary headers...
64 #endif /* HAVE_SHADOW_H */
67 #endif /* HAVE_CRYPT_H */
69 # ifdef HAVE_PAM_PAM_APPL_H
70 # include <pam/pam_appl.h>
72 # include <security/pam_appl.h>
73 # endif /* HAVE_PAM_PAM_APPL_H */
74 #endif /* HAVE_LIBPAM */
77 #endif /* HAVE_USERSEC_H */
78 #ifdef HAVE_MEMBERSHIP_H
79 # include <membership.h>
80 #endif /* HAVE_MEMBERSHIP_H */
81 #ifdef HAVE_AUTHORIZATION_H
82 # include <Security/AuthorizationTags.h>
83 # ifdef HAVE_SECBASEPRIV_H
84 # include <Security/SecBasePriv.h>
86 extern const char *cssmErrorString(int error
);
87 # endif /* HAVE_SECBASEPRIV_H */
88 #endif /* HAVE_AUTHORIZATION_H */
89 #ifdef HAVE_SYS_PARAM_H
90 # include <sys/param.h>
91 #endif /* HAVE_SYS_PARAM_H */
92 #ifdef HAVE_SYS_UCRED_H
93 # include <sys/ucred.h>
94 typedef struct xucred cupsd_ucred_t
;
95 # define CUPSD_UCRED_UID(c) (c).cr_uid
97 typedef struct ucred cupsd_ucred_t
;
98 # define CUPSD_UCRED_UID(c) (c).uid
99 #endif /* HAVE_SYS_UCRED_H */
106 static cupsd_authmask_t
*add_allow(cupsd_location_t
*loc
);
107 static cupsd_authmask_t
*add_deny(cupsd_location_t
*loc
);
108 #ifdef HAVE_AUTHORIZATION_H
109 static int check_authref(cupsd_client_t
*con
, const char *right
);
110 #endif /* HAVE_AUTHORIZATION_H */
111 static int compare_locations(cupsd_location_t
*a
,
112 cupsd_location_t
*b
);
113 #if !HAVE_LIBPAM && !defined(HAVE_USERSEC_H)
114 static char *cups_crypt(const char *pw
, const char *salt
);
115 #endif /* !HAVE_LIBPAM && !HAVE_USERSEC_H */
117 static gss_cred_id_t
get_gss_creds(const char *service_name
);
118 #endif /* HAVE_GSSAPI */
119 static char *get_md5_password(const char *username
,
120 const char *group
, char passwd
[33]);
122 static int pam_func(int, const struct pam_message
**,
123 struct pam_response
**, void *);
124 #elif !defined(HAVE_USERSEC_H)
125 static void to64(char *s
, unsigned long v
, int n
);
126 #endif /* HAVE_LIBPAM */
130 * Local structures...
134 typedef struct cupsd_authdata_s
/**** Authentication data ****/
136 char username
[33], /* Username string */
137 password
[33]; /* Password string */
139 #endif /* HAVE_LIBPAM */
146 #if defined(__hpux) && HAVE_LIBPAM
147 static cupsd_authdata_t
*auth_data
; /* Current client being authenticated */
148 #endif /* __hpux && HAVE_LIBPAM */
152 * 'cupsdAddLocation()' - Add a location for authorization.
155 cupsd_location_t
* /* O - Pointer to new location record */
156 cupsdAddLocation(const char *location
) /* I - Location path */
158 cupsd_location_t
*temp
; /* New location */
162 * Make sure the locations array is created...
166 Locations
= cupsArrayNew((cups_array_func_t
)compare_locations
, NULL
);
172 * Try to allocate memory for the new location.
175 if ((temp
= calloc(1, sizeof(cupsd_location_t
))) == NULL
)
179 * Initialize the record and copy the name over...
182 if ((temp
->location
= strdup(location
)) == NULL
)
188 temp
->length
= strlen(temp
->location
);
190 cupsArrayAdd(Locations
, temp
);
192 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddLocation: added location \'%s\'",
196 * Return the new record...
204 * 'cupsdAddName()' - Add a name to a location...
208 cupsdAddName(cupsd_location_t
*loc
, /* I - Location to add to */
209 char *name
) /* I - Name to add */
211 char **temp
; /* Pointer to names array */
214 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddName(loc=%p, name=\"%s\")",
217 if (loc
->num_names
== 0)
218 temp
= malloc(sizeof(char *));
220 temp
= realloc(loc
->names
, (loc
->num_names
+ 1) * sizeof(char *));
224 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to add name to location %s: %s",
225 loc
->location
? loc
->location
: "nil", strerror(errno
));
231 if ((temp
[loc
->num_names
] = strdup(name
)) == NULL
)
233 cupsdLogMessage(CUPSD_LOG_ERROR
,
234 "Unable to duplicate name for location %s: %s",
235 loc
->location
? loc
->location
: "nil", strerror(errno
));
244 * 'cupsdAllowHost()' - Add a host name that is allowed to access the location.
248 cupsdAllowHost(cupsd_location_t
*loc
, /* I - Location to add to */
249 char *name
) /* I - Name of host or domain to add */
251 cupsd_authmask_t
*temp
; /* New host/domain mask */
252 char ifname
[32], /* Interface name */
253 *ifptr
; /* Pointer to end of name */
256 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAllowHost(loc=%p(%s), name=\"%s\")",
257 loc
, loc
->location
? loc
->location
: "nil", name
);
259 if ((temp
= add_allow(loc
)) == NULL
)
262 if (!strcasecmp(name
, "@LOCAL"))
265 * Allow *interface*...
268 temp
->type
= AUTH_INTERFACE
;
269 temp
->mask
.name
.name
= strdup("*");
270 temp
->mask
.name
.length
= 1;
272 else if (!strncasecmp(name
, "@IF(", 4))
275 * Allow *interface*...
278 strlcpy(ifname
, name
+ 4, sizeof(ifname
));
280 ifptr
= ifname
+ strlen(ifname
);
282 if (ifptr
[-1] == ')')
288 temp
->type
= AUTH_INTERFACE
;
289 temp
->mask
.name
.name
= strdup(ifname
);
290 temp
->mask
.name
.length
= ifptr
- ifname
;
298 temp
->type
= AUTH_NAME
;
299 temp
->mask
.name
.name
= strdup(name
);
300 temp
->mask
.name
.length
= strlen(name
);
306 * 'cupsdAllowIP()' - Add an IP address or network that is allowed to access
311 cupsdAllowIP(cupsd_location_t
*loc
, /* I - Location to add to */
312 unsigned address
[4], /* I - IP address to add */
313 unsigned netmask
[4]) /* I - Netmask of address */
315 cupsd_authmask_t
*temp
; /* New host/domain mask */
318 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
319 "cupsdAllowIP(loc=%p(%s), address=%x:%x:%x:%x, netmask=%x:%x:%x:%x)",
320 loc
, loc
->location
? loc
->location
: "nil",
321 address
[0], address
[1], address
[2], address
[3],
322 netmask
[0], netmask
[1], netmask
[2], netmask
[3]);
324 if ((temp
= add_allow(loc
)) == NULL
)
327 temp
->type
= AUTH_IP
;
328 memcpy(temp
->mask
.ip
.address
, address
, sizeof(temp
->mask
.ip
.address
));
329 memcpy(temp
->mask
.ip
.netmask
, netmask
, sizeof(temp
->mask
.ip
.netmask
));
334 * 'cupsdAuthorize()' - Validate any authorization credentials.
338 cupsdAuthorize(cupsd_client_t
*con
) /* I - Client connection */
340 int type
; /* Authentication type */
341 const char *authorization
; /* Pointer into Authorization string */
342 char *ptr
, /* Pointer into string */
343 username
[256], /* Username string */
344 password
[33]; /* Password string */
345 const char *localuser
; /* Certificate username */
346 char nonce
[HTTP_MAX_VALUE
], /* Nonce value from client */
347 md5
[33], /* MD5 password */
348 basicmd5
[33]; /* MD5 of Basic password */
349 static const char * const states
[] = /* HTTP client states... */
369 * Locate the best matching location so we know what kind of
370 * authentication to expect...
373 con
->best
= cupsdFindBest(con
->uri
, con
->http
.state
);
374 con
->type
= AUTH_NONE
;
376 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
377 "cupsdAuthorize: con->uri=\"%s\", con->best=%p(%s)",
378 con
->uri
, con
->best
, con
->best
? con
->best
->location
: "");
380 if (con
->best
&& con
->best
->type
!= AUTH_NONE
)
382 if (con
->best
->type
== AUTH_DEFAULT
)
383 type
= DefaultAuthType
;
385 type
= con
->best
->type
;
388 type
= DefaultAuthType
;
391 * Decode the Authorization string...
394 authorization
= httpGetField(&con
->http
, HTTP_FIELD_AUTHORIZATION
);
396 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAuthorize: Authorization=\"%s\"",
402 #ifdef HAVE_AUTHORIZATION_H
405 AuthorizationFree(con
->authref
, kAuthorizationFlagDefaults
);
408 #endif /* HAVE_AUTHORIZATION_H */
413 * No authorization data provided, return early...
416 cupsdLogMessage(CUPSD_LOG_DEBUG
,
417 "cupsdAuthorize: No authentication data provided.");
420 #ifdef HAVE_AUTHORIZATION_H
421 else if (!strncmp(authorization
, "AuthRef", 6) &&
422 !strcasecmp(con
->http
.hostname
, "localhost"))
424 OSStatus status
; /* Status */
425 int authlen
; /* Auth string length */
426 AuthorizationItemSet
*authinfo
; /* Authorization item set */
429 * Get the Authorization Services data...
433 while (isspace(*authorization
& 255))
436 authlen
= sizeof(nonce
);
437 httpDecode64_2(nonce
, &authlen
, authorization
);
439 if (authlen
!= kAuthorizationExternalFormLength
)
441 cupsdLogMessage(CUPSD_LOG_ERROR
,
442 "External Authorization reference size is incorrect!");
446 if ((status
= AuthorizationCreateFromExternalForm(
447 (AuthorizationExternalForm
*)nonce
, &con
->authref
)) != 0)
449 cupsdLogMessage(CUPSD_LOG_ERROR
,
450 "AuthorizationCreateFromExternalForm returned %d (%s)",
451 (int)status
, cssmErrorString(status
));
455 if ((status
= AuthorizationCopyInfo(con
->authref
,
456 kAuthorizationEnvironmentUsername
,
459 cupsdLogMessage(CUPSD_LOG_ERROR
,
460 "AuthorizationCopyInfo returned %d (%s)",
461 (int)status
, cssmErrorString(status
));
465 if (authinfo
->count
== 1)
466 strlcpy(username
, authinfo
->items
[0].value
, sizeof(username
));
468 cupsdLogMessage(CUPSD_LOG_DEBUG
,
469 "cupsdAuthorize: Authorized as %s using AuthRef",
472 AuthorizationFreeItemSet(authinfo
);
474 con
->type
= AUTH_BASIC
;
476 #endif /* HAVE_AUTHORIZATION_H */
477 #if defined(SO_PEERCRED) && defined(AF_LOCAL)
478 else if (!strncmp(authorization
, "PeerCred ", 9) &&
479 con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
)
482 * Use peer credentials from domain socket connection...
485 struct passwd
*pwd
; /* Password entry for this user */
486 cupsd_ucred_t peercred
; /* Peer credentials */
487 socklen_t peersize
; /* Size of peer credentials */
490 if ((pwd
= getpwnam(authorization
+ 9)) == NULL
)
492 cupsdLogMessage(CUPSD_LOG_ERROR
, "User \"%s\" does not exist!",
497 peersize
= sizeof(peercred
);
499 if (getsockopt(con
->http
.fd
, SOL_SOCKET
, SO_PEERCRED
, &peercred
, &peersize
))
501 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get peer credentials - %s",
506 if (pwd
->pw_uid
!= CUPSD_UCRED_UID(peercred
))
508 cupsdLogMessage(CUPSD_LOG_ERROR
,
509 "Invalid peer credentials for \"%s\" - got %d, "
510 "expected %d!", authorization
+ 9,
511 CUPSD_UCRED_UID(peercred
), pwd
->pw_uid
);
512 # ifdef HAVE_SYS_UCRED_H
513 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdAuthorize: cr_version=%d",
514 peercred
.cr_version
);
515 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdAuthorize: cr_uid=%d",
517 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdAuthorize: cr_ngroups=%d",
518 peercred
.cr_ngroups
);
519 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdAuthorize: cr_groups[0]=%d",
520 peercred
.cr_groups
[0]);
521 # endif /* HAVE_SYS_UCRED_H */
525 strlcpy(username
, authorization
+ 9, sizeof(username
));
527 cupsdLogMessage(CUPSD_LOG_DEBUG
,
528 "cupsdAuthorize: Authorized as %s using PeerCred",
531 con
->type
= AUTH_BASIC
;
533 #endif /* SO_PEERCRED && AF_LOCAL */
534 else if (!strncmp(authorization
, "Local", 5) &&
535 !strcasecmp(con
->http
.hostname
, "localhost"))
538 * Get Local certificate authentication data...
542 while (isspace(*authorization
& 255))
545 if ((localuser
= cupsdFindCert(authorization
)) != NULL
)
547 strlcpy(username
, localuser
, sizeof(username
));
549 cupsdLogMessage(CUPSD_LOG_DEBUG
,
550 "cupsdAuthorize: Authorized as %s using Local",
555 cupsdLogMessage(CUPSD_LOG_ERROR
,
556 "cupsdAuthorize: Local authentication certificate not "
561 con
->type
= AUTH_BASIC
;
563 else if (!strncmp(authorization
, "Basic", 5))
566 * Get the Basic authentication data...
569 int userlen
; /* Username:password length */
573 while (isspace(*authorization
& 255))
576 userlen
= sizeof(username
);
577 httpDecode64_2(username
, &userlen
, authorization
);
580 * Pull the username and password out...
583 if ((ptr
= strchr(username
, ':')) == NULL
)
585 cupsdLogMessage(CUPSD_LOG_ERROR
,
586 "cupsdAuthorize: Missing Basic password!");
595 * Username must not be empty...
598 cupsdLogMessage(CUPSD_LOG_ERROR
,
599 "cupsdAuthorize: Empty Basic username!");
606 * Password must not be empty...
609 cupsdLogMessage(CUPSD_LOG_ERROR
,
610 "cupsdAuthorize: Empty Basic password!");
614 strlcpy(password
, ptr
, sizeof(password
));
617 * Validate the username and password...
627 * Only use PAM to do authentication. This supports MD5
628 * passwords, among other things...
631 pam_handle_t
*pamh
; /* PAM authentication handle */
632 int pamerr
; /* PAM error code */
633 struct pam_conv pamdata
;/* PAM conversation data */
634 cupsd_authdata_t data
; /* Authentication data */
637 strlcpy(data
.username
, username
, sizeof(data
.username
));
638 strlcpy(data
.password
, password
, sizeof(data
.password
));
640 # if defined(__sun) || defined(__hpux)
641 pamdata
.conv
= (int (*)(int, struct pam_message
**,
642 struct pam_response
**,
645 pamdata
.conv
= pam_func
;
646 # endif /* __sun || __hpux */
647 pamdata
.appdata_ptr
= &data
;
651 * Workaround for HP-UX bug in pam_unix; see pam_func() below for
658 pamerr
= pam_start("cups", username
, &pamdata
, &pamh
);
659 if (pamerr
!= PAM_SUCCESS
)
661 cupsdLogMessage(CUPSD_LOG_ERROR
,
662 "cupsdAuthorize: pam_start() returned %d (%s)!\n",
663 pamerr
, pam_strerror(pamh
, pamerr
));
668 # if defined(HAVE_PAM_SET_ITEM) && defined(PAM_RHOST)
669 pamerr
= pam_set_item(pamh
, PAM_RHOST
, con
->http
.hostname
);
670 if (pamerr
!= PAM_SUCCESS
)
671 cupsdLogMessage(CUPSD_LOG_WARN
,
672 "cupsdAuthorize: pam_set_item() returned %d "
673 "(%s)!\n", pamerr
, pam_strerror(pamh
, pamerr
));
674 # endif /* HAVE_PAM_SET_ITEM && PAM_RHOST */
676 pamerr
= pam_authenticate(pamh
, PAM_SILENT
);
677 if (pamerr
!= PAM_SUCCESS
)
679 cupsdLogMessage(CUPSD_LOG_ERROR
,
680 "cupsdAuthorize: pam_authenticate() returned %d "
682 pamerr
, pam_strerror(pamh
, pamerr
));
687 pamerr
= pam_acct_mgmt(pamh
, PAM_SILENT
);
688 if (pamerr
!= PAM_SUCCESS
)
690 cupsdLogMessage(CUPSD_LOG_ERROR
,
691 "cupsdAuthorize: pam_acct_mgmt() returned %d "
693 pamerr
, pam_strerror(pamh
, pamerr
));
698 pam_end(pamh
, PAM_SUCCESS
);
700 #elif defined(HAVE_USERSEC_H)
702 * Use AIX authentication interface...
705 char *authmsg
; /* Authentication message */
706 int reenter
; /* ??? */
709 cupsdLogMessage(CUPSD_LOG_DEBUG
,
710 "cupsdAuthorize: AIX authenticate of username \"%s\"",
714 if (authenticate(username
, password
, &reenter
, &authmsg
) != 0)
716 cupsdLogMessage(CUPSD_LOG_DEBUG
,
717 "cupsdAuthorize: Unable to authenticate username "
719 username
, strerror(errno
));
725 * Use normal UNIX password file-based authentication...
728 char *pass
; /* Encrypted password */
729 struct passwd
*pw
; /* User password data */
730 # ifdef HAVE_SHADOW_H
731 struct spwd
*spw
; /* Shadow password data */
732 # endif /* HAVE_SHADOW_H */
735 pw
= getpwnam(username
); /* Get the current password */
736 endpwent(); /* Close the password file */
744 cupsdLogMessage(CUPSD_LOG_ERROR
,
745 "cupsdAuthorize: Unknown username \"%s\"!",
750 # ifdef HAVE_SHADOW_H
751 spw
= getspnam(username
);
754 if (!spw
&& !strcmp(pw
->pw_passwd
, "x"))
757 * Don't allow blank passwords!
760 cupsdLogMessage(CUPSD_LOG_ERROR
,
761 "cupsdAuthorize: Username \"%s\" has no shadow "
762 "password!", username
);
766 if (spw
&& !spw
->sp_pwdp
[0] && !pw
->pw_passwd
[0])
768 if (!pw
->pw_passwd
[0])
769 # endif /* HAVE_SHADOW_H */
772 * Don't allow blank passwords!
775 cupsdLogMessage(CUPSD_LOG_ERROR
,
776 "cupsdAuthorize: Username \"%s\" has no password!",
782 * OK, the password isn't blank, so compare with what came from the
786 pass
= cups_crypt(password
, pw
->pw_passwd
);
788 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
789 "cupsdAuthorize: pw_passwd=\"%s\", crypt=\"%s\"",
790 pw
->pw_passwd
, pass
);
792 if (!pass
|| strcmp(pw
->pw_passwd
, pass
))
794 # ifdef HAVE_SHADOW_H
797 pass
= cups_crypt(password
, spw
->sp_pwdp
);
799 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
800 "cupsdAuthorize: sp_pwdp=\"%s\", crypt=\"%s\"",
803 if (pass
== NULL
|| strcmp(spw
->sp_pwdp
, pass
))
805 cupsdLogMessage(CUPSD_LOG_ERROR
,
806 "cupsdAuthorize: Authentication failed for "
813 # endif /* HAVE_SHADOW_H */
815 cupsdLogMessage(CUPSD_LOG_ERROR
,
816 "cupsdAuthorize: Authentication failed for "
822 #endif /* HAVE_LIBPAM */
825 cupsdLogMessage(CUPSD_LOG_DEBUG
,
826 "cupsdAuthorize: Authorized as %s using Basic",
830 case AUTH_BASICDIGEST
:
832 * Do Basic authentication with the Digest password file...
835 if (!get_md5_password(username
, NULL
, md5
))
837 cupsdLogMessage(CUPSD_LOG_ERROR
,
838 "cupsdAuthorize: Unknown MD5 username \"%s\"!",
843 httpMD5(username
, "CUPS", password
, basicmd5
);
845 if (strcmp(md5
, basicmd5
))
847 cupsdLogMessage(CUPSD_LOG_ERROR
,
848 "cupsdAuthorize: Authentication failed for \"%s\"!",
853 cupsdLogMessage(CUPSD_LOG_DEBUG
,
854 "cupsdAuthorize: Authorized as %s using BasicDigest",
861 else if (!strncmp(authorization
, "Digest", 6))
864 * Get the username, password, and nonce from the Digest attributes...
867 if (!httpGetSubField2(&(con
->http
), HTTP_FIELD_AUTHORIZATION
, "username",
868 username
, sizeof(username
)) || !username
[0])
871 * Username must not be empty...
874 cupsdLogMessage(CUPSD_LOG_ERROR
,
875 "cupsdAuthorize: Empty or missing Digest username!");
879 if (!httpGetSubField2(&(con
->http
), HTTP_FIELD_AUTHORIZATION
, "response",
880 password
, sizeof(password
)) || !password
[0])
883 * Password must not be empty...
886 cupsdLogMessage(CUPSD_LOG_ERROR
,
887 "cupsdAuthorize: Empty or missing Digest password!");
891 if (!httpGetSubField(&(con
->http
), HTTP_FIELD_AUTHORIZATION
, "nonce",
894 cupsdLogMessage(CUPSD_LOG_ERROR
,
895 "cupsdAuthorize: No nonce value for Digest "
900 if (strcmp(con
->http
.hostname
, nonce
))
902 cupsdLogMessage(CUPSD_LOG_ERROR
,
903 "cupsdAuthorize: Bad nonce value, expected \"%s\", "
904 "got \"%s\"!", con
->http
.hostname
, nonce
);
909 * Validate the username and password...
912 if (!get_md5_password(username
, NULL
, md5
))
914 cupsdLogMessage(CUPSD_LOG_ERROR
,
915 "cupsdAuthorize: Unknown MD5 username \"%s\"!",
920 httpMD5Final(nonce
, states
[con
->http
.state
], con
->uri
, md5
);
922 if (strcmp(md5
, password
))
924 cupsdLogMessage(CUPSD_LOG_ERROR
,
925 "cupsdAuthorize: Authentication failed for \"%s\"!",
930 cupsdLogMessage(CUPSD_LOG_DEBUG
,
931 "cupsdAuthorize: Authorized as %s using Digest",
934 con
->type
= AUTH_DIGEST
;
937 else if (!strncmp(authorization
, "Negotiate", 9))
939 int len
; /* Length of authorization string */
940 gss_cred_id_t server_creds
; /* Server credentials */
941 gss_ctx_id_t context
; /* Authorization context */
942 OM_uint32 major_status
, /* Major status code */
943 minor_status
; /* Minor status code */
944 gss_buffer_desc input_token
= GSS_C_EMPTY_BUFFER
,
945 /* Input token from string */
946 output_token
= GSS_C_EMPTY_BUFFER
;
947 /* Output token for username */
948 gss_name_t client_name
; /* Client name */
949 unsigned int ret_flags
; /* Credential flags */
954 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
958 if (gss_init_sec_context
== NULL
)
960 cupsdLogMessage(CUPSD_LOG_WARN
,
961 "GSSAPI/Kerberos authentication failed because the "
962 "Kerberos framework is not present.");
965 # endif /* __APPLE__ */
967 con
->gss_output_token
.length
= 0;
970 * Find the start of the Kerberos input token...
974 while (isspace(*authorization
& 255))
979 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
980 "cupsdAuthorize: No authentication data specified.");
985 * Get the server credentials...
988 if ((server_creds
= get_gss_creds(GSSServiceName
)) == NULL
)
992 * Decode the authorization string to get the input token...
995 len
= strlen(authorization
);
996 input_token
.value
= malloc(len
);
997 input_token
.value
= httpDecode64_2(input_token
.value
, &len
,
999 input_token
.length
= len
;
1002 * Accept the input token to get the authorization info...
1005 context
= GSS_C_NO_CONTEXT
;
1006 client_name
= GSS_C_NO_NAME
;
1007 major_status
= gss_accept_sec_context(&minor_status
,
1011 GSS_C_NO_CHANNEL_BINDINGS
,
1014 &con
->gss_output_token
,
1017 &con
->gss_delegated_cred
);
1019 if (GSS_ERROR(major_status
))
1021 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
1022 "cupsdAuthorize: Error accepting GSSAPI security "
1025 if (context
!= GSS_C_NO_CONTEXT
)
1026 gss_delete_sec_context(&minor_status
, &context
, GSS_C_NO_BUFFER
);
1028 gss_release_cred(&minor_status
, &server_creds
);
1033 * Release our credentials...
1036 gss_release_cred(&minor_status
, &server_creds
);
1039 * Get the username associated with the client's credentials...
1042 if (!con
->gss_delegated_cred
)
1043 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1044 "cupsdAuthorize: No delegated credentials!");
1046 if (major_status
== GSS_S_CONTINUE_NEEDED
)
1047 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
1048 "cupsdAuthorize: Credentials not complete");
1049 else if (major_status
== GSS_S_COMPLETE
)
1051 major_status
= gss_display_name(&minor_status
, client_name
,
1052 &output_token
, NULL
);
1054 if (GSS_ERROR(major_status
))
1056 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
1057 "cupsdAuthorize: Error getting username");
1058 gss_release_name(&minor_status
, &client_name
);
1059 gss_delete_sec_context(&minor_status
, &context
, GSS_C_NO_BUFFER
);
1063 gss_release_name(&minor_status
, &client_name
);
1064 strlcpy(username
, output_token
.value
, sizeof(username
));
1066 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1067 "cupsdAuthorize: Authorized as %s using Negotiate",
1070 gss_release_buffer(&minor_status
, &output_token
);
1071 gss_delete_sec_context(&minor_status
, &context
, GSS_C_NO_BUFFER
);
1073 con
->gss_have_creds
= 1;
1075 con
->type
= AUTH_NEGOTIATE
;
1078 gss_release_name(&minor_status
, &client_name
);
1080 #endif /* HAVE_GSSAPI */
1083 char scheme
[256]; /* Auth scheme... */
1086 if (sscanf(authorization
, "%255s", scheme
) != 1)
1087 strcpy(scheme
, "UNKNOWN");
1089 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad authentication data \"%s ...\"",
1095 * If we get here, then we were able to validate the username and
1096 * password - copy the validated username and password to the client
1097 * data and return...
1100 strlcpy(con
->username
, username
, sizeof(con
->username
));
1101 strlcpy(con
->password
, password
, sizeof(con
->password
));
1106 * 'cupsdCheckAccess()' - Check whether the given address is allowed to
1107 * access a location.
1110 int /* O - 1 if allowed, 0 otherwise */
1112 unsigned ip
[4], /* I - Client address */
1113 char *name
, /* I - Client hostname */
1114 int namelen
, /* I - Length of hostname */
1115 cupsd_location_t
*loc
) /* I - Location to check */
1117 int allow
; /* 1 if allowed, 0 otherwise */
1120 if (!strcasecmp(name
, "localhost"))
1123 * Access from localhost (127.0.0.1 or ::1) is always allowed...
1131 * Do authorization checks on the domain/address...
1134 switch (loc
->order_type
)
1137 allow
= 0; /* anti-compiler-warning-code */
1140 case AUTH_ALLOW
: /* Order Deny,Allow */
1143 if (cupsdCheckAuth(ip
, name
, namelen
, loc
->num_deny
, loc
->deny
))
1146 if (cupsdCheckAuth(ip
, name
, namelen
, loc
->num_allow
, loc
->allow
))
1150 case AUTH_DENY
: /* Order Allow,Deny */
1153 if (cupsdCheckAuth(ip
, name
, namelen
, loc
->num_allow
, loc
->allow
))
1156 if (cupsdCheckAuth(ip
, name
, namelen
, loc
->num_deny
, loc
->deny
))
1167 * 'cupsdCheckAuth()' - Check authorization masks.
1170 int /* O - 1 if mask matches, 0 otherwise */
1172 unsigned ip
[4], /* I - Client address */
1173 char *name
, /* I - Client hostname */
1174 int name_len
, /* I - Length of hostname */
1175 int num_masks
, /* I - Number of masks */
1176 cupsd_authmask_t
*masks
) /* I - Masks */
1178 int i
; /* Looping var */
1179 cupsd_netif_t
*iface
; /* Network interface */
1180 unsigned netip4
; /* IPv4 network address */
1182 unsigned netip6
[4]; /* IPv6 network address */
1183 #endif /* AF_INET6 */
1185 while (num_masks
> 0)
1187 switch (masks
->type
)
1189 case AUTH_INTERFACE
:
1191 * Check for a match with a network interface...
1194 netip4
= htonl(ip
[3]);
1197 netip6
[0] = htonl(ip
[0]);
1198 netip6
[1] = htonl(ip
[1]);
1199 netip6
[2] = htonl(ip
[2]);
1200 netip6
[3] = htonl(ip
[3]);
1201 #endif /* AF_INET6 */
1203 if (!strcmp(masks
->mask
.name
.name
, "*"))
1206 * Check against all local interfaces...
1211 for (iface
= (cupsd_netif_t
*)cupsArrayFirst(NetIFList
);
1213 iface
= (cupsd_netif_t
*)cupsArrayNext(NetIFList
))
1216 * Only check local interfaces...
1219 if (!iface
->is_local
)
1222 if (iface
->address
.addr
.sa_family
== AF_INET
)
1225 * Check IPv4 address...
1228 if ((netip4
& iface
->mask
.ipv4
.sin_addr
.s_addr
) ==
1229 (iface
->address
.ipv4
.sin_addr
.s_addr
&
1230 iface
->mask
.ipv4
.sin_addr
.s_addr
))
1237 * Check IPv6 address...
1240 for (i
= 0; i
< 4; i
++)
1241 if ((netip6
[i
] & iface
->mask
.ipv6
.sin6_addr
.s6_addr32
[i
]) !=
1242 (iface
->address
.ipv6
.sin6_addr
.s6_addr32
[i
] &
1243 iface
->mask
.ipv6
.sin6_addr
.s6_addr32
[i
]))
1249 #endif /* AF_INET6 */
1255 * Check the named interface...
1258 for (iface
= (cupsd_netif_t
*)cupsArrayFirst(NetIFList
);
1260 iface
= (cupsd_netif_t
*)cupsArrayNext(NetIFList
))
1262 if (strcmp(masks
->mask
.name
.name
, iface
->name
))
1265 if (iface
->address
.addr
.sa_family
== AF_INET
)
1268 * Check IPv4 address...
1271 if ((netip4
& iface
->mask
.ipv4
.sin_addr
.s_addr
) ==
1272 (iface
->address
.ipv4
.sin_addr
.s_addr
&
1273 iface
->mask
.ipv4
.sin_addr
.s_addr
))
1280 * Check IPv6 address...
1283 for (i
= 0; i
< 4; i
++)
1284 if ((netip6
[i
] & iface
->mask
.ipv6
.sin6_addr
.s6_addr32
[i
]) !=
1285 (iface
->address
.ipv6
.sin6_addr
.s6_addr32
[i
] &
1286 iface
->mask
.ipv6
.sin6_addr
.s6_addr32
[i
]))
1292 #endif /* AF_INET6 */
1299 * Check for exact name match...
1302 if (!strcasecmp(name
, masks
->mask
.name
.name
))
1306 * Check for domain match...
1309 if (name_len
>= masks
->mask
.name
.length
&&
1310 masks
->mask
.name
.name
[0] == '.' &&
1311 !strcasecmp(name
+ name_len
- masks
->mask
.name
.length
,
1312 masks
->mask
.name
.name
))
1318 * Check for IP/network address match...
1321 for (i
= 0; i
< 4; i
++)
1322 if ((ip
[i
] & masks
->mask
.ip
.netmask
[i
]) !=
1323 masks
->mask
.ip
.address
[i
])
1340 * 'cupsdCheckGroup()' - Check for a user's group membership.
1343 int /* O - 1 if user is a member, 0 otherwise */
1345 const char *username
, /* I - User name */
1346 struct passwd
*user
, /* I - System user info */
1347 const char *groupname
) /* I - Group name */
1349 int i
; /* Looping var */
1350 struct group
*group
; /* System group info */
1351 char junk
[33]; /* MD5 password (not used) */
1352 #ifdef HAVE_MBR_UID_TO_UUID
1353 uuid_t useruuid
, /* UUID for username */
1354 groupuuid
; /* UUID for groupname */
1355 int is_member
; /* True if user is a member of group */
1356 #endif /* HAVE_MBR_UID_TO_UUID */
1359 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1360 "cupsdCheckGroup(username=\"%s\", user=%p, groupname=\"%s\")",
1361 username
, user
, groupname
);
1367 if (!username
|| !groupname
)
1371 * Check to see if the user is a member of the named group...
1374 group
= getgrnam(groupname
);
1380 * Group exists, check it...
1383 for (i
= 0; group
->gr_mem
[i
]; i
++)
1384 if (!strcasecmp(username
, group
->gr_mem
[i
]))
1389 * Group doesn't exist or user not in group list, check the group ID
1390 * against the user's group ID...
1393 if (user
&& group
&& group
->gr_gid
== user
->pw_gid
)
1396 #ifdef HAVE_MBR_UID_TO_UUID
1398 * Check group membership through MacOS X membership API...
1402 if (!mbr_uid_to_uuid(user
->pw_uid
, useruuid
))
1403 if (!mbr_gid_to_uuid(group
->gr_gid
, groupuuid
))
1404 if (!mbr_check_membership(useruuid
, groupuuid
, &is_member
))
1407 #endif /* HAVE_MBR_UID_TO_UUID */
1410 * Username not found, group not found, or user is not part of the
1411 * system group... Check for a user and group in the MD5 password
1415 if (get_md5_password(username
, groupname
, junk
) != NULL
)
1419 * If we get this far, then the user isn't part of the named group...
1427 * 'cupsdCopyLocation()' - Make a copy of a location...
1430 cupsd_location_t
* /* O - New location */
1432 cupsd_location_t
**loc
) /* IO - Original location */
1434 int i
; /* Looping var */
1435 cupsd_location_t
*temp
; /* New location */
1436 char location
[HTTP_MAX_URI
];
1437 /* Location of resource */
1441 * Use a local copy of location because cupsdAddLocation may cause
1442 * this memory to be moved...
1445 strlcpy(location
, (*loc
)->location
, sizeof(location
));
1447 if ((temp
= cupsdAddLocation(location
)) == NULL
)
1451 * Copy the information from the original location to the new one.
1454 temp
->limit
= (*loc
)->limit
;
1455 temp
->order_type
= (*loc
)->order_type
;
1456 temp
->type
= (*loc
)->type
;
1457 temp
->level
= (*loc
)->level
;
1458 temp
->satisfy
= (*loc
)->satisfy
;
1459 temp
->encryption
= (*loc
)->encryption
;
1461 if ((temp
->num_names
= (*loc
)->num_names
) > 0)
1464 * Copy the names array...
1467 if ((temp
->names
= calloc(temp
->num_names
, sizeof(char *))) == NULL
)
1469 cupsdLogMessage(CUPSD_LOG_ERROR
,
1470 "cupsdCopyLocation: Unable to allocate memory for %d names: %s",
1471 temp
->num_names
, strerror(errno
));
1473 cupsdDeleteLocation(temp
);
1477 for (i
= 0; i
< temp
->num_names
; i
++)
1478 if ((temp
->names
[i
] = strdup((*loc
)->names
[i
])) == NULL
)
1480 cupsdLogMessage(CUPSD_LOG_ERROR
,
1481 "cupsdCopyLocation: Unable to copy name \"%s\": %s",
1482 (*loc
)->names
[i
], strerror(errno
));
1484 cupsdDeleteLocation(temp
);
1489 if ((temp
->num_allow
= (*loc
)->num_allow
) > 0)
1492 * Copy allow rules...
1495 if ((temp
->allow
= calloc(temp
->num_allow
, sizeof(cupsd_authmask_t
))) == NULL
)
1497 cupsdLogMessage(CUPSD_LOG_ERROR
,
1498 "cupsdCopyLocation: Unable to allocate memory for %d allow rules: %s",
1499 temp
->num_allow
, strerror(errno
));
1500 cupsdDeleteLocation(temp
);
1504 for (i
= 0; i
< temp
->num_allow
; i
++)
1505 switch (temp
->allow
[i
].type
= (*loc
)->allow
[i
].type
)
1508 temp
->allow
[i
].mask
.name
.length
= (*loc
)->allow
[i
].mask
.name
.length
;
1509 temp
->allow
[i
].mask
.name
.name
= strdup((*loc
)->allow
[i
].mask
.name
.name
);
1511 if (temp
->allow
[i
].mask
.name
.name
== NULL
)
1513 cupsdLogMessage(CUPSD_LOG_ERROR
,
1514 "cupsdCopyLocation: Unable to copy allow name \"%s\": %s",
1515 (*loc
)->allow
[i
].mask
.name
.name
, strerror(errno
));
1516 cupsdDeleteLocation(temp
);
1521 memcpy(&(temp
->allow
[i
].mask
.ip
), &((*loc
)->allow
[i
].mask
.ip
),
1522 sizeof(cupsd_ipmask_t
));
1527 if ((temp
->num_deny
= (*loc
)->num_deny
) > 0)
1530 * Copy deny rules...
1533 if ((temp
->deny
= calloc(temp
->num_deny
, sizeof(cupsd_authmask_t
))) == NULL
)
1535 cupsdLogMessage(CUPSD_LOG_ERROR
,
1536 "cupsdCopyLocation: Unable to allocate memory for %d deny rules: %s",
1537 temp
->num_deny
, strerror(errno
));
1538 cupsdDeleteLocation(temp
);
1542 for (i
= 0; i
< temp
->num_deny
; i
++)
1543 switch (temp
->deny
[i
].type
= (*loc
)->deny
[i
].type
)
1546 temp
->deny
[i
].mask
.name
.length
= (*loc
)->deny
[i
].mask
.name
.length
;
1547 temp
->deny
[i
].mask
.name
.name
= strdup((*loc
)->deny
[i
].mask
.name
.name
);
1549 if (temp
->deny
[i
].mask
.name
.name
== NULL
)
1551 cupsdLogMessage(CUPSD_LOG_ERROR
,
1552 "cupsdCopyLocation: Unable to copy deny name \"%s\": %s",
1553 (*loc
)->deny
[i
].mask
.name
.name
, strerror(errno
));
1554 cupsdDeleteLocation(temp
);
1559 memcpy(&(temp
->deny
[i
].mask
.ip
), &((*loc
)->deny
[i
].mask
.ip
),
1560 sizeof(cupsd_ipmask_t
));
1570 * 'cupsdDeleteAllLocations()' - Free all memory used for location authorization.
1574 cupsdDeleteAllLocations(void)
1576 cupsd_location_t
*loc
; /* Current location */
1580 * Free all of the allow/deny records first...
1583 for (loc
= (cupsd_location_t
*)cupsArrayFirst(Locations
);
1585 loc
= (cupsd_location_t
*)cupsArrayNext(Locations
))
1586 cupsdDeleteLocation(loc
);
1589 * Then free the location array...
1592 cupsArrayDelete(Locations
);
1598 * 'cupsdDeleteLocation()' - Free all memory used by a location.
1602 cupsdDeleteLocation(
1603 cupsd_location_t
*loc
) /* I - Location to delete */
1605 int i
; /* Looping var */
1606 cupsd_authmask_t
*mask
; /* Current mask */
1609 cupsArrayRemove(Locations
, loc
);
1611 for (i
= loc
->num_names
- 1; i
>= 0; i
--)
1612 free(loc
->names
[i
]);
1614 if (loc
->num_names
> 0)
1617 for (i
= loc
->num_allow
, mask
= loc
->allow
; i
> 0; i
--, mask
++)
1618 if (mask
->type
== AUTH_NAME
|| mask
->type
== AUTH_INTERFACE
)
1619 free(mask
->mask
.name
.name
);
1621 if (loc
->num_allow
> 0)
1624 for (i
= loc
->num_deny
, mask
= loc
->deny
; i
> 0; i
--, mask
++)
1625 if (mask
->type
== AUTH_NAME
|| mask
->type
== AUTH_INTERFACE
)
1626 free(mask
->mask
.name
.name
);
1628 if (loc
->num_deny
> 0)
1631 free(loc
->location
);
1637 * 'cupsdDenyHost()' - Add a host name that is not allowed to access the
1642 cupsdDenyHost(cupsd_location_t
*loc
, /* I - Location to add to */
1643 char *name
) /* I - Name of host or domain to add */
1645 cupsd_authmask_t
*temp
; /* New host/domain mask */
1646 char ifname
[32], /* Interface name */
1647 *ifptr
; /* Pointer to end of name */
1650 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDenyHost(loc=%p(%s), name=\"%s\")",
1651 loc
, loc
->location
? loc
->location
: "nil", name
);
1653 if ((temp
= add_deny(loc
)) == NULL
)
1656 if (!strcasecmp(name
, "@LOCAL"))
1659 * Deny *interface*...
1662 temp
->type
= AUTH_INTERFACE
;
1663 temp
->mask
.name
.name
= strdup("*");
1664 temp
->mask
.name
.length
= 1;
1666 else if (!strncasecmp(name
, "@IF(", 4))
1669 * Deny *interface*...
1672 strlcpy(ifname
, name
+ 4, sizeof(ifname
));
1674 ifptr
= ifname
+ strlen(ifname
);
1676 if (ifptr
[-1] == ')')
1682 temp
->type
= AUTH_INTERFACE
;
1683 temp
->mask
.name
.name
= strdup(ifname
);
1684 temp
->mask
.name
.length
= ifptr
- ifname
;
1692 temp
->type
= AUTH_NAME
;
1693 temp
->mask
.name
.name
= strdup(name
);
1694 temp
->mask
.name
.length
= strlen(name
);
1700 * 'cupsdDenyIP()' - Add an IP address or network that is not allowed to
1701 * access the location.
1705 cupsdDenyIP(cupsd_location_t
*loc
, /* I - Location to add to */
1706 unsigned address
[4],/* I - IP address to add */
1707 unsigned netmask
[4])/* I - Netmask of address */
1709 cupsd_authmask_t
*temp
; /* New host/domain mask */
1712 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1713 "cupsdDenyIP(loc=%p(%s), address=%x:%x:%x:%x, netmask=%x:%x:%x:%x)",
1714 loc
, loc
->location
? loc
->location
: "nil",
1715 address
[0], address
[1], address
[2], address
[3],
1716 netmask
[0], netmask
[1], netmask
[2], netmask
[3]);
1718 if ((temp
= add_deny(loc
)) == NULL
)
1721 temp
->type
= AUTH_IP
;
1722 memcpy(temp
->mask
.ip
.address
, address
, sizeof(temp
->mask
.ip
.address
));
1723 memcpy(temp
->mask
.ip
.netmask
, netmask
, sizeof(temp
->mask
.ip
.netmask
));
1728 * 'cupsdFindBest()' - Find the location entry that best matches the resource.
1731 cupsd_location_t
* /* O - Location that matches */
1732 cupsdFindBest(const char *path
, /* I - Resource path */
1733 http_state_t state
) /* I - HTTP state/request */
1735 char uri
[HTTP_MAX_URI
],
1736 /* URI in request... */
1737 *uriptr
; /* Pointer into URI */
1738 cupsd_location_t
*loc
, /* Current location */
1739 *best
; /* Best match for location so far */
1740 int bestlen
; /* Length of best match */
1741 int limit
; /* Limit field */
1742 static const int limits
[] = /* Map http_status_t to AUTH_LIMIT_xyz */
1762 * First copy the connection URI to a local string so we have drop
1763 * any .ppd extension from the pathname in /printers or /classes
1767 strlcpy(uri
, path
, sizeof(uri
));
1769 if (!strncmp(uri
, "/printers/", 10) ||
1770 !strncmp(uri
, "/classes/", 9))
1773 * Check if the URI has .ppd on the end...
1776 uriptr
= uri
+ strlen(uri
) - 4; /* len > 4 if we get here... */
1778 if (!strcmp(uriptr
, ".ppd"))
1782 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindBest: uri = \"%s\"...", uri
);
1785 * Loop through the list of locations to find a match...
1788 limit
= limits
[state
];
1792 for (loc
= (cupsd_location_t
*)cupsArrayFirst(Locations
);
1794 loc
= (cupsd_location_t
*)cupsArrayNext(Locations
))
1796 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindBest: Location %s Limit %x",
1797 loc
->location
? loc
->location
: "nil", loc
->limit
);
1799 if (!strncmp(uri
, "/printers/", 10) || !strncmp(uri
, "/classes/", 9))
1802 * Use case-insensitive comparison for queue names...
1805 if (loc
->length
> bestlen
&& loc
->location
&&
1806 !strncasecmp(uri
, loc
->location
, loc
->length
) &&
1807 loc
->location
[0] == '/' &&
1808 (limit
& loc
->limit
) != 0)
1811 bestlen
= loc
->length
;
1817 * Use case-sensitive comparison for other URIs...
1820 if (loc
->length
> bestlen
&& loc
->location
&&
1821 !strncmp(uri
, loc
->location
, loc
->length
) &&
1822 loc
->location
[0] == '/' &&
1823 (limit
& loc
->limit
) != 0)
1826 bestlen
= loc
->length
;
1832 * Return the match, if any...
1835 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindBest: best = %s",
1836 best
? best
->location
: "NONE");
1843 * 'cupsdFindLocation()' - Find the named location.
1846 cupsd_location_t
* /* O - Location that matches */
1847 cupsdFindLocation(const char *location
) /* I - Connection */
1849 cupsd_location_t key
; /* Search key */
1852 key
.location
= (char *)location
;
1854 return ((cupsd_location_t
*)cupsArrayFind(Locations
, &key
));
1859 * 'cupsdIsAuthorized()' - Check to see if the user is authorized...
1862 http_status_t
/* O - HTTP_OK if authorized or error code */
1863 cupsdIsAuthorized(cupsd_client_t
*con
, /* I - Connection */
1864 const char *owner
)/* I - Owner of object */
1866 int i
, j
, /* Looping vars */
1867 auth
, /* Authorization status */
1868 type
; /* Type of authentication */
1869 unsigned address
[4]; /* Authorization address */
1870 cupsd_location_t
*best
; /* Best match for location so far */
1871 int hostlen
; /* Length of hostname */
1872 char username
[256], /* Username to authorize */
1873 ownername
[256], /* Owner name to authorize */
1874 *ptr
; /* Pointer into username */
1875 struct passwd
*pw
; /* User password data */
1876 static const char * const levels
[] = /* Auth levels */
1882 static const char * const types
[] = /* Auth types */
1892 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1893 "cupsdIsAuthorized: con->uri=\"%s\", con->best=%p(%s)",
1894 con
->uri
, con
->best
, con
->best
? con
->best
->location
?
1895 con
->best
->location
: "(null)" : "");
1897 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1898 "cupsdIsAuthorized: owner=\"%s\"", owner
);
1901 * If there is no "best" authentication rule for this request, then
1902 * access is allowed from the local system and denied from other
1908 if (!strcmp(con
->http
.hostname
, "localhost") ||
1909 !strcmp(con
->http
.hostname
, ServerName
))
1912 return (HTTP_FORBIDDEN
);
1917 if ((type
= best
->type
) == AUTH_DEFAULT
)
1918 type
= DefaultAuthType
;
1920 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1921 "cupsdIsAuthorized: level=AUTH_%s, type=%s, "
1922 "satisfy=AUTH_SATISFY_%s, num_names=%d",
1923 levels
[best
->level
], types
[type
],
1924 best
->satisfy
? "ANY" : "ALL", best
->num_names
);
1926 if (best
->limit
== AUTH_LIMIT_IPP
)
1927 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdIsAuthorized: op=%x(%s)",
1928 best
->op
, ippOpString(best
->op
));
1931 * Check host/ip-based accesses...
1935 if (con
->http
.hostaddr
->addr
.sa_family
== AF_INET6
)
1938 * Copy IPv6 address...
1941 address
[0] = ntohl(con
->http
.hostaddr
->ipv6
.sin6_addr
.s6_addr32
[0]);
1942 address
[1] = ntohl(con
->http
.hostaddr
->ipv6
.sin6_addr
.s6_addr32
[1]);
1943 address
[2] = ntohl(con
->http
.hostaddr
->ipv6
.sin6_addr
.s6_addr32
[2]);
1944 address
[3] = ntohl(con
->http
.hostaddr
->ipv6
.sin6_addr
.s6_addr32
[3]);
1947 #endif /* AF_INET6 */
1948 if (con
->http
.hostaddr
->addr
.sa_family
== AF_INET
)
1951 * Copy IPv4 address...
1957 address
[3] = ntohl(con
->http
.hostaddr
->ipv4
.sin_addr
.s_addr
);
1960 memset(address
, 0, sizeof(address
));
1962 hostlen
= strlen(con
->http
.hostname
);
1964 auth
= cupsdCheckAccess(address
, con
->http
.hostname
, hostlen
, best
)
1965 ? AUTH_ALLOW
: AUTH_DENY
;
1967 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdIsAuthorized: auth=AUTH_%s...",
1968 auth
? "DENY" : "ALLOW");
1970 if (auth
== AUTH_DENY
&& best
->satisfy
== AUTH_SATISFY_ALL
)
1971 return (HTTP_FORBIDDEN
);
1975 * See if encryption is required...
1978 if ((best
->encryption
>= HTTP_ENCRYPT_REQUIRED
&& !con
->http
.tls
&&
1979 strcasecmp(con
->http
.hostname
, "localhost") &&
1980 best
->satisfy
== AUTH_SATISFY_ALL
) &&
1981 !(type
== AUTH_NEGOTIATE
||
1982 (type
== AUTH_NONE
&& DefaultAuthType
== AUTH_NEGOTIATE
)))
1984 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1985 "cupsdIsAuthorized: Need upgrade to TLS...");
1986 return (HTTP_UPGRADE_REQUIRED
);
1988 #endif /* HAVE_SSL */
1991 * Now see what access level is required...
1994 if (best
->level
== AUTH_ANON
|| /* Anonymous access - allow it */
1995 (type
== AUTH_NONE
&& best
->num_names
== 0))
1998 if (!con
->username
[0] && type
== AUTH_NONE
&&
1999 best
->limit
== AUTH_LIMIT_IPP
)
2002 * Check for unauthenticated username...
2005 ipp_attribute_t
*attr
; /* requesting-user-name attribute */
2008 attr
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_NAME
);
2011 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2012 "cupsdIsAuthorized: requesting-user-name=\"%s\"",
2013 attr
->values
[0].string
.text
);
2014 strlcpy(username
, attr
->values
[0].string
.text
, sizeof(username
));
2016 else if (best
->satisfy
== AUTH_SATISFY_ALL
|| auth
== AUTH_DENY
)
2017 return (HTTP_UNAUTHORIZED
); /* Non-anonymous needs user/pass */
2019 return (HTTP_OK
); /* unless overridden with Satisfy */
2023 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdIsAuthorized: username=\"%s\"",
2026 #ifdef HAVE_AUTHORIZATION_H
2027 if (!con
->username
[0] && !con
->authref
)
2029 if (!con
->username
[0])
2030 #endif /* HAVE_AUTHORIZATION_H */
2032 if (best
->satisfy
== AUTH_SATISFY_ALL
|| auth
== AUTH_DENY
)
2033 return (HTTP_UNAUTHORIZED
); /* Non-anonymous needs user/pass */
2035 return (HTTP_OK
); /* unless overridden with Satisfy */
2038 if (con
->type
!= type
&& type
!= AUTH_NONE
&&
2039 (con
->type
!= AUTH_BASIC
|| type
!= AUTH_BASICDIGEST
))
2041 cupsdLogMessage(CUPSD_LOG_ERROR
, "Authorized using %s, expected %s!",
2042 types
[con
->type
], types
[type
]);
2044 return (HTTP_UNAUTHORIZED
);
2047 strlcpy(username
, con
->username
, sizeof(username
));
2051 * OK, got a username. See if we need normal user access, or group
2052 * access... (root always matches)
2055 if (!strcmp(username
, "root"))
2059 * Strip any @domain or @KDC from the username and owner...
2062 if ((ptr
= strchr(username
, '@')) != NULL
)
2067 strlcpy(ownername
, owner
, sizeof(ownername
));
2069 if ((ptr
= strchr(ownername
, '@')) != NULL
)
2073 ownername
[0] = '\0';
2076 * Get the user info...
2081 pw
= getpwnam(username
);
2087 if (best
->level
== AUTH_USER
)
2090 * If there are no names associated with this location, then
2091 * any valid user is OK...
2094 if (best
->num_names
== 0)
2098 * Otherwise check the user list and return OK if this user is
2102 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2103 "cupsdIsAuthorized: Checking user membership...");
2105 #ifdef HAVE_AUTHORIZATION_H
2107 * If an authorization reference was supplied it must match a right name...
2112 for (i
= 0; i
< best
->num_names
; i
++)
2114 if (!strncasecmp(best
->names
[i
], "@AUTHKEY(", 9) &&
2115 check_authref(con
, best
->names
[i
] + 9))
2117 else if (!strcasecmp(best
->names
[i
], "@SYSTEM") &&
2118 SystemGroupAuthKey
&&
2119 check_authref(con
, SystemGroupAuthKey
))
2123 return (HTTP_UNAUTHORIZED
);
2125 #endif /* HAVE_AUTHORIZATION_H */
2127 for (i
= 0; i
< best
->num_names
; i
++)
2129 if (!strcasecmp(best
->names
[i
], "@OWNER") && owner
&&
2130 !strcasecmp(username
, ownername
))
2132 else if (!strcasecmp(best
->names
[i
], "@SYSTEM"))
2134 for (j
= 0; j
< NumSystemGroups
; j
++)
2135 if (cupsdCheckGroup(username
, pw
, SystemGroups
[j
]))
2138 else if (best
->names
[i
][0] == '@')
2140 if (cupsdCheckGroup(username
, pw
, best
->names
[i
] + 1))
2143 else if (!strcasecmp(username
, best
->names
[i
]))
2147 return (HTTP_UNAUTHORIZED
);
2151 * Check to see if this user is in any of the named groups...
2154 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2155 "cupsdIsAuthorized: Checking group membership...");
2158 * Check to see if this user is in any of the named groups...
2161 for (i
= 0; i
< best
->num_names
; i
++)
2163 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2164 "cupsdIsAuthorized: Checking group \"%s\" membership...",
2167 if (!strcasecmp(best
->names
[i
], "@SYSTEM"))
2169 for (j
= 0; j
< NumSystemGroups
; j
++)
2170 if (cupsdCheckGroup(username
, pw
, SystemGroups
[j
]))
2173 else if (cupsdCheckGroup(username
, pw
, best
->names
[i
]))
2178 * The user isn't part of the specified group, so deny access...
2181 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2182 "cupsdIsAuthorized: User not in group(s)!");
2184 return (HTTP_UNAUTHORIZED
);
2189 * 'add_allow()' - Add an allow mask to the location.
2192 static cupsd_authmask_t
* /* O - New mask record */
2193 add_allow(cupsd_location_t
*loc
) /* I - Location to add to */
2195 cupsd_authmask_t
*temp
; /* New mask record */
2206 * Try to allocate memory for the record...
2209 if (loc
->num_allow
== 0)
2210 temp
= malloc(sizeof(cupsd_authmask_t
));
2212 temp
= realloc(loc
->allow
, sizeof(cupsd_authmask_t
) * (loc
->num_allow
+ 1));
2218 temp
+= loc
->num_allow
;
2222 * Clear the mask record and return...
2225 memset(temp
, 0, sizeof(cupsd_authmask_t
));
2231 * 'add_deny()' - Add a deny mask to the location.
2234 static cupsd_authmask_t
* /* O - New mask record */
2235 add_deny(cupsd_location_t
*loc
) /* I - Location to add to */
2237 cupsd_authmask_t
*temp
; /* New mask record */
2248 * Try to allocate memory for the record...
2251 if (loc
->num_deny
== 0)
2252 temp
= malloc(sizeof(cupsd_authmask_t
));
2254 temp
= realloc(loc
->deny
, sizeof(cupsd_authmask_t
) * (loc
->num_deny
+ 1));
2260 temp
+= loc
->num_deny
;
2264 * Clear the mask record and return...
2267 memset(temp
, 0, sizeof(cupsd_authmask_t
));
2272 #ifdef HAVE_AUTHORIZATION_H
2274 * 'check_authref()' - Check if an authorization services reference has the
2278 static int /* O - 1 if right is valid, 0 otherwise */
2279 check_authref(cupsd_client_t
*con
, /* I - Connection */
2280 const char *right
) /* I - Right name */
2282 OSStatus status
; /* OS Status */
2283 AuthorizationItem authright
; /* Authorization right */
2284 AuthorizationRights authrights
; /* Authorization rights */
2285 AuthorizationFlags authflags
; /* Authorization flags */
2289 * Check to see if the user is allowed to perform the task...
2295 authright
.name
= right
;
2296 authright
.valueLength
= 0;
2297 authright
.value
= NULL
;
2298 authright
.flags
= 0;
2300 authrights
.count
= 1;
2301 authrights
.items
= &authright
;
2303 authflags
= kAuthorizationFlagDefaults
|
2304 kAuthorizationFlagExtendRights
;
2306 if ((status
= AuthorizationCopyRights(con
->authref
, &authrights
,
2307 kAuthorizationEmptyEnvironment
,
2308 authflags
, NULL
)) != 0)
2310 cupsdLogMessage(CUPSD_LOG_ERROR
,
2311 "AuthorizationCopyRights(\"%s\") returned %d (%s)",
2312 authright
.name
, (int)status
, cssmErrorString(status
));
2316 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2317 "AuthorizationCopyRights(\"%s\") succeeded!",
2322 #endif /* HAVE_AUTHORIZATION_H */
2326 * 'compare_locations()' - Compare two locations.
2329 static int /* O - Result of comparison */
2330 compare_locations(cupsd_location_t
*a
, /* I - First location */
2331 cupsd_location_t
*b
) /* I - Second location */
2333 return (strcmp(b
->location
, a
->location
));
2337 #if !HAVE_LIBPAM && !defined(HAVE_USERSEC_H)
2339 * 'cups_crypt()' - Encrypt the password using the DES or MD5 algorithms,
2343 static char * /* O - Encrypted password */
2344 cups_crypt(const char *pw
, /* I - Password string */
2345 const char *salt
) /* I - Salt (key) string */
2347 if (!strncmp(salt
, "$1$", 3))
2350 * Use MD5 passwords without the benefit of PAM; this is for
2351 * Slackware Linux, and the algorithm was taken from the
2352 * old shadow-19990827/lib/md5crypt.c source code... :(
2355 int i
; /* Looping var */
2356 unsigned long n
; /* Output number */
2357 int pwlen
; /* Length of password string */
2358 const char *salt_end
; /* End of "salt" data for MD5 */
2359 char *ptr
; /* Pointer into result string */
2360 _cups_md5_state_t state
; /* Primary MD5 state info */
2361 _cups_md5_state_t state2
; /* Secondary MD5 state info */
2362 unsigned char digest
[16]; /* MD5 digest result */
2363 static char result
[120]; /* Final password string */
2367 * Get the salt data between dollar signs, e.g. $1$saltdata$md5.
2368 * Get a maximum of 8 characters of salt data after $1$...
2371 for (salt_end
= salt
+ 3; *salt_end
&& (salt_end
- salt
) < 11; salt_end
++)
2372 if (*salt_end
== '$')
2376 * Compute the MD5 sum we need...
2381 _cupsMD5Init(&state
);
2382 _cupsMD5Append(&state
, (unsigned char *)pw
, pwlen
);
2383 _cupsMD5Append(&state
, (unsigned char *)salt
, salt_end
- salt
);
2385 _cupsMD5Init(&state2
);
2386 _cupsMD5Append(&state2
, (unsigned char *)pw
, pwlen
);
2387 _cupsMD5Append(&state2
, (unsigned char *)salt
+ 3, salt_end
- salt
- 3);
2388 _cupsMD5Append(&state2
, (unsigned char *)pw
, pwlen
);
2389 _cupsMD5Finish(&state2
, digest
);
2391 for (i
= pwlen
; i
> 0; i
-= 16)
2392 _cupsMD5Append(&state
, digest
, i
> 16 ? 16 : i
);
2394 for (i
= pwlen
; i
> 0; i
>>= 1)
2395 _cupsMD5Append(&state
, (unsigned char *)((i
& 1) ? "" : pw
), 1);
2397 _cupsMD5Finish(&state
, digest
);
2399 for (i
= 0; i
< 1000; i
++)
2401 _cupsMD5Init(&state
);
2404 _cupsMD5Append(&state
, (unsigned char *)pw
, pwlen
);
2406 _cupsMD5Append(&state
, digest
, 16);
2409 _cupsMD5Append(&state
, (unsigned char *)salt
+ 3, salt_end
- salt
- 3);
2412 _cupsMD5Append(&state
, (unsigned char *)pw
, pwlen
);
2415 _cupsMD5Append(&state
, digest
, 16);
2417 _cupsMD5Append(&state
, (unsigned char *)pw
, pwlen
);
2419 _cupsMD5Finish(&state
, digest
);
2423 * Copy the final sum to the result string and return...
2426 memcpy(result
, salt
, salt_end
- salt
);
2427 ptr
= result
+ (salt_end
- salt
);
2430 for (i
= 0; i
< 5; i
++, ptr
+= 4)
2432 n
= (((digest
[i
] << 8) | digest
[i
+ 6]) << 8);
2435 n
|= digest
[i
+ 12];
2442 to64(ptr
, digest
[11], 2);
2451 * Use the standard crypt() function...
2454 return (crypt(pw
, salt
));
2457 #endif /* !HAVE_LIBPAM && !HAVE_USERSEC_H */
2462 * 'get_gss_creds()' - Obtain GSS credentials.
2465 static gss_cred_id_t
/* O - Server credentials */
2466 get_gss_creds(const char *service_name
) /* I - Service name */
2468 OM_uint32 major_status
, /* Major status code */
2469 minor_status
; /* Minor status code */
2470 gss_name_t server_name
; /* Server name */
2471 gss_cred_id_t server_creds
; /* Server credentials */
2472 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
2473 /* Service name token */
2474 char buf
[1024], /* Service name buffer */
2475 fqdn
[HTTP_MAX_URI
]; /* Hostname of server */
2478 snprintf(buf
, sizeof(buf
), "%s@%s", service_name
,
2479 httpGetHostname(NULL
, fqdn
, sizeof(fqdn
)));
2482 token
.length
= strlen(buf
);
2483 server_name
= GSS_C_NO_NAME
;
2484 major_status
= gss_import_name(&minor_status
, &token
,
2485 GSS_C_NT_HOSTBASED_SERVICE
,
2488 memset(&token
, 0, sizeof(token
));
2490 if (GSS_ERROR(major_status
))
2492 cupsdLogGSSMessage(CUPSD_LOG_WARN
, major_status
, minor_status
,
2493 "gss_import_name() failed");
2497 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
2499 if (GSS_ERROR(major_status
))
2501 cupsdLogGSSMessage(CUPSD_LOG_WARN
, major_status
, minor_status
,
2502 "gss_display_name() failed");
2506 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2507 "get_gss_creds: Attempting to acquire credentials for %s...",
2508 (char *)token
.value
);
2510 server_creds
= GSS_C_NO_CREDENTIAL
;
2511 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
2512 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
2513 &server_creds
, NULL
, NULL
);
2514 if (GSS_ERROR(major_status
))
2516 cupsdLogGSSMessage(CUPSD_LOG_WARN
, major_status
, minor_status
,
2517 "gss_acquire_cred() failed");
2518 gss_release_name(&minor_status
, &server_name
);
2519 gss_release_buffer(&minor_status
, &token
);
2523 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2524 "get_gss_creds: Credentials acquired successfully for %s.",
2525 (char *)token
.value
);
2527 gss_release_name(&minor_status
, &server_name
);
2528 gss_release_buffer(&minor_status
, &token
);
2530 return (server_creds
);
2532 #endif /* HAVE_GSSAPI */
2536 * 'get_md5_password()' - Get an MD5 password.
2539 static char * /* O - MD5 password string */
2540 get_md5_password(const char *username
, /* I - Username */
2541 const char *group
, /* I - Group */
2542 char passwd
[33]) /* O - MD5 password string */
2544 cups_file_t
*fp
; /* passwd.md5 file */
2545 char filename
[1024], /* passwd.md5 filename */
2546 line
[256], /* Line from file */
2547 tempuser
[33], /* User from file */
2548 tempgroup
[33]; /* Group from file */
2551 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2552 "get_md5_password(username=\"%s\", group=\"%s\", passwd=%p)",
2553 username
, group
? group
: "(null)", passwd
);
2555 snprintf(filename
, sizeof(filename
), "%s/passwd.md5", ServerRoot
);
2556 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
2558 if (errno
!= ENOENT
)
2559 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", filename
,
2565 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
2567 if (sscanf(line
, "%32[^:]:%32[^:]:%32s", tempuser
, tempgroup
, passwd
) != 3)
2569 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad MD5 password line: %s", line
);
2573 if (!strcmp(username
, tempuser
) &&
2574 (group
== NULL
|| !strcmp(group
, tempgroup
)))
2577 * Found the password entry!
2580 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "Found MD5 user %s, group %s...",
2581 username
, tempgroup
);
2589 * Didn't find a password entry - return NULL!
2599 * 'pam_func()' - PAM conversation function.
2602 static int /* O - Success or failure */
2604 int num_msg
, /* I - Number of messages */
2605 const struct pam_message
**msg
, /* I - Messages */
2606 struct pam_response
**resp
, /* O - Responses */
2608 /* I - Pointer to connection */
2610 int i
; /* Looping var */
2611 struct pam_response
*replies
; /* Replies */
2612 cupsd_authdata_t
*data
; /* Pointer to auth data */
2616 * Allocate memory for the responses...
2619 if ((replies
= malloc(sizeof(struct pam_response
) * num_msg
)) == NULL
)
2620 return (PAM_CONV_ERR
);
2623 * Answer all of the messages...
2626 DEBUG_printf(("pam_func: appdata_ptr = %p\n", appdata_ptr
));
2630 * Apparently some versions of HP-UX 11 have a broken pam_unix security
2631 * module. This is a workaround...
2637 data
= (cupsd_authdata_t
*)appdata_ptr
;
2640 for (i
= 0; i
< num_msg
; i
++)
2642 DEBUG_printf(("pam_func: Message = \"%s\"\n", msg
[i
]->msg
));
2644 switch (msg
[i
]->msg_style
)
2646 case PAM_PROMPT_ECHO_ON
:
2647 DEBUG_printf(("pam_func: PAM_PROMPT_ECHO_ON, returning \"%s\"...\n",
2649 replies
[i
].resp_retcode
= PAM_SUCCESS
;
2650 replies
[i
].resp
= strdup(data
->username
);
2653 case PAM_PROMPT_ECHO_OFF
:
2654 DEBUG_printf(("pam_func: PAM_PROMPT_ECHO_OFF, returning \"%s\"...\n",
2656 replies
[i
].resp_retcode
= PAM_SUCCESS
;
2657 replies
[i
].resp
= strdup(data
->password
);
2661 DEBUG_puts("pam_func: PAM_TEXT_INFO...");
2662 replies
[i
].resp_retcode
= PAM_SUCCESS
;
2663 replies
[i
].resp
= NULL
;
2667 DEBUG_puts("pam_func: PAM_ERROR_MSG...");
2668 replies
[i
].resp_retcode
= PAM_SUCCESS
;
2669 replies
[i
].resp
= NULL
;
2673 DEBUG_printf(("pam_func: Unknown PAM message %d...\n",
2674 msg
[i
]->msg_style
));
2676 return (PAM_CONV_ERR
);
2681 * Return the responses back to PAM...
2686 return (PAM_SUCCESS
);
2688 #elif !defined(HAVE_USERSEC_H)
2692 * 'to64()' - Base64-encode an integer value...
2696 to64(char *s
, /* O - Output string */
2697 unsigned long v
, /* I - Value to encode */
2698 int n
) /* I - Number of digits */
2700 const char *itoa64
= "./0123456789"
2701 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2702 "abcdefghijklmnopqrstuvwxyz";
2705 for (; n
> 0; n
--, v
>>= 6)
2706 *s
++ = itoa64
[v
& 0x3f];
2708 #endif /* HAVE_LIBPAM */
2712 * End of "$Id: auth.c 6947 2007-09-12 21:09:49Z mike $".