summaryrefslogtreecommitdiffstats
path: root/src/lib/krb425/realmhost.c
blob: d7d2f9eff520c31f94f227c098859276b7671d2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * $Source$
 * $Author$
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <krb5/copyright.h>.
 *
 * krb_realmofhost for krb425
 */

#if !defined(lint) && !defined(SABER)
static char rcsid_realmhost_c[] =
"$Id$";
#endif	/* !lint & !SABER */

#include <krb5/copyright.h>
#include "krb425.h"

char *
krb_realmofhost(host)
char *host;
{
	char **realms;
	char *domain;
	static char ret_realm[REALM_SZ+1];


        domain = index(host, '.');

        /* prepare default */
        if (domain) {
                char *cp;

                strncpy(ret_realm, &domain[1], REALM_SZ);
                ret_realm[REALM_SZ] = '\0';
                /* Upper-case realm */
                for (cp = ret_realm; *cp; cp++)
                        if (islower(*cp))
                                *cp = toupper(*cp);
        } else {
		if (!_krb425_local_realm &&
		    krb5_get_default_realm(&_krb425_local_realm))
			_krb425_local_realm = NULL;

		if (_krb425_local_realm) {
			strncpy(ret_realm, _krb425_local_realm, REALM_SZ);
			ret_realm[REALM_SZ-1] = 0;
		}
	}

	if (krb5_get_host_realm(host, &realms)) {
		return(ret_realm);
	}
	strncpy(ret_realm, realms[0], REALM_SZ);
	krb5_free_host_realm(realms);
	return(ret_realm);
}