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 temp
->location
= strdup(location
);
183 temp
->length
= strlen(temp
->location
);
185 cupsArrayAdd(Locations
, temp
);
187 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddLocation: added location \'%s\'",
191 * Return the new record...
199 * 'cupsdAddName()' - Add a name to a location...
203 cupsdAddName(cupsd_location_t
*loc
, /* I - Location to add to */
204 char *name
) /* I - Name to add */
206 char **temp
; /* Pointer to names array */
209 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddName(loc=%p, name=\"%s\")",
212 if (loc
->num_names
== 0)
213 temp
= malloc(sizeof(char *));
215 temp
= realloc(loc
->names
, (loc
->num_names
+ 1) * sizeof(char *));
219 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to add name to location %s: %s",
220 loc
->location
? loc
->location
: "nil", strerror(errno
));
226 if ((temp
[loc
->num_names
] = strdup(name
)) == NULL
)
228 cupsdLogMessage(CUPSD_LOG_ERROR
,
229 "Unable to duplicate name for location %s: %s",
230 loc
->location
? loc
->location
: "nil", strerror(errno
));
239 * 'cupsdAllowHost()' - Add a host name that is allowed to access the location.
243 cupsdAllowHost(cupsd_location_t
*loc
, /* I - Location to add to */
244 char *name
) /* I - Name of host or domain to add */
246 cupsd_authmask_t
*temp
; /* New host/domain mask */
247 char ifname
[32], /* Interface name */
248 *ifptr
; /* Pointer to end of name */
251 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAllowHost(loc=%p(%s), name=\"%s\")",
252 loc
, loc
->location
? loc
->location
: "nil", name
);
254 if ((temp
= add_allow(loc
)) == NULL
)
257 if (!strcasecmp(name
, "@LOCAL"))
260 * Allow *interface*...
263 temp
->type
= AUTH_INTERFACE
;
264 temp
->mask
.name
.name
= strdup("*");
265 temp
->mask
.name
.length
= 1;
267 else if (!strncasecmp(name
, "@IF(", 4))
270 * Allow *interface*...
273 strlcpy(ifname
, name
+ 4, sizeof(ifname
));
275 ifptr
= ifname
+ strlen(ifname
);
277 if (ifptr
[-1] == ')')
283 temp
->type
= AUTH_INTERFACE
;
284 temp
->mask
.name
.name
= strdup(ifname
);
285 temp
->mask
.name
.length
= ifptr
- ifname
;
293 temp
->type
= AUTH_NAME
;
294 temp
->mask
.name
.name
= strdup(name
);
295 temp
->mask
.name
.length
= strlen(name
);
301 * 'cupsdAllowIP()' - Add an IP address or network that is allowed to access
306 cupsdAllowIP(cupsd_location_t
*loc
, /* I - Location to add to */
307 unsigned address
[4], /* I - IP address to add */
308 unsigned netmask
[4]) /* I - Netmask of address */
310 cupsd_authmask_t
*temp
; /* New host/domain mask */
313 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
314 "cupsdAllowIP(loc=%p(%s), address=%x:%x:%x:%x, netmask=%x:%x:%x:%x)",
315 loc
, loc
->location
? loc
->location
: "nil",
316 address
[0], address
[1], address
[2], address
[3],
317 netmask
[0], netmask
[1], netmask
[2], netmask
[3]);
319 if ((temp
= add_allow(loc
)) == NULL
)
322 temp
->type
= AUTH_IP
;
323 memcpy(temp
->mask
.ip
.address
, address
, sizeof(temp
->mask
.ip
.address
));
324 memcpy(temp
->mask
.ip
.netmask
, netmask
, sizeof(temp
->mask
.ip
.netmask
));
329 * 'cupsdAuthorize()' - Validate any authorization credentials.
333 cupsdAuthorize(cupsd_client_t
*con
) /* I - Client connection */
335 int type
; /* Authentication type */
336 const char *authorization
; /* Pointer into Authorization string */
337 char *ptr
, /* Pointer into string */
338 username
[256], /* Username string */
339 password
[33]; /* Password string */
340 const char *localuser
; /* Certificate username */
341 char nonce
[HTTP_MAX_VALUE
], /* Nonce value from client */
342 md5
[33], /* MD5 password */
343 basicmd5
[33]; /* MD5 of Basic password */
344 static const char * const states
[] = /* HTTP client states... */
364 * Locate the best matching location so we know what kind of
365 * authentication to expect...
368 con
->best
= cupsdFindBest(con
->uri
, con
->http
.state
);
369 con
->type
= AUTH_NONE
;
371 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
372 "cupsdAuthorize: con->uri=\"%s\", con->best=%p(%s)",
373 con
->uri
, con
->best
, con
->best
? con
->best
->location
: "");
375 if (con
->best
&& con
->best
->type
!= AUTH_NONE
)
377 if (con
->best
->type
== AUTH_DEFAULT
)
378 type
= DefaultAuthType
;
380 type
= con
->best
->type
;
383 type
= DefaultAuthType
;
386 * Decode the Authorization string...
389 authorization
= httpGetField(&con
->http
, HTTP_FIELD_AUTHORIZATION
);
391 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAuthorize: Authorization=\"%s\"",
397 #ifdef HAVE_AUTHORIZATION_H
400 AuthorizationFree(con
->authref
, kAuthorizationFlagDefaults
);
403 #endif /* HAVE_AUTHORIZATION_H */
408 * No authorization data provided, return early...
411 cupsdLogMessage(CUPSD_LOG_DEBUG
,
412 "cupsdAuthorize: No authentication data provided.");
415 #ifdef HAVE_AUTHORIZATION_H
416 else if (!strncmp(authorization
, "AuthRef", 6) &&
417 !strcasecmp(con
->http
.hostname
, "localhost"))
419 OSStatus status
; /* Status */
420 int authlen
; /* Auth string length */
421 AuthorizationItemSet
*authinfo
; /* Authorization item set */
424 * Get the Authorization Services data...
428 while (isspace(*authorization
& 255))
431 authlen
= sizeof(nonce
);
432 httpDecode64_2(nonce
, &authlen
, authorization
);
434 if (authlen
!= kAuthorizationExternalFormLength
)
436 cupsdLogMessage(CUPSD_LOG_ERROR
,
437 "External Authorization reference size is incorrect!");
441 if ((status
= AuthorizationCreateFromExternalForm(
442 (AuthorizationExternalForm
*)nonce
, &con
->authref
)) != 0)
444 cupsdLogMessage(CUPSD_LOG_ERROR
,
445 "AuthorizationCreateFromExternalForm returned %d (%s)",
446 (int)status
, cssmErrorString(status
));
450 if ((status
= AuthorizationCopyInfo(con
->authref
,
451 kAuthorizationEnvironmentUsername
,
454 cupsdLogMessage(CUPSD_LOG_ERROR
,
455 "AuthorizationCopyInfo returned %d (%s)",
456 (int)status
, cssmErrorString(status
));
460 if (authinfo
->count
== 1)
461 strlcpy(username
, authinfo
->items
[0].value
, sizeof(username
));
463 cupsdLogMessage(CUPSD_LOG_DEBUG
,
464 "cupsdAuthorize: Authorized as %s using AuthRef",
467 AuthorizationFreeItemSet(authinfo
);
469 con
->type
= AUTH_BASIC
;
471 #endif /* HAVE_AUTHORIZATION_H */
472 #if defined(SO_PEERCRED) && defined(AF_LOCAL)
473 else if (!strncmp(authorization
, "PeerCred ", 9) &&
474 con
->http
.hostaddr
->addr
.sa_family
== AF_LOCAL
)
477 * Use peer credentials from domain socket connection...
480 struct passwd
*pwd
; /* Password entry for this user */
481 cupsd_ucred_t peercred
; /* Peer credentials */
482 socklen_t peersize
; /* Size of peer credentials */
485 if ((pwd
= getpwnam(authorization
+ 9)) == NULL
)
487 cupsdLogMessage(CUPSD_LOG_ERROR
, "User \"%s\" does not exist!",
492 peersize
= sizeof(peercred
);
494 if (getsockopt(con
->http
.fd
, SOL_SOCKET
, SO_PEERCRED
, &peercred
, &peersize
))
496 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to get peer credentials - %s",
501 if (pwd
->pw_uid
!= CUPSD_UCRED_UID(peercred
))
503 cupsdLogMessage(CUPSD_LOG_ERROR
,
504 "Invalid peer credentials for \"%s\" - got %d, "
505 "expected %d!", authorization
+ 9,
506 CUPSD_UCRED_UID(peercred
), pwd
->pw_uid
);
507 # ifdef HAVE_SYS_UCRED_H
508 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdAuthorize: cr_version=%d",
509 peercred
.cr_version
);
510 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdAuthorize: cr_uid=%d",
512 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdAuthorize: cr_ngroups=%d",
513 peercred
.cr_ngroups
);
514 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdAuthorize: cr_groups[0]=%d",
515 peercred
.cr_groups
[0]);
516 # endif /* HAVE_SYS_UCRED_H */
520 strlcpy(username
, authorization
+ 9, sizeof(username
));
522 cupsdLogMessage(CUPSD_LOG_DEBUG
,
523 "cupsdAuthorize: Authorized as %s using PeerCred",
526 con
->type
= AUTH_BASIC
;
528 #endif /* SO_PEERCRED && AF_LOCAL */
529 else if (!strncmp(authorization
, "Local", 5) &&
530 !strcasecmp(con
->http
.hostname
, "localhost"))
533 * Get Local certificate authentication data...
537 while (isspace(*authorization
& 255))
540 if ((localuser
= cupsdFindCert(authorization
)) != NULL
)
542 strlcpy(username
, localuser
, sizeof(username
));
544 cupsdLogMessage(CUPSD_LOG_DEBUG
,
545 "cupsdAuthorize: Authorized as %s using Local",
550 cupsdLogMessage(CUPSD_LOG_ERROR
,
551 "cupsdAuthorize: Local authentication certificate not "
556 con
->type
= AUTH_BASIC
;
558 else if (!strncmp(authorization
, "Basic", 5))
561 * Get the Basic authentication data...
564 int userlen
; /* Username:password length */
568 while (isspace(*authorization
& 255))
571 userlen
= sizeof(username
);
572 httpDecode64_2(username
, &userlen
, authorization
);
575 * Pull the username and password out...
578 if ((ptr
= strchr(username
, ':')) == NULL
)
580 cupsdLogMessage(CUPSD_LOG_ERROR
,
581 "cupsdAuthorize: Missing Basic password!");
590 * Username must not be empty...
593 cupsdLogMessage(CUPSD_LOG_ERROR
,
594 "cupsdAuthorize: Empty Basic username!");
601 * Password must not be empty...
604 cupsdLogMessage(CUPSD_LOG_ERROR
,
605 "cupsdAuthorize: Empty Basic password!");
609 strlcpy(password
, ptr
, sizeof(password
));
612 * Validate the username and password...
622 * Only use PAM to do authentication. This supports MD5
623 * passwords, among other things...
626 pam_handle_t
*pamh
; /* PAM authentication handle */
627 int pamerr
; /* PAM error code */
628 struct pam_conv pamdata
;/* PAM conversation data */
629 cupsd_authdata_t data
; /* Authentication data */
632 strlcpy(data
.username
, username
, sizeof(data
.username
));
633 strlcpy(data
.password
, password
, sizeof(data
.password
));
635 # if defined(__sun) || defined(__hpux)
636 pamdata
.conv
= (int (*)(int, struct pam_message
**,
637 struct pam_response
**,
640 pamdata
.conv
= pam_func
;
641 # endif /* __sun || __hpux */
642 pamdata
.appdata_ptr
= &data
;
646 * Workaround for HP-UX bug in pam_unix; see pam_func() below for
653 pamerr
= pam_start("cups", username
, &pamdata
, &pamh
);
654 if (pamerr
!= PAM_SUCCESS
)
656 cupsdLogMessage(CUPSD_LOG_ERROR
,
657 "cupsdAuthorize: pam_start() returned %d (%s)!\n",
658 pamerr
, pam_strerror(pamh
, pamerr
));
663 # if defined(HAVE_PAM_SET_ITEM) && defined(PAM_RHOST)
664 pamerr
= pam_set_item(pamh
, PAM_RHOST
, con
->http
.hostname
);
665 if (pamerr
!= PAM_SUCCESS
)
666 cupsdLogMessage(CUPSD_LOG_WARN
,
667 "cupsdAuthorize: pam_set_item() returned %d "
668 "(%s)!\n", pamerr
, pam_strerror(pamh
, pamerr
));
669 # endif /* HAVE_PAM_SET_ITEM && PAM_RHOST */
671 pamerr
= pam_authenticate(pamh
, PAM_SILENT
);
672 if (pamerr
!= PAM_SUCCESS
)
674 cupsdLogMessage(CUPSD_LOG_ERROR
,
675 "cupsdAuthorize: pam_authenticate() returned %d "
677 pamerr
, pam_strerror(pamh
, pamerr
));
682 pamerr
= pam_acct_mgmt(pamh
, PAM_SILENT
);
683 if (pamerr
!= PAM_SUCCESS
)
685 cupsdLogMessage(CUPSD_LOG_ERROR
,
686 "cupsdAuthorize: pam_acct_mgmt() returned %d "
688 pamerr
, pam_strerror(pamh
, pamerr
));
693 pam_end(pamh
, PAM_SUCCESS
);
695 #elif defined(HAVE_USERSEC_H)
697 * Use AIX authentication interface...
700 char *authmsg
; /* Authentication message */
701 int reenter
; /* ??? */
704 cupsdLogMessage(CUPSD_LOG_DEBUG
,
705 "cupsdAuthorize: AIX authenticate of username \"%s\"",
709 if (authenticate(username
, password
, &reenter
, &authmsg
) != 0)
711 cupsdLogMessage(CUPSD_LOG_DEBUG
,
712 "cupsdAuthorize: Unable to authenticate username "
714 username
, strerror(errno
));
720 * Use normal UNIX password file-based authentication...
723 char *pass
; /* Encrypted password */
724 struct passwd
*pw
; /* User password data */
725 # ifdef HAVE_SHADOW_H
726 struct spwd
*spw
; /* Shadow password data */
727 # endif /* HAVE_SHADOW_H */
730 pw
= getpwnam(username
); /* Get the current password */
731 endpwent(); /* Close the password file */
739 cupsdLogMessage(CUPSD_LOG_ERROR
,
740 "cupsdAuthorize: Unknown username \"%s\"!",
745 # ifdef HAVE_SHADOW_H
746 spw
= getspnam(username
);
749 if (!spw
&& !strcmp(pw
->pw_passwd
, "x"))
752 * Don't allow blank passwords!
755 cupsdLogMessage(CUPSD_LOG_ERROR
,
756 "cupsdAuthorize: Username \"%s\" has no shadow "
757 "password!", username
);
761 if (spw
&& !spw
->sp_pwdp
[0] && !pw
->pw_passwd
[0])
763 if (!pw
->pw_passwd
[0])
764 # endif /* HAVE_SHADOW_H */
767 * Don't allow blank passwords!
770 cupsdLogMessage(CUPSD_LOG_ERROR
,
771 "cupsdAuthorize: Username \"%s\" has no password!",
777 * OK, the password isn't blank, so compare with what came from the
781 pass
= cups_crypt(password
, pw
->pw_passwd
);
783 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
784 "cupsdAuthorize: pw_passwd=\"%s\", crypt=\"%s\"",
785 pw
->pw_passwd
, pass
);
787 if (!pass
|| strcmp(pw
->pw_passwd
, pass
))
789 # ifdef HAVE_SHADOW_H
792 pass
= cups_crypt(password
, spw
->sp_pwdp
);
794 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
795 "cupsdAuthorize: sp_pwdp=\"%s\", crypt=\"%s\"",
798 if (pass
== NULL
|| strcmp(spw
->sp_pwdp
, pass
))
800 cupsdLogMessage(CUPSD_LOG_ERROR
,
801 "cupsdAuthorize: Authentication failed for "
808 # endif /* HAVE_SHADOW_H */
810 cupsdLogMessage(CUPSD_LOG_ERROR
,
811 "cupsdAuthorize: Authentication failed for "
817 #endif /* HAVE_LIBPAM */
820 cupsdLogMessage(CUPSD_LOG_DEBUG
,
821 "cupsdAuthorize: Authorized as %s using Basic",
825 case AUTH_BASICDIGEST
:
827 * Do Basic authentication with the Digest password file...
830 if (!get_md5_password(username
, NULL
, md5
))
832 cupsdLogMessage(CUPSD_LOG_ERROR
,
833 "cupsdAuthorize: Unknown MD5 username \"%s\"!",
838 httpMD5(username
, "CUPS", password
, basicmd5
);
840 if (strcmp(md5
, basicmd5
))
842 cupsdLogMessage(CUPSD_LOG_ERROR
,
843 "cupsdAuthorize: Authentication failed for \"%s\"!",
848 cupsdLogMessage(CUPSD_LOG_DEBUG
,
849 "cupsdAuthorize: Authorized as %s using BasicDigest",
856 else if (!strncmp(authorization
, "Digest", 6))
859 * Get the username, password, and nonce from the Digest attributes...
862 if (!httpGetSubField2(&(con
->http
), HTTP_FIELD_AUTHORIZATION
, "username",
863 username
, sizeof(username
)) || !username
[0])
866 * Username must not be empty...
869 cupsdLogMessage(CUPSD_LOG_ERROR
,
870 "cupsdAuthorize: Empty or missing Digest username!");
874 if (!httpGetSubField2(&(con
->http
), HTTP_FIELD_AUTHORIZATION
, "response",
875 password
, sizeof(password
)) || !password
[0])
878 * Password must not be empty...
881 cupsdLogMessage(CUPSD_LOG_ERROR
,
882 "cupsdAuthorize: Empty or missing Digest password!");
886 if (!httpGetSubField(&(con
->http
), HTTP_FIELD_AUTHORIZATION
, "nonce",
889 cupsdLogMessage(CUPSD_LOG_ERROR
,
890 "cupsdAuthorize: No nonce value for Digest "
895 if (strcmp(con
->http
.hostname
, nonce
))
897 cupsdLogMessage(CUPSD_LOG_ERROR
,
898 "cupsdAuthorize: Bad nonce value, expected \"%s\", "
899 "got \"%s\"!", con
->http
.hostname
, nonce
);
904 * Validate the username and password...
907 if (!get_md5_password(username
, NULL
, md5
))
909 cupsdLogMessage(CUPSD_LOG_ERROR
,
910 "cupsdAuthorize: Unknown MD5 username \"%s\"!",
915 httpMD5Final(nonce
, states
[con
->http
.state
], con
->uri
, md5
);
917 if (strcmp(md5
, password
))
919 cupsdLogMessage(CUPSD_LOG_ERROR
,
920 "cupsdAuthorize: Authentication failed for \"%s\"!",
925 cupsdLogMessage(CUPSD_LOG_DEBUG
,
926 "cupsdAuthorize: Authorized as %s using Digest",
929 con
->type
= AUTH_DIGEST
;
932 else if (!strncmp(authorization
, "Negotiate", 9))
934 int len
; /* Length of authorization string */
935 gss_cred_id_t server_creds
; /* Server credentials */
936 gss_ctx_id_t context
; /* Authorization context */
937 OM_uint32 major_status
, /* Major status code */
938 minor_status
; /* Minor status code */
939 gss_buffer_desc input_token
= GSS_C_EMPTY_BUFFER
,
940 /* Input token from string */
941 output_token
= GSS_C_EMPTY_BUFFER
;
942 /* Output token for username */
943 gss_name_t client_name
; /* Client name */
944 unsigned int ret_flags
; /* Credential flags */
949 * If the weak-linked GSSAPI/Kerberos library is not present, don't try
953 if (gss_init_sec_context
== NULL
)
955 cupsdLogMessage(CUPSD_LOG_WARN
,
956 "GSSAPI/Kerberos authentication failed because the "
957 "Kerberos framework is not present.");
960 # endif /* __APPLE__ */
962 con
->gss_output_token
.length
= 0;
965 * Find the start of the Kerberos input token...
969 while (isspace(*authorization
& 255))
974 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
975 "cupsdAuthorize: No authentication data specified.");
980 * Get the server credentials...
983 if ((server_creds
= get_gss_creds(GSSServiceName
)) == NULL
)
987 * Decode the authorization string to get the input token...
990 len
= strlen(authorization
);
991 input_token
.value
= malloc(len
);
992 input_token
.value
= httpDecode64_2(input_token
.value
, &len
,
994 input_token
.length
= len
;
997 * Accept the input token to get the authorization info...
1000 context
= GSS_C_NO_CONTEXT
;
1001 client_name
= GSS_C_NO_NAME
;
1002 major_status
= gss_accept_sec_context(&minor_status
,
1006 GSS_C_NO_CHANNEL_BINDINGS
,
1009 &con
->gss_output_token
,
1012 &con
->gss_delegated_cred
);
1014 if (GSS_ERROR(major_status
))
1016 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
1017 "cupsdAuthorize: Error accepting GSSAPI security "
1020 if (context
!= GSS_C_NO_CONTEXT
)
1021 gss_delete_sec_context(&minor_status
, &context
, GSS_C_NO_BUFFER
);
1023 gss_release_cred(&minor_status
, &server_creds
);
1028 * Release our credentials...
1031 gss_release_cred(&minor_status
, &server_creds
);
1034 * Get the username associated with the client's credentials...
1037 if (!con
->gss_delegated_cred
)
1038 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1039 "cupsdAuthorize: No delegated credentials!");
1041 if (major_status
== GSS_S_CONTINUE_NEEDED
)
1042 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
1043 "cupsdAuthorize: Credentials not complete");
1044 else if (major_status
== GSS_S_COMPLETE
)
1046 major_status
= gss_display_name(&minor_status
, client_name
,
1047 &output_token
, NULL
);
1049 if (GSS_ERROR(major_status
))
1051 cupsdLogGSSMessage(CUPSD_LOG_DEBUG
, major_status
, minor_status
,
1052 "cupsdAuthorize: Error getting username");
1053 gss_release_name(&minor_status
, &client_name
);
1054 gss_delete_sec_context(&minor_status
, &context
, GSS_C_NO_BUFFER
);
1058 gss_release_name(&minor_status
, &client_name
);
1059 strlcpy(username
, output_token
.value
, sizeof(username
));
1061 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1062 "cupsdAuthorize: Authorized as %s using Negotiate",
1065 gss_release_buffer(&minor_status
, &output_token
);
1066 gss_delete_sec_context(&minor_status
, &context
, GSS_C_NO_BUFFER
);
1068 con
->gss_have_creds
= 1;
1070 con
->type
= AUTH_NEGOTIATE
;
1073 gss_release_name(&minor_status
, &client_name
);
1075 #endif /* HAVE_GSSAPI */
1078 char scheme
[256]; /* Auth scheme... */
1081 if (sscanf(authorization
, "%255s", scheme
) != 1)
1082 strcpy(scheme
, "UNKNOWN");
1084 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad authentication data \"%s ...\"",
1090 * If we get here, then we were able to validate the username and
1091 * password - copy the validated username and password to the client
1092 * data and return...
1095 strlcpy(con
->username
, username
, sizeof(con
->username
));
1096 strlcpy(con
->password
, password
, sizeof(con
->password
));
1101 * 'cupsdCheckAccess()' - Check whether the given address is allowed to
1102 * access a location.
1105 int /* O - 1 if allowed, 0 otherwise */
1107 unsigned ip
[4], /* I - Client address */
1108 char *name
, /* I - Client hostname */
1109 int namelen
, /* I - Length of hostname */
1110 cupsd_location_t
*loc
) /* I - Location to check */
1112 int allow
; /* 1 if allowed, 0 otherwise */
1115 if (!strcasecmp(name
, "localhost"))
1118 * Access from localhost (127.0.0.1 or ::1) is always allowed...
1126 * Do authorization checks on the domain/address...
1129 switch (loc
->order_type
)
1132 allow
= 0; /* anti-compiler-warning-code */
1135 case AUTH_ALLOW
: /* Order Deny,Allow */
1138 if (cupsdCheckAuth(ip
, name
, namelen
, loc
->num_deny
, loc
->deny
))
1141 if (cupsdCheckAuth(ip
, name
, namelen
, loc
->num_allow
, loc
->allow
))
1145 case AUTH_DENY
: /* Order Allow,Deny */
1148 if (cupsdCheckAuth(ip
, name
, namelen
, loc
->num_allow
, loc
->allow
))
1151 if (cupsdCheckAuth(ip
, name
, namelen
, loc
->num_deny
, loc
->deny
))
1162 * 'cupsdCheckAuth()' - Check authorization masks.
1165 int /* O - 1 if mask matches, 0 otherwise */
1167 unsigned ip
[4], /* I - Client address */
1168 char *name
, /* I - Client hostname */
1169 int name_len
, /* I - Length of hostname */
1170 int num_masks
, /* I - Number of masks */
1171 cupsd_authmask_t
*masks
) /* I - Masks */
1173 int i
; /* Looping var */
1174 cupsd_netif_t
*iface
; /* Network interface */
1175 unsigned netip4
; /* IPv4 network address */
1177 unsigned netip6
[4]; /* IPv6 network address */
1178 #endif /* AF_INET6 */
1180 while (num_masks
> 0)
1182 switch (masks
->type
)
1184 case AUTH_INTERFACE
:
1186 * Check for a match with a network interface...
1189 netip4
= htonl(ip
[3]);
1192 netip6
[0] = htonl(ip
[0]);
1193 netip6
[1] = htonl(ip
[1]);
1194 netip6
[2] = htonl(ip
[2]);
1195 netip6
[3] = htonl(ip
[3]);
1196 #endif /* AF_INET6 */
1198 if (!strcmp(masks
->mask
.name
.name
, "*"))
1201 * Check against all local interfaces...
1206 for (iface
= (cupsd_netif_t
*)cupsArrayFirst(NetIFList
);
1208 iface
= (cupsd_netif_t
*)cupsArrayNext(NetIFList
))
1211 * Only check local interfaces...
1214 if (!iface
->is_local
)
1217 if (iface
->address
.addr
.sa_family
== AF_INET
)
1220 * Check IPv4 address...
1223 if ((netip4
& iface
->mask
.ipv4
.sin_addr
.s_addr
) ==
1224 (iface
->address
.ipv4
.sin_addr
.s_addr
&
1225 iface
->mask
.ipv4
.sin_addr
.s_addr
))
1232 * Check IPv6 address...
1235 for (i
= 0; i
< 4; i
++)
1236 if ((netip6
[i
] & iface
->mask
.ipv6
.sin6_addr
.s6_addr32
[i
]) !=
1237 (iface
->address
.ipv6
.sin6_addr
.s6_addr32
[i
] &
1238 iface
->mask
.ipv6
.sin6_addr
.s6_addr32
[i
]))
1244 #endif /* AF_INET6 */
1250 * Check the named interface...
1253 for (iface
= (cupsd_netif_t
*)cupsArrayFirst(NetIFList
);
1255 iface
= (cupsd_netif_t
*)cupsArrayNext(NetIFList
))
1257 if (strcmp(masks
->mask
.name
.name
, iface
->name
))
1260 if (iface
->address
.addr
.sa_family
== AF_INET
)
1263 * Check IPv4 address...
1266 if ((netip4
& iface
->mask
.ipv4
.sin_addr
.s_addr
) ==
1267 (iface
->address
.ipv4
.sin_addr
.s_addr
&
1268 iface
->mask
.ipv4
.sin_addr
.s_addr
))
1275 * Check IPv6 address...
1278 for (i
= 0; i
< 4; i
++)
1279 if ((netip6
[i
] & iface
->mask
.ipv6
.sin6_addr
.s6_addr32
[i
]) !=
1280 (iface
->address
.ipv6
.sin6_addr
.s6_addr32
[i
] &
1281 iface
->mask
.ipv6
.sin6_addr
.s6_addr32
[i
]))
1287 #endif /* AF_INET6 */
1294 * Check for exact name match...
1297 if (!strcasecmp(name
, masks
->mask
.name
.name
))
1301 * Check for domain match...
1304 if (name_len
>= masks
->mask
.name
.length
&&
1305 masks
->mask
.name
.name
[0] == '.' &&
1306 !strcasecmp(name
+ name_len
- masks
->mask
.name
.length
,
1307 masks
->mask
.name
.name
))
1313 * Check for IP/network address match...
1316 for (i
= 0; i
< 4; i
++)
1317 if ((ip
[i
] & masks
->mask
.ip
.netmask
[i
]) !=
1318 masks
->mask
.ip
.address
[i
])
1335 * 'cupsdCheckGroup()' - Check for a user's group membership.
1338 int /* O - 1 if user is a member, 0 otherwise */
1340 const char *username
, /* I - User name */
1341 struct passwd
*user
, /* I - System user info */
1342 const char *groupname
) /* I - Group name */
1344 int i
; /* Looping var */
1345 struct group
*group
; /* System group info */
1346 char junk
[33]; /* MD5 password (not used) */
1347 #ifdef HAVE_MBR_UID_TO_UUID
1348 uuid_t useruuid
, /* UUID for username */
1349 groupuuid
; /* UUID for groupname */
1350 int is_member
; /* True if user is a member of group */
1351 #endif /* HAVE_MBR_UID_TO_UUID */
1354 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1355 "cupsdCheckGroup(username=\"%s\", user=%p, groupname=\"%s\")",
1356 username
, user
, groupname
);
1362 if (!username
|| !groupname
)
1366 * Check to see if the user is a member of the named group...
1369 group
= getgrnam(groupname
);
1375 * Group exists, check it...
1378 for (i
= 0; group
->gr_mem
[i
]; i
++)
1379 if (!strcasecmp(username
, group
->gr_mem
[i
]))
1384 * Group doesn't exist or user not in group list, check the group ID
1385 * against the user's group ID...
1388 if (user
&& group
&& group
->gr_gid
== user
->pw_gid
)
1391 #ifdef HAVE_MBR_UID_TO_UUID
1393 * Check group membership through MacOS X membership API...
1397 if (!mbr_uid_to_uuid(user
->pw_uid
, useruuid
))
1398 if (!mbr_gid_to_uuid(group
->gr_gid
, groupuuid
))
1399 if (!mbr_check_membership(useruuid
, groupuuid
, &is_member
))
1402 #endif /* HAVE_MBR_UID_TO_UUID */
1405 * Username not found, group not found, or user is not part of the
1406 * system group... Check for a user and group in the MD5 password
1410 if (get_md5_password(username
, groupname
, junk
) != NULL
)
1414 * If we get this far, then the user isn't part of the named group...
1422 * 'cupsdCopyLocation()' - Make a copy of a location...
1425 cupsd_location_t
* /* O - New location */
1427 cupsd_location_t
**loc
) /* IO - Original location */
1429 int i
; /* Looping var */
1430 cupsd_location_t
*temp
; /* New location */
1431 char location
[HTTP_MAX_URI
];
1432 /* Location of resource */
1436 * Use a local copy of location because cupsdAddLocation may cause
1437 * this memory to be moved...
1440 strlcpy(location
, (*loc
)->location
, sizeof(location
));
1442 if ((temp
= cupsdAddLocation(location
)) == NULL
)
1446 * Copy the information from the original location to the new one.
1449 temp
->limit
= (*loc
)->limit
;
1450 temp
->order_type
= (*loc
)->order_type
;
1451 temp
->type
= (*loc
)->type
;
1452 temp
->level
= (*loc
)->level
;
1453 temp
->satisfy
= (*loc
)->satisfy
;
1454 temp
->encryption
= (*loc
)->encryption
;
1456 if ((temp
->num_names
= (*loc
)->num_names
) > 0)
1459 * Copy the names array...
1462 if ((temp
->names
= calloc(temp
->num_names
, sizeof(char *))) == NULL
)
1464 cupsdLogMessage(CUPSD_LOG_ERROR
,
1465 "cupsdCopyLocation: Unable to allocate memory for %d names: %s",
1466 temp
->num_names
, strerror(errno
));
1468 cupsdDeleteLocation(temp
);
1472 for (i
= 0; i
< temp
->num_names
; i
++)
1473 if ((temp
->names
[i
] = strdup((*loc
)->names
[i
])) == NULL
)
1475 cupsdLogMessage(CUPSD_LOG_ERROR
,
1476 "cupsdCopyLocation: Unable to copy name \"%s\": %s",
1477 (*loc
)->names
[i
], strerror(errno
));
1479 cupsdDeleteLocation(temp
);
1484 if ((temp
->num_allow
= (*loc
)->num_allow
) > 0)
1487 * Copy allow rules...
1490 if ((temp
->allow
= calloc(temp
->num_allow
, sizeof(cupsd_authmask_t
))) == NULL
)
1492 cupsdLogMessage(CUPSD_LOG_ERROR
,
1493 "cupsdCopyLocation: Unable to allocate memory for %d allow rules: %s",
1494 temp
->num_allow
, strerror(errno
));
1495 cupsdDeleteLocation(temp
);
1499 for (i
= 0; i
< temp
->num_allow
; i
++)
1500 switch (temp
->allow
[i
].type
= (*loc
)->allow
[i
].type
)
1503 temp
->allow
[i
].mask
.name
.length
= (*loc
)->allow
[i
].mask
.name
.length
;
1504 temp
->allow
[i
].mask
.name
.name
= strdup((*loc
)->allow
[i
].mask
.name
.name
);
1506 if (temp
->allow
[i
].mask
.name
.name
== NULL
)
1508 cupsdLogMessage(CUPSD_LOG_ERROR
,
1509 "cupsdCopyLocation: Unable to copy allow name \"%s\": %s",
1510 (*loc
)->allow
[i
].mask
.name
.name
, strerror(errno
));
1511 cupsdDeleteLocation(temp
);
1516 memcpy(&(temp
->allow
[i
].mask
.ip
), &((*loc
)->allow
[i
].mask
.ip
),
1517 sizeof(cupsd_ipmask_t
));
1522 if ((temp
->num_deny
= (*loc
)->num_deny
) > 0)
1525 * Copy deny rules...
1528 if ((temp
->deny
= calloc(temp
->num_deny
, sizeof(cupsd_authmask_t
))) == NULL
)
1530 cupsdLogMessage(CUPSD_LOG_ERROR
,
1531 "cupsdCopyLocation: Unable to allocate memory for %d deny rules: %s",
1532 temp
->num_deny
, strerror(errno
));
1533 cupsdDeleteLocation(temp
);
1537 for (i
= 0; i
< temp
->num_deny
; i
++)
1538 switch (temp
->deny
[i
].type
= (*loc
)->deny
[i
].type
)
1541 temp
->deny
[i
].mask
.name
.length
= (*loc
)->deny
[i
].mask
.name
.length
;
1542 temp
->deny
[i
].mask
.name
.name
= strdup((*loc
)->deny
[i
].mask
.name
.name
);
1544 if (temp
->deny
[i
].mask
.name
.name
== NULL
)
1546 cupsdLogMessage(CUPSD_LOG_ERROR
,
1547 "cupsdCopyLocation: Unable to copy deny name \"%s\": %s",
1548 (*loc
)->deny
[i
].mask
.name
.name
, strerror(errno
));
1549 cupsdDeleteLocation(temp
);
1554 memcpy(&(temp
->deny
[i
].mask
.ip
), &((*loc
)->deny
[i
].mask
.ip
),
1555 sizeof(cupsd_ipmask_t
));
1565 * 'cupsdDeleteAllLocations()' - Free all memory used for location authorization.
1569 cupsdDeleteAllLocations(void)
1571 cupsd_location_t
*loc
; /* Current location */
1575 * Free all of the allow/deny records first...
1578 for (loc
= (cupsd_location_t
*)cupsArrayFirst(Locations
);
1580 loc
= (cupsd_location_t
*)cupsArrayNext(Locations
))
1581 cupsdDeleteLocation(loc
);
1584 * Then free the location array...
1587 cupsArrayDelete(Locations
);
1593 * 'cupsdDeleteLocation()' - Free all memory used by a location.
1597 cupsdDeleteLocation(
1598 cupsd_location_t
*loc
) /* I - Location to delete */
1600 int i
; /* Looping var */
1601 cupsd_authmask_t
*mask
; /* Current mask */
1604 cupsArrayRemove(Locations
, loc
);
1606 for (i
= loc
->num_names
- 1; i
>= 0; i
--)
1607 free(loc
->names
[i
]);
1609 if (loc
->num_names
> 0)
1612 for (i
= loc
->num_allow
, mask
= loc
->allow
; i
> 0; i
--, mask
++)
1613 if (mask
->type
== AUTH_NAME
|| mask
->type
== AUTH_INTERFACE
)
1614 free(mask
->mask
.name
.name
);
1616 if (loc
->num_allow
> 0)
1619 for (i
= loc
->num_deny
, mask
= loc
->deny
; i
> 0; i
--, mask
++)
1620 if (mask
->type
== AUTH_NAME
|| mask
->type
== AUTH_INTERFACE
)
1621 free(mask
->mask
.name
.name
);
1623 if (loc
->num_deny
> 0)
1626 free(loc
->location
);
1632 * 'cupsdDenyHost()' - Add a host name that is not allowed to access the
1637 cupsdDenyHost(cupsd_location_t
*loc
, /* I - Location to add to */
1638 char *name
) /* I - Name of host or domain to add */
1640 cupsd_authmask_t
*temp
; /* New host/domain mask */
1641 char ifname
[32], /* Interface name */
1642 *ifptr
; /* Pointer to end of name */
1645 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdDenyHost(loc=%p(%s), name=\"%s\")",
1646 loc
, loc
->location
? loc
->location
: "nil", name
);
1648 if ((temp
= add_deny(loc
)) == NULL
)
1651 if (!strcasecmp(name
, "@LOCAL"))
1654 * Deny *interface*...
1657 temp
->type
= AUTH_INTERFACE
;
1658 temp
->mask
.name
.name
= strdup("*");
1659 temp
->mask
.name
.length
= 1;
1661 else if (!strncasecmp(name
, "@IF(", 4))
1664 * Deny *interface*...
1667 strlcpy(ifname
, name
+ 4, sizeof(ifname
));
1669 ifptr
= ifname
+ strlen(ifname
);
1671 if (ifptr
[-1] == ')')
1677 temp
->type
= AUTH_INTERFACE
;
1678 temp
->mask
.name
.name
= strdup(ifname
);
1679 temp
->mask
.name
.length
= ifptr
- ifname
;
1687 temp
->type
= AUTH_NAME
;
1688 temp
->mask
.name
.name
= strdup(name
);
1689 temp
->mask
.name
.length
= strlen(name
);
1695 * 'cupsdDenyIP()' - Add an IP address or network that is not allowed to
1696 * access the location.
1700 cupsdDenyIP(cupsd_location_t
*loc
, /* I - Location to add to */
1701 unsigned address
[4],/* I - IP address to add */
1702 unsigned netmask
[4])/* I - Netmask of address */
1704 cupsd_authmask_t
*temp
; /* New host/domain mask */
1707 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1708 "cupsdDenyIP(loc=%p(%s), address=%x:%x:%x:%x, netmask=%x:%x:%x:%x)",
1709 loc
, loc
->location
? loc
->location
: "nil",
1710 address
[0], address
[1], address
[2], address
[3],
1711 netmask
[0], netmask
[1], netmask
[2], netmask
[3]);
1713 if ((temp
= add_deny(loc
)) == NULL
)
1716 temp
->type
= AUTH_IP
;
1717 memcpy(temp
->mask
.ip
.address
, address
, sizeof(temp
->mask
.ip
.address
));
1718 memcpy(temp
->mask
.ip
.netmask
, netmask
, sizeof(temp
->mask
.ip
.netmask
));
1723 * 'cupsdFindBest()' - Find the location entry that best matches the resource.
1726 cupsd_location_t
* /* O - Location that matches */
1727 cupsdFindBest(const char *path
, /* I - Resource path */
1728 http_state_t state
) /* I - HTTP state/request */
1730 char uri
[HTTP_MAX_URI
],
1731 /* URI in request... */
1732 *uriptr
; /* Pointer into URI */
1733 cupsd_location_t
*loc
, /* Current location */
1734 *best
; /* Best match for location so far */
1735 int bestlen
; /* Length of best match */
1736 int limit
; /* Limit field */
1737 static const int limits
[] = /* Map http_status_t to AUTH_LIMIT_xyz */
1757 * First copy the connection URI to a local string so we have drop
1758 * any .ppd extension from the pathname in /printers or /classes
1762 strlcpy(uri
, path
, sizeof(uri
));
1764 if (!strncmp(uri
, "/printers/", 10) ||
1765 !strncmp(uri
, "/classes/", 9))
1768 * Check if the URI has .ppd on the end...
1771 uriptr
= uri
+ strlen(uri
) - 4; /* len > 4 if we get here... */
1773 if (!strcmp(uriptr
, ".ppd"))
1777 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindBest: uri = \"%s\"...", uri
);
1780 * Loop through the list of locations to find a match...
1783 limit
= limits
[state
];
1787 for (loc
= (cupsd_location_t
*)cupsArrayFirst(Locations
);
1789 loc
= (cupsd_location_t
*)cupsArrayNext(Locations
))
1791 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindBest: Location %s Limit %x",
1792 loc
->location
? loc
->location
: "nil", loc
->limit
);
1794 if (!strncmp(uri
, "/printers/", 10) || !strncmp(uri
, "/classes/", 9))
1797 * Use case-insensitive comparison for queue names...
1800 if (loc
->length
> bestlen
&& loc
->location
&&
1801 !strncasecmp(uri
, loc
->location
, loc
->length
) &&
1802 loc
->location
[0] == '/' &&
1803 (limit
& loc
->limit
) != 0)
1806 bestlen
= loc
->length
;
1812 * Use case-sensitive comparison for other URIs...
1815 if (loc
->length
> bestlen
&& loc
->location
&&
1816 !strncmp(uri
, loc
->location
, loc
->length
) &&
1817 loc
->location
[0] == '/' &&
1818 (limit
& loc
->limit
) != 0)
1821 bestlen
= loc
->length
;
1827 * Return the match, if any...
1830 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindBest: best = %s",
1831 best
? best
->location
: "NONE");
1838 * 'cupsdFindLocation()' - Find the named location.
1841 cupsd_location_t
* /* O - Location that matches */
1842 cupsdFindLocation(const char *location
) /* I - Connection */
1844 cupsd_location_t key
; /* Search key */
1847 key
.location
= (char *)location
;
1849 return ((cupsd_location_t
*)cupsArrayFind(Locations
, &key
));
1854 * 'cupsdIsAuthorized()' - Check to see if the user is authorized...
1857 http_status_t
/* O - HTTP_OK if authorized or error code */
1858 cupsdIsAuthorized(cupsd_client_t
*con
, /* I - Connection */
1859 const char *owner
)/* I - Owner of object */
1861 int i
, j
, /* Looping vars */
1862 auth
, /* Authorization status */
1863 type
; /* Type of authentication */
1864 unsigned address
[4]; /* Authorization address */
1865 cupsd_location_t
*best
; /* Best match for location so far */
1866 int hostlen
; /* Length of hostname */
1867 char username
[256], /* Username to authorize */
1868 ownername
[256], /* Owner name to authorize */
1869 *ptr
; /* Pointer into username */
1870 struct passwd
*pw
; /* User password data */
1871 static const char * const levels
[] = /* Auth levels */
1877 static const char * const types
[] = /* Auth types */
1887 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1888 "cupsdIsAuthorized: con->uri=\"%s\", con->best=%p(%s)",
1889 con
->uri
, con
->best
, con
->best
? con
->best
->location
?
1890 con
->best
->location
: "(null)" : "");
1892 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1893 "cupsdIsAuthorized: owner=\"%s\"", owner
);
1896 * If there is no "best" authentication rule for this request, then
1897 * access is allowed from the local system and denied from other
1903 if (!strcmp(con
->http
.hostname
, "localhost") ||
1904 !strcmp(con
->http
.hostname
, ServerName
))
1907 return (HTTP_FORBIDDEN
);
1912 if ((type
= best
->type
) == AUTH_DEFAULT
)
1913 type
= DefaultAuthType
;
1915 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
1916 "cupsdIsAuthorized: level=AUTH_%s, type=%s, "
1917 "satisfy=AUTH_SATISFY_%s, num_names=%d",
1918 levels
[best
->level
], types
[type
],
1919 best
->satisfy
? "ANY" : "ALL", best
->num_names
);
1921 if (best
->limit
== AUTH_LIMIT_IPP
)
1922 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdIsAuthorized: op=%x(%s)",
1923 best
->op
, ippOpString(best
->op
));
1926 * Check host/ip-based accesses...
1930 if (con
->http
.hostaddr
->addr
.sa_family
== AF_INET6
)
1933 * Copy IPv6 address...
1936 address
[0] = ntohl(con
->http
.hostaddr
->ipv6
.sin6_addr
.s6_addr32
[0]);
1937 address
[1] = ntohl(con
->http
.hostaddr
->ipv6
.sin6_addr
.s6_addr32
[1]);
1938 address
[2] = ntohl(con
->http
.hostaddr
->ipv6
.sin6_addr
.s6_addr32
[2]);
1939 address
[3] = ntohl(con
->http
.hostaddr
->ipv6
.sin6_addr
.s6_addr32
[3]);
1942 #endif /* AF_INET6 */
1943 if (con
->http
.hostaddr
->addr
.sa_family
== AF_INET
)
1946 * Copy IPv4 address...
1952 address
[3] = ntohl(con
->http
.hostaddr
->ipv4
.sin_addr
.s_addr
);
1955 memset(address
, 0, sizeof(address
));
1957 hostlen
= strlen(con
->http
.hostname
);
1959 auth
= cupsdCheckAccess(address
, con
->http
.hostname
, hostlen
, best
)
1960 ? AUTH_ALLOW
: AUTH_DENY
;
1962 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdIsAuthorized: auth=AUTH_%s...",
1963 auth
? "DENY" : "ALLOW");
1965 if (auth
== AUTH_DENY
&& best
->satisfy
== AUTH_SATISFY_ALL
)
1966 return (HTTP_FORBIDDEN
);
1970 * See if encryption is required...
1973 if ((best
->encryption
>= HTTP_ENCRYPT_REQUIRED
&& !con
->http
.tls
&&
1974 strcasecmp(con
->http
.hostname
, "localhost") &&
1975 best
->satisfy
== AUTH_SATISFY_ALL
) &&
1976 !(type
== AUTH_NEGOTIATE
||
1977 (type
== AUTH_NONE
&& DefaultAuthType
== AUTH_NEGOTIATE
)))
1979 cupsdLogMessage(CUPSD_LOG_DEBUG
,
1980 "cupsdIsAuthorized: Need upgrade to TLS...");
1981 return (HTTP_UPGRADE_REQUIRED
);
1983 #endif /* HAVE_SSL */
1986 * Now see what access level is required...
1989 if (best
->level
== AUTH_ANON
|| /* Anonymous access - allow it */
1990 (type
== AUTH_NONE
&& best
->num_names
== 0))
1993 if (!con
->username
[0] && type
== AUTH_NONE
&&
1994 best
->limit
== AUTH_LIMIT_IPP
)
1997 * Check for unauthenticated username...
2000 ipp_attribute_t
*attr
; /* requesting-user-name attribute */
2003 attr
= ippFindAttribute(con
->request
, "requesting-user-name", IPP_TAG_NAME
);
2006 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2007 "cupsdIsAuthorized: requesting-user-name=\"%s\"",
2008 attr
->values
[0].string
.text
);
2009 strlcpy(username
, attr
->values
[0].string
.text
, sizeof(username
));
2011 else if (best
->satisfy
== AUTH_SATISFY_ALL
|| auth
== AUTH_DENY
)
2012 return (HTTP_UNAUTHORIZED
); /* Non-anonymous needs user/pass */
2014 return (HTTP_OK
); /* unless overridden with Satisfy */
2018 cupsdLogMessage(CUPSD_LOG_DEBUG
, "cupsdIsAuthorized: username=\"%s\"",
2021 #ifdef HAVE_AUTHORIZATION_H
2022 if (!con
->username
[0] && !con
->authref
)
2024 if (!con
->username
[0])
2025 #endif /* HAVE_AUTHORIZATION_H */
2027 if (best
->satisfy
== AUTH_SATISFY_ALL
|| auth
== AUTH_DENY
)
2028 return (HTTP_UNAUTHORIZED
); /* Non-anonymous needs user/pass */
2030 return (HTTP_OK
); /* unless overridden with Satisfy */
2033 if (con
->type
!= type
&& type
!= AUTH_NONE
&&
2034 (con
->type
!= AUTH_BASIC
|| type
!= AUTH_BASICDIGEST
))
2036 cupsdLogMessage(CUPSD_LOG_ERROR
, "Authorized using %s, expected %s!",
2037 types
[con
->type
], types
[type
]);
2039 return (HTTP_UNAUTHORIZED
);
2042 strlcpy(username
, con
->username
, sizeof(username
));
2046 * OK, got a username. See if we need normal user access, or group
2047 * access... (root always matches)
2050 if (!strcmp(username
, "root"))
2054 * Strip any @domain or @KDC from the username and owner...
2057 if ((ptr
= strchr(username
, '@')) != NULL
)
2062 strlcpy(ownername
, owner
, sizeof(ownername
));
2064 if ((ptr
= strchr(ownername
, '@')) != NULL
)
2068 ownername
[0] = '\0';
2071 * Get the user info...
2076 pw
= getpwnam(username
);
2082 if (best
->level
== AUTH_USER
)
2085 * If there are no names associated with this location, then
2086 * any valid user is OK...
2089 if (best
->num_names
== 0)
2093 * Otherwise check the user list and return OK if this user is
2097 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2098 "cupsdIsAuthorized: Checking user membership...");
2100 #ifdef HAVE_AUTHORIZATION_H
2102 * If an authorization reference was supplied it must match a right name...
2107 for (i
= 0; i
< best
->num_names
; i
++)
2109 if (!strncasecmp(best
->names
[i
], "@AUTHKEY(", 9) &&
2110 check_authref(con
, best
->names
[i
] + 9))
2112 else if (!strcasecmp(best
->names
[i
], "@SYSTEM") &&
2113 SystemGroupAuthKey
&&
2114 check_authref(con
, SystemGroupAuthKey
))
2118 return (HTTP_UNAUTHORIZED
);
2120 #endif /* HAVE_AUTHORIZATION_H */
2122 for (i
= 0; i
< best
->num_names
; i
++)
2124 if (!strcasecmp(best
->names
[i
], "@OWNER") && owner
&&
2125 !strcasecmp(username
, ownername
))
2127 else if (!strcasecmp(best
->names
[i
], "@SYSTEM"))
2129 for (j
= 0; j
< NumSystemGroups
; j
++)
2130 if (cupsdCheckGroup(username
, pw
, SystemGroups
[j
]))
2133 else if (best
->names
[i
][0] == '@')
2135 if (cupsdCheckGroup(username
, pw
, best
->names
[i
] + 1))
2138 else if (!strcasecmp(username
, best
->names
[i
]))
2142 return (HTTP_UNAUTHORIZED
);
2146 * Check to see if this user is in any of the named groups...
2149 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2150 "cupsdIsAuthorized: Checking group membership...");
2153 * Check to see if this user is in any of the named groups...
2156 for (i
= 0; i
< best
->num_names
; i
++)
2158 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2159 "cupsdIsAuthorized: Checking group \"%s\" membership...",
2162 if (!strcasecmp(best
->names
[i
], "@SYSTEM"))
2164 for (j
= 0; j
< NumSystemGroups
; j
++)
2165 if (cupsdCheckGroup(username
, pw
, SystemGroups
[j
]))
2168 else if (cupsdCheckGroup(username
, pw
, best
->names
[i
]))
2173 * The user isn't part of the specified group, so deny access...
2176 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2177 "cupsdIsAuthorized: User not in group(s)!");
2179 return (HTTP_UNAUTHORIZED
);
2184 * 'add_allow()' - Add an allow mask to the location.
2187 static cupsd_authmask_t
* /* O - New mask record */
2188 add_allow(cupsd_location_t
*loc
) /* I - Location to add to */
2190 cupsd_authmask_t
*temp
; /* New mask record */
2201 * Try to allocate memory for the record...
2204 if (loc
->num_allow
== 0)
2205 temp
= malloc(sizeof(cupsd_authmask_t
));
2207 temp
= realloc(loc
->allow
, sizeof(cupsd_authmask_t
) * (loc
->num_allow
+ 1));
2213 temp
+= loc
->num_allow
;
2217 * Clear the mask record and return...
2220 memset(temp
, 0, sizeof(cupsd_authmask_t
));
2226 * 'add_deny()' - Add a deny mask to the location.
2229 static cupsd_authmask_t
* /* O - New mask record */
2230 add_deny(cupsd_location_t
*loc
) /* I - Location to add to */
2232 cupsd_authmask_t
*temp
; /* New mask record */
2243 * Try to allocate memory for the record...
2246 if (loc
->num_deny
== 0)
2247 temp
= malloc(sizeof(cupsd_authmask_t
));
2249 temp
= realloc(loc
->deny
, sizeof(cupsd_authmask_t
) * (loc
->num_deny
+ 1));
2255 temp
+= loc
->num_deny
;
2259 * Clear the mask record and return...
2262 memset(temp
, 0, sizeof(cupsd_authmask_t
));
2267 #ifdef HAVE_AUTHORIZATION_H
2269 * 'check_authref()' - Check if an authorization services reference has the
2273 static int /* O - 1 if right is valid, 0 otherwise */
2274 check_authref(cupsd_client_t
*con
, /* I - Connection */
2275 const char *right
) /* I - Right name */
2277 OSStatus status
; /* OS Status */
2278 AuthorizationItem authright
; /* Authorization right */
2279 AuthorizationRights authrights
; /* Authorization rights */
2280 AuthorizationFlags authflags
; /* Authorization flags */
2284 * Check to see if the user is allowed to perform the task...
2290 authright
.name
= right
;
2291 authright
.valueLength
= 0;
2292 authright
.value
= NULL
;
2293 authright
.flags
= 0;
2295 authrights
.count
= 1;
2296 authrights
.items
= &authright
;
2298 authflags
= kAuthorizationFlagDefaults
|
2299 kAuthorizationFlagExtendRights
;
2301 if ((status
= AuthorizationCopyRights(con
->authref
, &authrights
,
2302 kAuthorizationEmptyEnvironment
,
2303 authflags
, NULL
)) != 0)
2305 cupsdLogMessage(CUPSD_LOG_ERROR
,
2306 "AuthorizationCopyRights(\"%s\") returned %d (%s)",
2307 authright
.name
, (int)status
, cssmErrorString(status
));
2311 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2312 "AuthorizationCopyRights(\"%s\") succeeded!",
2317 #endif /* HAVE_AUTHORIZATION_H */
2321 * 'compare_locations()' - Compare two locations.
2324 static int /* O - Result of comparison */
2325 compare_locations(cupsd_location_t
*a
, /* I - First location */
2326 cupsd_location_t
*b
) /* I - Second location */
2328 return (strcmp(b
->location
, a
->location
));
2332 #if !HAVE_LIBPAM && !defined(HAVE_USERSEC_H)
2334 * 'cups_crypt()' - Encrypt the password using the DES or MD5 algorithms,
2338 static char * /* O - Encrypted password */
2339 cups_crypt(const char *pw
, /* I - Password string */
2340 const char *salt
) /* I - Salt (key) string */
2342 if (!strncmp(salt
, "$1$", 3))
2345 * Use MD5 passwords without the benefit of PAM; this is for
2346 * Slackware Linux, and the algorithm was taken from the
2347 * old shadow-19990827/lib/md5crypt.c source code... :(
2350 int i
; /* Looping var */
2351 unsigned long n
; /* Output number */
2352 int pwlen
; /* Length of password string */
2353 const char *salt_end
; /* End of "salt" data for MD5 */
2354 char *ptr
; /* Pointer into result string */
2355 _cups_md5_state_t state
; /* Primary MD5 state info */
2356 _cups_md5_state_t state2
; /* Secondary MD5 state info */
2357 unsigned char digest
[16]; /* MD5 digest result */
2358 static char result
[120]; /* Final password string */
2362 * Get the salt data between dollar signs, e.g. $1$saltdata$md5.
2363 * Get a maximum of 8 characters of salt data after $1$...
2366 for (salt_end
= salt
+ 3; *salt_end
&& (salt_end
- salt
) < 11; salt_end
++)
2367 if (*salt_end
== '$')
2371 * Compute the MD5 sum we need...
2376 _cupsMD5Init(&state
);
2377 _cupsMD5Append(&state
, (unsigned char *)pw
, pwlen
);
2378 _cupsMD5Append(&state
, (unsigned char *)salt
, salt_end
- salt
);
2380 _cupsMD5Init(&state2
);
2381 _cupsMD5Append(&state2
, (unsigned char *)pw
, pwlen
);
2382 _cupsMD5Append(&state2
, (unsigned char *)salt
+ 3, salt_end
- salt
- 3);
2383 _cupsMD5Append(&state2
, (unsigned char *)pw
, pwlen
);
2384 _cupsMD5Finish(&state2
, digest
);
2386 for (i
= pwlen
; i
> 0; i
-= 16)
2387 _cupsMD5Append(&state
, digest
, i
> 16 ? 16 : i
);
2389 for (i
= pwlen
; i
> 0; i
>>= 1)
2390 _cupsMD5Append(&state
, (unsigned char *)((i
& 1) ? "" : pw
), 1);
2392 _cupsMD5Finish(&state
, digest
);
2394 for (i
= 0; i
< 1000; i
++)
2396 _cupsMD5Init(&state
);
2399 _cupsMD5Append(&state
, (unsigned char *)pw
, pwlen
);
2401 _cupsMD5Append(&state
, digest
, 16);
2404 _cupsMD5Append(&state
, (unsigned char *)salt
+ 3, salt_end
- salt
- 3);
2407 _cupsMD5Append(&state
, (unsigned char *)pw
, pwlen
);
2410 _cupsMD5Append(&state
, digest
, 16);
2412 _cupsMD5Append(&state
, (unsigned char *)pw
, pwlen
);
2414 _cupsMD5Finish(&state
, digest
);
2418 * Copy the final sum to the result string and return...
2421 memcpy(result
, salt
, salt_end
- salt
);
2422 ptr
= result
+ (salt_end
- salt
);
2425 for (i
= 0; i
< 5; i
++, ptr
+= 4)
2427 n
= (((digest
[i
] << 8) | digest
[i
+ 6]) << 8);
2430 n
|= digest
[i
+ 12];
2437 to64(ptr
, digest
[11], 2);
2446 * Use the standard crypt() function...
2449 return (crypt(pw
, salt
));
2452 #endif /* !HAVE_LIBPAM && !HAVE_USERSEC_H */
2457 * 'get_gss_creds()' - Obtain GSS credentials.
2460 static gss_cred_id_t
/* O - Server credentials */
2461 get_gss_creds(const char *service_name
) /* I - Service name */
2463 OM_uint32 major_status
, /* Major status code */
2464 minor_status
; /* Minor status code */
2465 gss_name_t server_name
; /* Server name */
2466 gss_cred_id_t server_creds
; /* Server credentials */
2467 gss_buffer_desc token
= GSS_C_EMPTY_BUFFER
;
2468 /* Service name token */
2469 char buf
[1024], /* Service name buffer */
2470 fqdn
[HTTP_MAX_URI
]; /* Hostname of server */
2473 snprintf(buf
, sizeof(buf
), "%s@%s", service_name
,
2474 httpGetHostname(NULL
, fqdn
, sizeof(fqdn
)));
2477 token
.length
= strlen(buf
);
2478 server_name
= GSS_C_NO_NAME
;
2479 major_status
= gss_import_name(&minor_status
, &token
,
2480 GSS_C_NT_HOSTBASED_SERVICE
,
2483 memset(&token
, 0, sizeof(token
));
2485 if (GSS_ERROR(major_status
))
2487 cupsdLogGSSMessage(CUPSD_LOG_WARN
, major_status
, minor_status
,
2488 "gss_import_name() failed");
2492 major_status
= gss_display_name(&minor_status
, server_name
, &token
, NULL
);
2494 if (GSS_ERROR(major_status
))
2496 cupsdLogGSSMessage(CUPSD_LOG_WARN
, major_status
, minor_status
,
2497 "gss_display_name() failed");
2501 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2502 "get_gss_creds: Attempting to acquire credentials for %s...",
2503 (char *)token
.value
);
2505 server_creds
= GSS_C_NO_CREDENTIAL
;
2506 major_status
= gss_acquire_cred(&minor_status
, server_name
, GSS_C_INDEFINITE
,
2507 GSS_C_NO_OID_SET
, GSS_C_ACCEPT
,
2508 &server_creds
, NULL
, NULL
);
2509 if (GSS_ERROR(major_status
))
2511 cupsdLogGSSMessage(CUPSD_LOG_WARN
, major_status
, minor_status
,
2512 "gss_acquire_cred() failed");
2513 gss_release_name(&minor_status
, &server_name
);
2514 gss_release_buffer(&minor_status
, &token
);
2518 cupsdLogMessage(CUPSD_LOG_DEBUG
,
2519 "get_gss_creds: Credentials acquired successfully for %s.",
2520 (char *)token
.value
);
2522 gss_release_name(&minor_status
, &server_name
);
2523 gss_release_buffer(&minor_status
, &token
);
2525 return (server_creds
);
2527 #endif /* HAVE_GSSAPI */
2531 * 'get_md5_password()' - Get an MD5 password.
2534 static char * /* O - MD5 password string */
2535 get_md5_password(const char *username
, /* I - Username */
2536 const char *group
, /* I - Group */
2537 char passwd
[33]) /* O - MD5 password string */
2539 cups_file_t
*fp
; /* passwd.md5 file */
2540 char filename
[1024], /* passwd.md5 filename */
2541 line
[256], /* Line from file */
2542 tempuser
[33], /* User from file */
2543 tempgroup
[33]; /* Group from file */
2546 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
2547 "get_md5_password(username=\"%s\", group=\"%s\", passwd=%p)",
2548 username
, group
? group
: "(null)", passwd
);
2550 snprintf(filename
, sizeof(filename
), "%s/passwd.md5", ServerRoot
);
2551 if ((fp
= cupsFileOpen(filename
, "r")) == NULL
)
2553 if (errno
!= ENOENT
)
2554 cupsdLogMessage(CUPSD_LOG_ERROR
, "Unable to open %s - %s", filename
,
2560 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
2562 if (sscanf(line
, "%32[^:]:%32[^:]:%32s", tempuser
, tempgroup
, passwd
) != 3)
2564 cupsdLogMessage(CUPSD_LOG_ERROR
, "Bad MD5 password line: %s", line
);
2568 if (!strcmp(username
, tempuser
) &&
2569 (group
== NULL
|| !strcmp(group
, tempgroup
)))
2572 * Found the password entry!
2575 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "Found MD5 user %s, group %s...",
2576 username
, tempgroup
);
2584 * Didn't find a password entry - return NULL!
2594 * 'pam_func()' - PAM conversation function.
2597 static int /* O - Success or failure */
2599 int num_msg
, /* I - Number of messages */
2600 const struct pam_message
**msg
, /* I - Messages */
2601 struct pam_response
**resp
, /* O - Responses */
2603 /* I - Pointer to connection */
2605 int i
; /* Looping var */
2606 struct pam_response
*replies
; /* Replies */
2607 cupsd_authdata_t
*data
; /* Pointer to auth data */
2611 * Allocate memory for the responses...
2614 if ((replies
= malloc(sizeof(struct pam_response
) * num_msg
)) == NULL
)
2615 return (PAM_CONV_ERR
);
2618 * Answer all of the messages...
2621 DEBUG_printf(("pam_func: appdata_ptr = %p\n", appdata_ptr
));
2625 * Apparently some versions of HP-UX 11 have a broken pam_unix security
2626 * module. This is a workaround...
2632 data
= (cupsd_authdata_t
*)appdata_ptr
;
2635 for (i
= 0; i
< num_msg
; i
++)
2637 DEBUG_printf(("pam_func: Message = \"%s\"\n", msg
[i
]->msg
));
2639 switch (msg
[i
]->msg_style
)
2641 case PAM_PROMPT_ECHO_ON
:
2642 DEBUG_printf(("pam_func: PAM_PROMPT_ECHO_ON, returning \"%s\"...\n",
2644 replies
[i
].resp_retcode
= PAM_SUCCESS
;
2645 replies
[i
].resp
= strdup(data
->username
);
2648 case PAM_PROMPT_ECHO_OFF
:
2649 DEBUG_printf(("pam_func: PAM_PROMPT_ECHO_OFF, returning \"%s\"...\n",
2651 replies
[i
].resp_retcode
= PAM_SUCCESS
;
2652 replies
[i
].resp
= strdup(data
->password
);
2656 DEBUG_puts("pam_func: PAM_TEXT_INFO...");
2657 replies
[i
].resp_retcode
= PAM_SUCCESS
;
2658 replies
[i
].resp
= NULL
;
2662 DEBUG_puts("pam_func: PAM_ERROR_MSG...");
2663 replies
[i
].resp_retcode
= PAM_SUCCESS
;
2664 replies
[i
].resp
= NULL
;
2668 DEBUG_printf(("pam_func: Unknown PAM message %d...\n",
2669 msg
[i
]->msg_style
));
2671 return (PAM_CONV_ERR
);
2676 * Return the responses back to PAM...
2681 return (PAM_SUCCESS
);
2683 #elif !defined(HAVE_USERSEC_H)
2687 * 'to64()' - Base64-encode an integer value...
2691 to64(char *s
, /* O - Output string */
2692 unsigned long v
, /* I - Value to encode */
2693 int n
) /* I - Number of digits */
2695 const char *itoa64
= "./0123456789"
2696 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
2697 "abcdefghijklmnopqrstuvwxyz";
2700 for (; n
> 0; n
--, v
>>= 6)
2701 *s
++ = itoa64
[v
& 0x3f];
2703 #endif /* HAVE_LIBPAM */
2707 * End of "$Id: auth.c 6947 2007-09-12 21:09:49Z mike $".