10Sstevel@tonic-gate /*
2*7934SMark.Phalan@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate
60Sstevel@tonic-gate
70Sstevel@tonic-gate /*
80Sstevel@tonic-gate * lib/krb5/os/kuserok.c
90Sstevel@tonic-gate *
100Sstevel@tonic-gate * Copyright 1990,1993 by the Massachusetts Institute of Technology.
110Sstevel@tonic-gate * All Rights Reserved.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * Export of this software from the United States of America may
140Sstevel@tonic-gate * require a specific license from the United States Government.
150Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
160Sstevel@tonic-gate * export to obtain such a license before exporting.
17*7934SMark.Phalan@Sun.COM *
180Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
190Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
200Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
210Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
220Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
230Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
240Sstevel@tonic-gate * to distribution of the software without specific, written prior
25*7934SMark.Phalan@Sun.COM * permission. Furthermore if you modify this software you must label
26*7934SMark.Phalan@Sun.COM * your software as modified software and not distribute it in such a
27*7934SMark.Phalan@Sun.COM * fashion that it might be confused with the original M.I.T. software.
28*7934SMark.Phalan@Sun.COM * M.I.T. makes no representations about the suitability of
290Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
300Sstevel@tonic-gate * or implied warranty.
31*7934SMark.Phalan@Sun.COM *
320Sstevel@tonic-gate *
330Sstevel@tonic-gate * krb5_kuserok()
340Sstevel@tonic-gate */
350Sstevel@tonic-gate
360Sstevel@tonic-gate #include "k5-int.h"
37*7934SMark.Phalan@Sun.COM #if !defined(_WIN32) /* Not yet for Windows */
380Sstevel@tonic-gate #include <stdio.h>
390Sstevel@tonic-gate #include <string.h>
400Sstevel@tonic-gate #include <stdlib.h>
410Sstevel@tonic-gate #include <pwd.h>
420Sstevel@tonic-gate #include <libintl.h>
430Sstevel@tonic-gate #include <gssapi/gssapi.h>
440Sstevel@tonic-gate #include <gssapi/gssapi_ext.h>
450Sstevel@tonic-gate #include <gssapi_krb5.h>
460Sstevel@tonic-gate #include <gssapiP_krb5.h>
470Sstevel@tonic-gate #include <syslog.h>
480Sstevel@tonic-gate
49*7934SMark.Phalan@Sun.COM #if defined(_AIX) && defined(_IBMR2)
50*7934SMark.Phalan@Sun.COM #include <sys/access.h>
51*7934SMark.Phalan@Sun.COM /* xlc has a bug with "const" */
52*7934SMark.Phalan@Sun.COM #define getpwnam(user) getpwnam((char *)user)
53*7934SMark.Phalan@Sun.COM #endif
54*7934SMark.Phalan@Sun.COM
55*7934SMark.Phalan@Sun.COM #define MAX_USERNAME 65
56*7934SMark.Phalan@Sun.COM #define CACHE_FILENAME_LEN 35
57*7934SMark.Phalan@Sun.COM
58*7934SMark.Phalan@Sun.COM #if defined(__APPLE__) && defined(__MACH__)
59*7934SMark.Phalan@Sun.COM #include <hfs/hfs_mount.h> /* XXX */
60*7934SMark.Phalan@Sun.COM #define FILE_OWNER_OK(UID) ((UID) == 0 || (UID) == UNKNOWNUID)
61*7934SMark.Phalan@Sun.COM #else
62*7934SMark.Phalan@Sun.COM #define FILE_OWNER_OK(UID) ((UID) == 0)
63*7934SMark.Phalan@Sun.COM #endif
64*7934SMark.Phalan@Sun.COM
65*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
660Sstevel@tonic-gate extern void
670Sstevel@tonic-gate gsscred_set_options();
680Sstevel@tonic-gate
690Sstevel@tonic-gate extern OM_uint32
700Sstevel@tonic-gate gsscred_name_to_unix_cred_ext();
710Sstevel@tonic-gate
720Sstevel@tonic-gate extern int
730Sstevel@tonic-gate safechown(const char *src, uid_t uid, gid_t gid, int mode);
740Sstevel@tonic-gate
75781Sgtb extern const char *error_message(long);
760Sstevel@tonic-gate
770Sstevel@tonic-gate
780Sstevel@tonic-gate krb5_data tgtname = {
790Sstevel@tonic-gate 0,
800Sstevel@tonic-gate KRB5_TGS_NAME_SIZE,
810Sstevel@tonic-gate KRB5_TGS_NAME
820Sstevel@tonic-gate };
830Sstevel@tonic-gate
84*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
850Sstevel@tonic-gate static krb5_error_code
krb5_move_ccache(krb5_context kcontext,krb5_principal client,struct passwd * pwd)860Sstevel@tonic-gate krb5_move_ccache(krb5_context kcontext, krb5_principal client,
870Sstevel@tonic-gate struct passwd *pwd)
880Sstevel@tonic-gate {
890Sstevel@tonic-gate char *name = 0;
900Sstevel@tonic-gate static char ccache_name_buf[CACHE_FILENAME_LEN];
910Sstevel@tonic-gate krb5_ccache ccache = NULL;
920Sstevel@tonic-gate krb5_error_code retval;
930Sstevel@tonic-gate
940Sstevel@tonic-gate name = getenv(KRB5_ENV_CCNAME);
950Sstevel@tonic-gate if (name == 0)
960Sstevel@tonic-gate /*
970Sstevel@tonic-gate * This means that there was no forwarding
980Sstevel@tonic-gate * of creds
990Sstevel@tonic-gate */
1000Sstevel@tonic-gate return (0);
1010Sstevel@tonic-gate else {
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate * creds have been forwarded and stored in
1040Sstevel@tonic-gate * KRB5_ENV_CCNAME and now we need to store it
1050Sstevel@tonic-gate * under uid
1060Sstevel@tonic-gate */
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate krb5_creds mcreds, save_v5creds;
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate memset(&mcreds, 0, sizeof (mcreds));
1110Sstevel@tonic-gate memset(&save_v5creds, 0, sizeof (save_v5creds));
1120Sstevel@tonic-gate
1130Sstevel@tonic-gate mcreds.client = client;
1140Sstevel@tonic-gate retval = krb5_build_principal_ext(kcontext, &mcreds.server,
1150Sstevel@tonic-gate krb5_princ_realm(kcontext, client)->length,
1160Sstevel@tonic-gate krb5_princ_realm(kcontext, client)->data,
1170Sstevel@tonic-gate tgtname.length, tgtname.data,
1180Sstevel@tonic-gate krb5_princ_realm(kcontext, client)->length,
1190Sstevel@tonic-gate krb5_princ_realm(kcontext, client)->data,
1200Sstevel@tonic-gate 0);
1210Sstevel@tonic-gate if (retval) {
1220Sstevel@tonic-gate syslog(LOG_ERR,
1230Sstevel@tonic-gate gettext("KRB5: %s while creating"
1240Sstevel@tonic-gate "V5 krbtgt principal "),
1250Sstevel@tonic-gate error_message(retval));
1260Sstevel@tonic-gate return (retval);
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate mcreds.ticket_flags = 0;
1300Sstevel@tonic-gate retval = krb5_cc_default(kcontext, &ccache);
1310Sstevel@tonic-gate if (retval) {
1320Sstevel@tonic-gate syslog(LOG_ERR,
1330Sstevel@tonic-gate gettext("KRB5: %s while getting "
1340Sstevel@tonic-gate "default cache "),
1350Sstevel@tonic-gate error_message(retval));
1360Sstevel@tonic-gate return (retval);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate retval = krb5_cc_retrieve_cred(kcontext, ccache,
1400Sstevel@tonic-gate 0,
1410Sstevel@tonic-gate &mcreds, &save_v5creds);
1420Sstevel@tonic-gate if (retval) {
1430Sstevel@tonic-gate syslog(LOG_ERR,
1440Sstevel@tonic-gate gettext("KRB5: %s while retrieving "
1450Sstevel@tonic-gate "cerdentials "),
1460Sstevel@tonic-gate error_message(retval));
1470Sstevel@tonic-gate return (retval);
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate * reset the env variable and recreate the
1510Sstevel@tonic-gate * cache using the default cache name
1520Sstevel@tonic-gate */
1530Sstevel@tonic-gate retval = krb5_cc_destroy(kcontext, ccache);
1540Sstevel@tonic-gate if (retval) {
1550Sstevel@tonic-gate syslog(LOG_ERR,
1560Sstevel@tonic-gate gettext("KRB5: %s while destroying cache "),
1570Sstevel@tonic-gate error_message(retval));
1580Sstevel@tonic-gate return (retval);
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate krb5_unsetenv(KRB5_ENV_CCNAME);
1610Sstevel@tonic-gate snprintf(ccache_name_buf,
1620Sstevel@tonic-gate CACHE_FILENAME_LEN,
1630Sstevel@tonic-gate "FILE:/tmp/krb5cc_%d", pwd->pw_uid);
1640Sstevel@tonic-gate krb5_setenv(KRB5_ENV_CCNAME, ccache_name_buf, 1);
1650Sstevel@tonic-gate retval = krb5_cc_resolve(kcontext, ccache_name_buf, &ccache);
1660Sstevel@tonic-gate if (retval) {
1670Sstevel@tonic-gate syslog(LOG_ERR,
1680Sstevel@tonic-gate gettext("KRB5: %s while resolving cache "),
1690Sstevel@tonic-gate error_message(retval));
1700Sstevel@tonic-gate return (retval);
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate retval = krb5_cc_initialize(kcontext, ccache, client);
1730Sstevel@tonic-gate if (retval) {
1740Sstevel@tonic-gate syslog(LOG_ERR,
1750Sstevel@tonic-gate gettext("KRB5: %s while initializing cache "),
1760Sstevel@tonic-gate error_message(retval));
1770Sstevel@tonic-gate return (retval);
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate retval = krb5_cc_store_cred(kcontext, ccache, &save_v5creds);
1800Sstevel@tonic-gate if (retval) {
1810Sstevel@tonic-gate syslog(LOG_ERR,
1820Sstevel@tonic-gate gettext("KRB5: %s while storing creds "),
1830Sstevel@tonic-gate error_message(retval));
1840Sstevel@tonic-gate return (retval);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate snprintf(ccache_name_buf,
1870Sstevel@tonic-gate CACHE_FILENAME_LEN,
1880Sstevel@tonic-gate "/tmp/krb5cc_%d", pwd->pw_uid);
1890Sstevel@tonic-gate if (safechown(ccache_name_buf, pwd->pw_uid,
1900Sstevel@tonic-gate pwd->pw_gid, -1) == -1) {
1910Sstevel@tonic-gate syslog(LOG_ERR,
1920Sstevel@tonic-gate gettext("KRB5: Can not change "
1930Sstevel@tonic-gate "ownership of cache file, "
1940Sstevel@tonic-gate "possible security breach\n"));
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate return (0);
1990Sstevel@tonic-gate }
2000Sstevel@tonic-gate
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate /*
203*7934SMark.Phalan@Sun.COM * Solaris Kerberos:
2040Sstevel@tonic-gate * krb5_gsscred: Given a kerberos principal try to find the corresponding
2050Sstevel@tonic-gate * local uid via the gss cred table. Return TRUE if the uid was found in the
2060Sstevel@tonic-gate * cred table, otherwise return FALSE.
2070Sstevel@tonic-gate */
2080Sstevel@tonic-gate static krb5_boolean
krb5_gsscred(krb5_principal principal,uid_t * uid)2090Sstevel@tonic-gate krb5_gsscred(krb5_principal principal, uid_t *uid)
2100Sstevel@tonic-gate {
2110Sstevel@tonic-gate OM_uint32 minor, major;
2120Sstevel@tonic-gate gss_name_t name;
2130Sstevel@tonic-gate gss_buffer_desc name_buf;
2140Sstevel@tonic-gate
2150Sstevel@tonic-gate name_buf.value = &principal;
2160Sstevel@tonic-gate name_buf.length = sizeof (principal);
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate /*
2190Sstevel@tonic-gate * Convert the kerb principal in to a gss name
2200Sstevel@tonic-gate */
2210Sstevel@tonic-gate major = gss_import_name(&minor, &name_buf,
2220Sstevel@tonic-gate (gss_OID)gss_nt_krb5_principal, &name);
2230Sstevel@tonic-gate
2240Sstevel@tonic-gate if (major != GSS_S_COMPLETE)
2250Sstevel@tonic-gate return (FALSE);
2260Sstevel@tonic-gate
2270Sstevel@tonic-gate gsscred_set_options();
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate /*
2300Sstevel@tonic-gate * Get the uid mapping from the gsscred table.
2310Sstevel@tonic-gate * (but set flag to not call back into this mech as we do krb5
2320Sstevel@tonic-gate * auth_to_local name mapping from this module).
2330Sstevel@tonic-gate */
2340Sstevel@tonic-gate major = gsscred_name_to_unix_cred_ext(name, (gss_OID)gss_mech_krb5,
2350Sstevel@tonic-gate uid, 0, 0, 0, 0);
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate (void) gss_release_name(&minor, &name);
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate if (major != GSS_S_COMPLETE)
2400Sstevel@tonic-gate return (FALSE);
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate return (TRUE);
2430Sstevel@tonic-gate }
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate /*
2460Sstevel@tonic-gate * Given a Kerberos principal "principal", and a local username "luser",
2470Sstevel@tonic-gate * determine whether user is authorized to login according to the
2480Sstevel@tonic-gate * authorization file ("~luser/.k5login" by default). Returns TRUE
2490Sstevel@tonic-gate * if authorized, FALSE if not authorized.
2500Sstevel@tonic-gate *
2510Sstevel@tonic-gate * If there is no account for "luser" on the local machine, returns
2520Sstevel@tonic-gate * FALSE. If there is no authorization file, and the given Kerberos
2530Sstevel@tonic-gate * name "server" translates to the same name as "luser" (using
2540Sstevel@tonic-gate * krb5_aname_to_lname()), returns TRUE. Otherwise, if the authorization file
2550Sstevel@tonic-gate * can't be accessed, returns FALSE. Otherwise, the file is read for
2560Sstevel@tonic-gate * a matching principal name, instance, and realm. If one is found,
2570Sstevel@tonic-gate * returns TRUE, if none is found, returns FALSE.
2580Sstevel@tonic-gate *
2590Sstevel@tonic-gate * The file entries are in the format produced by krb5_unparse_name(),
2600Sstevel@tonic-gate * one entry per line.
2610Sstevel@tonic-gate *
2620Sstevel@tonic-gate */
2630Sstevel@tonic-gate
264781Sgtb krb5_boolean KRB5_CALLCONV
krb5_kuserok(krb5_context context,krb5_principal principal,const char * luser)265781Sgtb krb5_kuserok(krb5_context context, krb5_principal principal, const char *luser)
2660Sstevel@tonic-gate {
2670Sstevel@tonic-gate struct stat sbuf;
2680Sstevel@tonic-gate struct passwd *pwd;
2690Sstevel@tonic-gate char pbuf[MAXPATHLEN];
2700Sstevel@tonic-gate krb5_boolean isok = FALSE;
2710Sstevel@tonic-gate FILE *fp;
2720Sstevel@tonic-gate char kuser[MAX_USERNAME];
2730Sstevel@tonic-gate char *princname;
2740Sstevel@tonic-gate char linebuf[BUFSIZ];
2750Sstevel@tonic-gate char *newline;
276*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
2770Sstevel@tonic-gate uid_t uid;
2780Sstevel@tonic-gate int gobble;
2790Sstevel@tonic-gate
2800Sstevel@tonic-gate /* no account => no access */
281781Sgtb char pwbuf[BUFSIZ];
282781Sgtb struct passwd pwx;
283*7934SMark.Phalan@Sun.COM if (k5_getpwnam_r(luser, &pwx, pwbuf, sizeof(pwbuf), &pwd) != 0)
2840Sstevel@tonic-gate return(FALSE);
2850Sstevel@tonic-gate (void) strncpy(pbuf, pwd->pw_dir, sizeof(pbuf) - 1);
2860Sstevel@tonic-gate pbuf[sizeof(pbuf) - 1] = '\0';
2870Sstevel@tonic-gate (void) strncat(pbuf, "/.k5login", sizeof(pbuf) - 1 - strlen(pbuf));
2880Sstevel@tonic-gate
2890Sstevel@tonic-gate if (access(pbuf, F_OK)) { /* not accessible */
2900Sstevel@tonic-gate /*
2910Sstevel@tonic-gate * if he's trying to log in as himself, and there is no .k5login file,
2920Sstevel@tonic-gate * let him. First, have krb5 check it's rules. If no success,
2930Sstevel@tonic-gate * search the gsscred table (the sequence here should be consistent
2940Sstevel@tonic-gate * with the uid mappings done for gssd).
2950Sstevel@tonic-gate */
2960Sstevel@tonic-gate if (!(krb5_aname_to_localname(context, principal,
2970Sstevel@tonic-gate sizeof(kuser), kuser))
2980Sstevel@tonic-gate && (strcmp(kuser, luser) == 0)) {
299*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
3000Sstevel@tonic-gate if (krb5_move_ccache(context, principal, pwd))
3010Sstevel@tonic-gate return (FALSE);
3020Sstevel@tonic-gate return(TRUE);
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate if (krb5_gsscred(principal, &uid)) {
3060Sstevel@tonic-gate #ifdef DEBUG
3070Sstevel@tonic-gate char *princname;
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate (void)krb5_unparse_name(context, principal, &princname);
3100Sstevel@tonic-gate syslog(LOG_DEBUG, "gsscred mapped %s to %d expecting %d (%s)\n",
3110Sstevel@tonic-gate princname, uid, pwd->pw_uid, luser);
3120Sstevel@tonic-gate free(princname);
3130Sstevel@tonic-gate #endif
3140Sstevel@tonic-gate if (uid == pwd->pw_uid) {
3150Sstevel@tonic-gate if (krb5_move_ccache(context, principal, pwd))
3160Sstevel@tonic-gate return (FALSE);
3170Sstevel@tonic-gate return (TRUE);
3181914Scasper }
3190Sstevel@tonic-gate }
3200Sstevel@tonic-gate
3210Sstevel@tonic-gate }
3220Sstevel@tonic-gate if (krb5_unparse_name(context, principal, &princname))
3230Sstevel@tonic-gate return(FALSE); /* no hope of matching */
3240Sstevel@tonic-gate
3250Sstevel@tonic-gate /* open ~/.k5login */
326*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
3271914Scasper if ((fp = fopen(pbuf, "rF")) == NULL) {
3280Sstevel@tonic-gate free(princname);
3290Sstevel@tonic-gate return(FALSE);
3300Sstevel@tonic-gate }
3310Sstevel@tonic-gate /*
3320Sstevel@tonic-gate * For security reasons, the .k5login file must be owned either by
3330Sstevel@tonic-gate * the user himself, or by root. Otherwise, don't grant access.
3340Sstevel@tonic-gate */
3350Sstevel@tonic-gate if (fstat(fileno(fp), &sbuf)) {
3360Sstevel@tonic-gate fclose(fp);
3370Sstevel@tonic-gate free(princname);
3380Sstevel@tonic-gate return(FALSE);
3390Sstevel@tonic-gate }
340*7934SMark.Phalan@Sun.COM if (sbuf.st_uid != pwd->pw_uid && !FILE_OWNER_OK(sbuf.st_uid)) {
3410Sstevel@tonic-gate fclose(fp);
3420Sstevel@tonic-gate free(princname);
3430Sstevel@tonic-gate return(FALSE);
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate /* check each line */
3470Sstevel@tonic-gate while (!isok && (fgets(linebuf, BUFSIZ, fp) != NULL)) {
3480Sstevel@tonic-gate /* null-terminate the input string */
3490Sstevel@tonic-gate linebuf[BUFSIZ-1] = '\0';
3500Sstevel@tonic-gate newline = NULL;
3510Sstevel@tonic-gate /* nuke the newline if it exists */
3520Sstevel@tonic-gate if ((newline = strchr(linebuf, '\n')))
3530Sstevel@tonic-gate *newline = '\0';
3540Sstevel@tonic-gate if (!strcmp(linebuf, princname)) {
3550Sstevel@tonic-gate isok = TRUE;
356*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
3570Sstevel@tonic-gate if (krb5_move_ccache(context, principal, pwd))
3580Sstevel@tonic-gate return (FALSE);
3590Sstevel@tonic-gate continue;
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate /* clean up the rest of the line if necessary */
3620Sstevel@tonic-gate if (!newline)
3630Sstevel@tonic-gate while (((gobble = getc(fp)) != EOF) && gobble != '\n');
3640Sstevel@tonic-gate }
3650Sstevel@tonic-gate free(princname);
3660Sstevel@tonic-gate fclose(fp);
3670Sstevel@tonic-gate return(isok);
3680Sstevel@tonic-gate }
3690Sstevel@tonic-gate
370*7934SMark.Phalan@Sun.COM /* Solaris Kerberos */
3710Sstevel@tonic-gate OM_uint32
krb5_gss_userok(OM_uint32 * minor,const gss_name_t pname,const char * user,int * user_ok)3725053Sgtb krb5_gss_userok(OM_uint32 *minor,
3730Sstevel@tonic-gate const gss_name_t pname,
3740Sstevel@tonic-gate const char *user,
3750Sstevel@tonic-gate int *user_ok)
3760Sstevel@tonic-gate {
3775053Sgtb krb5_context ctxt;
3785053Sgtb OM_uint32 kret;
3795053Sgtb
3800Sstevel@tonic-gate if (pname == NULL || user == NULL)
3810Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_READ);
3820Sstevel@tonic-gate
3830Sstevel@tonic-gate if (minor == NULL || user_ok == NULL)
3840Sstevel@tonic-gate return (GSS_S_CALL_INACCESSIBLE_WRITE);
3851914Scasper
3860Sstevel@tonic-gate *user_ok = 0;
3870Sstevel@tonic-gate
3885053Sgtb kret = krb5_gss_init_context(&ctxt);
3895053Sgtb if (kret) {
3905053Sgtb *minor = kret;
3915053Sgtb return (GSS_S_FAILURE);
3925053Sgtb }
3935053Sgtb
3940Sstevel@tonic-gate if (! kg_validate_name(pname)) {
3955053Sgtb *minor = (OM_uint32) G_VALIDATE_FAILED;
3965053Sgtb krb5_free_context(ctxt);
3975053Sgtb return (GSS_S_CALL_BAD_STRUCTURE|GSS_S_BAD_NAME);
3980Sstevel@tonic-gate }
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate if (krb5_kuserok(ctxt, (krb5_principal) pname, user)) {
4010Sstevel@tonic-gate *user_ok = 1;
4020Sstevel@tonic-gate }
4035053Sgtb
4045053Sgtb krb5_free_context(ctxt);
4050Sstevel@tonic-gate return (GSS_S_COMPLETE);
4060Sstevel@tonic-gate }
407*7934SMark.Phalan@Sun.COM
408*7934SMark.Phalan@Sun.COM #else /* _WIN32 */
409*7934SMark.Phalan@Sun.COM
410*7934SMark.Phalan@Sun.COM /*
411*7934SMark.Phalan@Sun.COM * If the given Kerberos name "server" translates to the same name as "luser"
412*7934SMark.Phalan@Sun.COM * (using * krb5_aname_to_lname()), returns TRUE.
413*7934SMark.Phalan@Sun.COM */
414*7934SMark.Phalan@Sun.COM krb5_boolean KRB5_CALLCONV
krb5_kuserok(context,principal,luser)415*7934SMark.Phalan@Sun.COM krb5_kuserok(context, principal, luser)
416*7934SMark.Phalan@Sun.COM krb5_context context;
417*7934SMark.Phalan@Sun.COM krb5_principal principal;
418*7934SMark.Phalan@Sun.COM const char *luser;
419*7934SMark.Phalan@Sun.COM {
420*7934SMark.Phalan@Sun.COM char kuser[50];
421*7934SMark.Phalan@Sun.COM
422*7934SMark.Phalan@Sun.COM if (krb5_aname_to_localname(context, principal, sizeof(kuser), kuser))
423*7934SMark.Phalan@Sun.COM return FALSE;
424*7934SMark.Phalan@Sun.COM
425*7934SMark.Phalan@Sun.COM if (strcmp(kuser, luser) == 0)
426*7934SMark.Phalan@Sun.COM return TRUE;
427*7934SMark.Phalan@Sun.COM
428*7934SMark.Phalan@Sun.COM return FALSE;
429*7934SMark.Phalan@Sun.COM }
430*7934SMark.Phalan@Sun.COM #endif /* _WIN32 */
431