4
* For copying and distribution information, please see the file
7
* Macintosh oopserating system stub interface for Kerberos.
8
* Applications call these routines, which then call the driver to do the work.
12
#include "krb_driver.h" /* Mac driver interface */
19
/* We export the driver reference under the name mac_stubs_kdriver,
20
but for convenience throughout this code, we call it "kdriver",
21
which was its name when it was static. */
22
short mac_stubs_kdriver = 0; /* .Kerberos driver ref */
23
#define kdriver mac_stubs_kdriver
26
struct krbHiParmBlock khipb[1];
27
struct krbParmBlock klopb[1];
29
short lowcall (long cscode, krbParmBlock *klopb, short kdriver)
34
memset (&pb, 0, sizeof(ParamBlockRec));
35
*(long *)pb.cntrlParam.csParam = (long)klopb;
36
pb.cntrlParam.ioCompletion = nil;
37
pb.cntrlParam.ioCRefNum = kdriver;
38
pb.cntrlParam.csCode = cscode;
40
if (s = PBControl(&pb, false))
42
if (s = pb.cntrlParam.ioResult)
43
return -(s - cKrbKerberosErrBlock); /* Restore krb err code from driver err */
49
short hicall (long cscode, krbHiParmBlock *khipb, short kdriver)
53
memset(&pb, 0, sizeof(ParamBlockRec));
54
*(long *)pb.cntrlParam.csParam = (long)khipb;
55
pb.cntrlParam.ioCompletion = nil;
56
pb.cntrlParam.ioCRefNum = kdriver;
58
pb.cntrlParam.csCode = cscode;
59
if (s = PBControl(&pb, false))
61
if (s = pb.cntrlParam.ioResult)
62
return -(s - cKrbKerberosErrBlock); /* Restore krb err code from driver err */
75
* Open the .Kerberos driver if not already open
78
s = OpenDriver("\p.Kerberos", &kdriver);
80
return KFAILURE; /* Improve this error code */
94
#if 0 /* This driver doesn't want to be closed. FIXME, is this OK? */
96
s = CloseDriver(kdriver);
107
krb_realmofhost (host)
112
static char realm[REALM_SZ];
114
memset(klopb, 0, sizeof(*klopb));
116
klopb->uRealm = realm;
118
/* FIXME jcm - no error handling for return value of lowcall in krb_realmofhost */
119
s = lowcall (cKrbGetRealm , klopb, kdriver);
125
krb_get_lrealm (realm, n)
135
memset(klopb, 0, sizeof(*klopb));
136
klopb->uRealm = realm;
138
s = lowcall (cKrbGetLocalRealm, klopb, kdriver);
145
kname_parse (name, instance, realm, fullname)
146
char *name, *instance, *realm, *fullname;
151
memset(klopb, 0, sizeof(*klopb));
153
klopb->uInstance = instance;
154
klopb->uRealm = realm;
155
klopb->fullname = fullname;
157
s = lowcall (cKrbKnameParse, klopb, kdriver);
161
const char* INTERFACE
162
krb_get_err_text (error_code)
167
memset(klopb, 0, sizeof(*klopb));
168
klopb->admin = error_code;
169
s = lowcall (cKrbGetErrText, klopb, kdriver);
171
return "Error in get_err_text";
177
krb_get_pw_in_tkt(user,instance,realm,service,sinstance,life,password)
178
char *user, *instance, *realm, *service, *sinstance;
184
memset(klopb, 0, sizeof(*klopb));
186
klopb->uInstance = instance;
187
klopb->uRealm = realm;
188
klopb->sName = service;
189
klopb->sInstance = sinstance;
191
klopb->fullname = password;
193
s = lowcall (cKrbGetPwInTkt, klopb, kdriver);
198
/* FIXME: For now, we handle the preauth version exactly the same
199
as the non-preauth. */
200
krb_get_pw_in_tkt_preauth(user,instance,realm,service,sinstance,life,password)
201
char *user, *instance, *realm, *service, *sinstance;
207
memset(klopb, 0, sizeof(*klopb));
209
klopb->uInstance = instance;
210
klopb->uRealm = realm;
211
klopb->sName = service;
212
klopb->sInstance = sinstance;
214
klopb->fullname = password;
216
s = lowcall (cKrbGetPwInTkt, klopb, kdriver);
223
krb_get_default_user (void)
226
static char return_name[MAX_K_NAME_SZ];
228
memset(khipb, 0, sizeof(*khipb));
229
khipb->user = return_name;
230
s = hicall (cKrbGetUserName, khipb, kdriver);
238
krb_set_default_user (uName)
243
memset(khipb, 0, sizeof(*khipb));
245
s = hicall (cKrbSetUserName, khipb, kdriver);
250
krb_get_cred (name, instance, realm, cr)
258
memset(klopb, 0, sizeof(*klopb));
260
strcpy(cr->service, name);
261
strcpy(cr->instance, instance);
262
strcpy(cr->realm, realm);
266
s = lowcall (cKrbGetCredentials, klopb, kdriver);
271
krb_save_credentials (sname, sinstance, srealm, session,
272
lifetime, kvno,ticket, issue_date)
273
char *sname; /* service name */
274
char *sinstance; /* service instance */
275
char *srealm; /* service realm */
276
C_Block session; /* Session key */
277
int lifetime; /* Lifetime */
278
int kvno; /* Key version number */
279
KTEXT ticket; /* The ticket itself */
280
long issue_date; /* The issue time */
286
strcpy(cr.service, sname);
287
strcpy(cr.instance, sinstance);
288
strcpy(cr.realm, srealm);
289
memcpy(cr.session, session, sizeof(C_Block));
290
cr.lifetime = lifetime;
292
cr.ticket_st = *ticket;
293
cr.issue_date = issue_date;
295
memset(klopb, 0, sizeof(*klopb));
298
s = lowcall (cKrbAddCredentials, klopb, kdriver);
304
krb_delete_cred (sname, sinstance, srealm)
311
memset(klopb, 0, sizeof(*klopb));
313
klopb->sName = sname;
314
klopb->sInstance = sinstance;
315
klopb->sRealm = srealm;
317
s = lowcall (cKrbDeleteCredentials, klopb, kdriver);
323
char *cachename; /* This parameter is ignored. */
327
memset(klopb, 0, sizeof(*klopb));
328
s = lowcall (cKrbDeleteAllSessions, klopb, kdriver);
333
* returns service name, service instance and realm of the nth credential.
334
* credential numbering is 1 based.
338
krb_get_nth_cred (sname, sinstance, srealm, n)
346
memset(klopb, 0, sizeof(*klopb));
348
klopb->sName = sname;
349
klopb->sInstance = sinstance;
350
klopb->sRealm = srealm;
351
klopb->itemNumber = &n;
353
s = lowcall (cKrbGetNthCredentials, klopb, kdriver);
358
* Return the number of credentials in the current credential cache (ticket cache).
359
* On error, returns -1.
367
memset(klopb, 0, sizeof(*klopb));
368
klopb->itemNumber = &n;
370
s = lowcall (cKrbGetNumCredentials, klopb, kdriver);
373
return *(klopb->itemNumber);
379
yields the Nth mapping of a net or host to a Kerberos realm
380
-> itemNumber which mapping, traditionally the first
382
-> uRealm pointer to buffer that will receive realm name
386
GetNthRealmMap(n, netorhost, realm)
392
memset(klopb, 0, sizeof(*klopb));
393
klopb->itemNumber = &n;
394
klopb->host = netorhost;
395
klopb->uRealm = realm;
397
s = lowcall (cKrbGetNthRealmMap, klopb, kdriver);
402
yields Nth realm-server mapping
403
-> itemNumber which mapping should be returned
404
-> uRealm pointer to buffer that will receive realm name
405
-> host pointer to buffer that will receive server name
406
-> admin pointer to admin flag
410
GetNthServerMap(n, realm, server, admin)
417
memset(klopb, 0, sizeof(*klopb));
418
klopb->itemNumber = &n;
419
klopb->uRealm = realm;
420
klopb->host = server;
421
klopb->adminReturn = admin;
423
s = lowcall (cKrbGetNthServerMap, klopb, kdriver);
429
/* krb_get_ticket_for_service
430
* Gets a ticket and returns it to application in buf
431
-> service Formal Kerberos name of service
432
-> buf Buffer to receive ticket
433
-> checksum checksum for this service
434
<-> buflen length of ticket buffer (must be at least
436
<- sessionKey for internal use
437
<- schedule for internal use
440
* GC_NOTKT if there is no matching TGT in the cache
441
* MK_AP_TGTEXP if the matching TGT is expired
442
* Other errors possible. These could cause a dialogue with the user
447
krb_get_ticket_for_service (serviceName, buf, buflen, checksum, sessionKey,
448
schedule, version, includeVersion)
451
unsigned KRB4_32 *buflen;
453
des_cblock sessionKey;
454
Key_schedule schedule;
461
return KFAILURE; /* Not implmented in the kclient driver iface */
463
memset(khipb, 0, sizeof(*khipb));
464
khipb->service = serviceName;
466
khipb->buflen = *buflen;
467
khipb->checksum = checksum;
469
s = hicall (cKrbGetTicketForService, khipb, kdriver);
470
/* These are ARRAYS in the hiparmblock, for some reason! */
471
memcpy (sessionKey, khipb->sessionKey, sizeof (khipb[0].sessionKey));
472
memcpy (schedule, khipb->schedule, sizeof (khipb[0].schedule));
473
*buflen = khipb->buflen;
478
/* krb_get_tf_fullname -- return name, instance and realm of the
479
principal in the current ticket file. The ticket file name is not
480
currently used for anything since there is only one credentials
485
krb_get_tf_fullname (tktfile, name, instance, realm)
493
memset (klopb, 0, sizeof(*klopb));
494
klopb->fullname = tktfile;
496
klopb->uInstance = instance;
497
klopb->uRealm = realm;
499
s = lowcall (cKrbGetTfFullname, klopb, kdriver);
506
xbzero(khipb, sizeof(krbHiParmBlock));
507
khipb->service = (char *)cannon;
508
khipb->buf = (char *)buf; /* where to build it */
510
khipb->buflen = sizeof(buf);
511
if (s = hicall(cKrbGetTicketForService, khipb, kdriver))
513
xbcopy(khipb->sessionKey, sessionKey, sizeof(sessionKey)); /* save the session key */
515
* cKrbGetTicketForService put a longword buffer length into the buffer
516
* which we don't want, so we ignore it.
517
* Make room for first 3 bytes which preceed the auth data.
519
cp = &buf[4-3]; /* skip long, make room for 3 bytes */
520
cp[0] = tp[0]; /* copy type and modifier */
522
cp[2] = KRB_AUTH; /* suboption command */
523
len = khipb->buflen - sizeof(long) + 3; /* data - 4 + 3 */