No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / kafs / afskrb.c
blobd493e743772ea951386cd338072ef35761d29a11
1 /*
2 * Copyright (c) 1995 - 2001, 2003 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 #include "kafs_locl.h"
36 __RCSID("$Heimdal: afskrb.c 15342 2005-06-02 07:38:22Z lha $"
37 "$NetBSD$");
39 #ifdef KRB4
41 struct krb_kafs_data {
42 const char *realm;
45 static int
46 get_cred(struct kafs_data *data, const char *name, const char *inst,
47 const char *realm, uid_t uid, struct kafs_token *kt)
49 CREDENTIALS c;
50 KTEXT_ST tkt;
51 int ret = krb_get_cred((char*)name, (char*)inst, (char*)realm, &c);
53 if (ret) {
54 ret = krb_mk_req(&tkt, (char*)name, (char*)inst, (char*)realm, 0);
55 if (ret == KSUCCESS)
56 ret = krb_get_cred((char*)name, (char*)inst, (char*)realm, &c);
58 if (ret == 0)
59 ret = _kafs_v4_to_kt(&c, uid, kt);
60 return ret;
63 static int
64 afslog_uid_int(struct kafs_data *data,
65 const char *cell,
66 const char *realm_hint,
67 uid_t uid,
68 const char *homedir)
70 int ret;
71 struct kafs_token kt;
72 char name[ANAME_SZ];
73 char inst[INST_SZ];
74 char realm[REALM_SZ];
76 kt.ticket = NULL;
78 if (cell == 0 || cell[0] == 0)
79 return _kafs_afslog_all_local_cells (data, uid, homedir);
81 /* Extract realm from ticket file. */
82 ret = krb_get_tf_fullname(tkt_string(), name, inst, realm);
83 if (ret != KSUCCESS)
84 return ret;
86 kt.ticket = NULL;
87 ret = _kafs_get_cred(data, cell, realm_hint, realm, uid, &kt);
89 if (ret == 0) {
90 ret = kafs_settoken_rxkad(cell, &kt.ct, kt.ticket, kt.ticket_len);
91 free(kt.ticket);
93 return ret;
96 static char *
97 get_realm(struct kafs_data *data, const char *host)
99 char *r = krb_realmofhost(host);
100 if(r != NULL)
101 return strdup(r);
102 else
103 return NULL;
107 krb_afslog_uid_home(const char *cell, const char *realm_hint, uid_t uid,
108 const char *homedir)
110 struct kafs_data kd;
112 kd.name = "krb4";
113 kd.afslog_uid = afslog_uid_int;
114 kd.get_cred = get_cred;
115 kd.get_realm = get_realm;
116 kd.data = 0;
117 return afslog_uid_int(&kd, cell, realm_hint, uid, homedir);
121 krb_afslog_uid(const char *cell, const char *realm_hint, uid_t uid)
123 return krb_afslog_uid_home(cell, realm_hint, uid, NULL);
127 krb_afslog(const char *cell, const char *realm_hint)
129 return krb_afslog_uid(cell, realm_hint, getuid());
133 krb_afslog_home(const char *cell, const char *realm_hint, const char *homedir)
135 return krb_afslog_uid_home(cell, realm_hint, getuid(), homedir);
143 krb_realm_of_cell(const char *cell, char **realm)
145 struct kafs_data kd;
147 kd.name = "krb4";
148 kd.get_realm = get_realm;
149 return _kafs_realm_of_cell(&kd, cell, realm);
153 kafs_settoken(const char *cell, uid_t uid, CREDENTIALS *c)
155 struct kafs_token kt;
156 int ret;
158 kt.ticket = NULL;
160 ret = _kafs_v4_to_kt(c, uid, &kt);
161 if (ret)
162 return ret;
164 if (kt.ct.EndTimestamp < time(NULL)) {
165 free(kt.ticket);
166 return 0;
169 ret = kafs_settoken_rxkad(cell, &kt.ct, kt.ticket, kt.ticket_len);
170 free(kt.ticket);
171 return ret;
174 #else /* KRB4 */
176 #define KAFS_KRBET_KDC_SERVICE_EXP 39525378
179 krb_afslog_uid_home(const char *cell, const char *realm_hint, uid_t uid,
180 const char *homedir)
182 return KAFS_KRBET_KDC_SERVICE_EXP;
186 krb_afslog_uid(const char *cell, const char *realm_hint, uid_t uid)
188 return KAFS_KRBET_KDC_SERVICE_EXP;
192 krb_afslog_home(const char *cell, const char *realm_hint, const char *homedir)
194 return KAFS_KRBET_KDC_SERVICE_EXP;
198 krb_afslog(const char *cell, const char *realm_hint)
200 return KAFS_KRBET_KDC_SERVICE_EXP;
204 krb_realm_of_cell(const char *cell, char **realm)
206 *realm = NULL;
207 return KAFS_KRBET_KDC_SERVICE_EXP;
210 int kafs_settoken (const char*, uid_t, struct credentials *);
213 kafs_settoken(const char *cell, uid_t uid, struct credentials *c)
215 return KAFS_KRBET_KDC_SERVICE_EXP;
218 #endif /* KRB4 */