Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / aklog / krb_util.c
CommitLineData
805e021f
CE
1/*
2 * This file replaces some of the routines in the Kerberos utilities.
3 * It is based on the Kerberos library modules:
4 * send_to_kdc.c
5 *
6 * Copyright 1987, 1988, 1992 by the Massachusetts Institute of Technology.
7 *
8 * For copying and distribution information, please see the file
9 * <mit-copyright.h>.
10 */
11
12#include <afsconfig.h>
13#include <afs/stds.h>
14
15#include <roken.h>
16
17#define KERBEROS_APPLE_DEPRECATED(x)
18#include "aklog.h"
19#include <krb5.h>
20
21#ifndef MAX_HSTNM
22#define MAX_HSTNM 100
23#endif
24
25#include <afs/cellconfig.h>
26
27#include <ctype.h>
28
29#define S_AD_SZ sizeof(struct sockaddr_in)
30
31char *afs_realm_of_cell(krb5_context context, struct afsconf_cell *cellconfig, int fallback)
32{
33 static char krbrlm[REALM_SZ+1];
34 char **hrealms = 0;
35 krb5_error_code retval;
36
37 if (!cellconfig)
38 return 0;
39
40 if (fallback) {
41 char * p;
42 p = strchr(cellconfig->hostName[0], '.');
43 if (p++)
44 strcpy(krbrlm, p);
45 else
46 strcpy(krbrlm, cellconfig->name);
47 for (p=krbrlm; *p; p++) {
48 if (islower(*p))
49 *p = toupper(*p);
50 }
51 } else {
52 if ((retval = krb5_get_host_realm(context,
53 cellconfig->hostName[0], &hrealms)))
54 return 0;
55 if(!hrealms[0]) return 0;
56 strcpy(krbrlm, hrealms[0]);
57
58 if (hrealms) krb5_free_host_realm(context, hrealms);
59 }
60 return krbrlm;
61}