-: 0:Source:def_realm.c -: 0:Graph:/var/tsitkova/Sources/v10/trunk/src/lib/krb5/os/def_realm.so.gcno -: 0:Data:/var/tsitkova/Sources/v10/trunk/src/lib/krb5/os/def_realm.so.gcda -: 0:Runs:1602 -: 0:Programs:1 -: 1:/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -: 2:/* lib/krb5/os/def_realm.c */ -: 3:/* -: 4: * Copyright 1990,1991,2009 by the Massachusetts Institute of Technology. -: 5: * All Rights Reserved. -: 6: * -: 7: * Export of this software from the United States of America may -: 8: * require a specific license from the United States Government. -: 9: * It is the responsibility of any person or organization contemplating -: 10: * export to obtain such a license before exporting. -: 11: * -: 12: * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and -: 13: * distribute this software and its documentation for any purpose and -: 14: * without fee is hereby granted, provided that the above copyright -: 15: * notice appear in all copies and that both that copyright notice and -: 16: * this permission notice appear in supporting documentation, and that -: 17: * the name of M.I.T. not be used in advertising or publicity pertaining -: 18: * to distribution of the software without specific, written prior -: 19: * permission. Furthermore if you modify this software you must label -: 20: * your software as modified software and not distribute it in such a -: 21: * fashion that it might be confused with the original M.I.T. software. -: 22: * M.I.T. makes no representations about the suitability of -: 23: * this software for any purpose. It is provided "as is" without express -: 24: * or implied warranty. -: 25: */ -: 26: -: 27:/* -: 28: * krb5_get_default_realm(), krb5_set_default_realm(), -: 29: * krb5_free_default_realm() functions. -: 30: */ -: 31: -: 32:#include "k5-int.h" -: 33:#include "os-proto.h" -: 34:#include -: 35: -: 36:#ifdef KRB5_DNS_LOOKUP -: 37:#ifdef WSHELPER -: 38:#include -: 39:#else /* WSHELPER */ -: 40:#ifdef HAVE_NETINET_IN_H -: 41:#include -: 42:#endif -: 43:#include -: 44:#include -: 45:#include -: 46:#include -: 47:#endif /* WSHELPER */ -: 48: -: 49:/* for old Unixes and friends ... */ -: 50:#ifndef MAXHOSTNAMELEN -: 51:#define MAXHOSTNAMELEN 64 -: 52:#endif -: 53: -: 54:#endif /* KRB5_DNS_LOOKUP */ -: 55: -: 56:/* -: 57: * Retrieves the default realm to be used if no user-specified realm is -: 58: * available. [e.g. to interpret a user-typed principal name with the -: 59: * realm omitted for convenience] -: 60: * -: 61: * returns system errors, NOT_ENOUGH_SPACE, KV5M_CONTEXT -: 62: */ -: 63: -: 64:/* -: 65: * Implementation: the default realm is stored in a configuration file, -: 66: * named by krb5_config_file; the first token in this file is taken as -: 67: * the default local realm name. -: 68: */ -: 69: -: 70:krb5_error_code KRB5_CALLCONV 1221: 71:krb5_get_default_realm(krb5_context context, char **lrealm) -: 72:{ 1221: 73: char *realm = 0; -: 74: krb5_error_code retval; -: 75: 1221: 76: if (!context || (context->magic != KV5M_CONTEXT)) #####: 77: return KV5M_CONTEXT; -: 78: 1221: 79: if (!context->default_realm) { -: 80: /* -: 81: * XXX should try to figure out a reasonable default based -: 82: * on the host's DNS domain. -: 83: */ 852: 84: context->default_realm = 0; 852: 85: if (context->profile != 0) { 852: 86: retval = profile_get_string(context->profile, KRB5_CONF_LIBDEFAULTS, -: 87: KRB5_CONF_DEFAULT_REALM, 0, 0, -: 88: &realm); -: 89: 852: 90: if (!retval && realm) { 852: 91: context->default_realm = strdup(realm); 852: 92: if (!context->default_realm) { #####: 93: profile_release_string(realm); #####: 94: return ENOMEM; -: 95: } 852: 96: profile_release_string(realm); -: 97: } -: 98: } -: 99:#ifndef KRB5_DNS_LOOKUP -: 100: else -: 101: return KRB5_CONFIG_CANTOPEN; -: 102:#else /* KRB5_DNS_LOOKUP */ 852: 103: if (context->default_realm == 0) { #####: 104: int use_dns = _krb5_use_dns_realm(context); #####: 105: if ( use_dns ) { -: 106: /* -: 107: * Since this didn't appear in our config file, try looking -: 108: * it up via DNS. Look for a TXT records of the form: -: 109: * -: 110: * _kerberos. -: 111: * _kerberos. -: 112: * _kerberos. -: 113: * -: 114: */ -: 115: char localhost[MAX_DNS_NAMELEN+1]; -: 116: char * p; -: 117: #####: 118: krb5int_get_fq_local_hostname (localhost, sizeof(localhost)); -: 119: #####: 120: if ( localhost[0] ) { #####: 121: p = localhost; -: 122: do { #####: 123: retval = krb5_try_realm_txt_rr("_kerberos", p, -: 124: &context->default_realm); #####: 125: p = strchr(p,'.'); #####: 126: if (p) #####: 127: p++; #####: 128: } while (retval && p && p[0]); -: 129: #####: 130: if (retval) #####: 131: retval = krb5_try_realm_txt_rr("_kerberos", "", -: 132: &context->default_realm); -: 133: } else { #####: 134: retval = krb5_try_realm_txt_rr("_kerberos", "", -: 135: &context->default_realm); -: 136: } #####: 137: if (retval) { #####: 138: return(KRB5_CONFIG_NODEFREALM); -: 139: } -: 140: } -: 141: } -: 142:#endif /* KRB5_DNS_LOOKUP */ -: 143: } -: 144: 1221: 145: if (context->default_realm == 0) #####: 146: return(KRB5_CONFIG_NODEFREALM); 1221: 147: if (context->default_realm[0] == 0) { #####: 148: free (context->default_realm); #####: 149: context->default_realm = 0; #####: 150: return KRB5_CONFIG_NODEFREALM; -: 151: } -: 152: 1221: 153: realm = context->default_realm; -: 154: 1221: 155: if (!(*lrealm = strdup(realm))) #####: 156: return ENOMEM; 1221: 157: return(0); -: 158:} -: 159: -: 160:krb5_error_code KRB5_CALLCONV 804: 161:krb5_set_default_realm(krb5_context context, const char *lrealm) -: 162:{ 804: 163: if (!context || (context->magic != KV5M_CONTEXT)) #####: 164: return KV5M_CONTEXT; -: 165: 804: 166: if (context->default_realm) { 561: 167: free(context->default_realm); 561: 168: context->default_realm = 0; -: 169: } -: 170: -: 171: /* Allow the user to clear the default realm setting by passing in -: 172: NULL */ 804: 173: if (!lrealm) return 0; -: 174: 804: 175: context->default_realm = strdup(lrealm); -: 176: 804: 177: if (!context->default_realm) #####: 178: return ENOMEM; -: 179: 804: 180: return(0); -: 181: -: 182:} -: 183: -: 184:void KRB5_CALLCONV 107: 185:krb5_free_default_realm(krb5_context context, char *lrealm) -: 186:{ 107: 187: free (lrealm); 107: 188:}