summaryrefslogtreecommitdiffstats
path: root/src/lib/krb4/mac_store.c
blob: 262ba58bd5e29eb1ea2068cc9b4f7fbdf33201a2 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/*
 * mac_store.c
 *
 * Kerberos configuration store
 * Originally coded by Tim Miller / Brown University as KRB_Store.c
 * Mods 1/92 By Peter Bosanko
 *
 * Modified May-June 1994 by Julia Menapace and John Gilmore
 * of Cygnus Support.
 *
 * This file incorporates replacements for the Unix files
 * g_admhst.c, g_krbhst.c, realmofhost.c, and g_krbrlm.c.
 */

/* Headers from in_tkt.c, merged in by gnu FIXME */
#include <types.h>

/* Headers from store.c from KClient */
#include <string.h>
#include <traps.h>
#include <gestaltEqu.h>
#include <Folders.h>
#include <Resources.h>
#include <Memory.h>
#include <Files.h>

#include "krb.h"
#include "mac_store.h"	/* includes memcache.h */
#include "krb_driver.h"

#define	prefname	"\pKerberos Client Preferences"
const	OSType	preftype = 'PREF';
const	OSType	prefcrea	= 'krbL';
const	OSType	unametype = 'UNam';
const	OSType	lrealmtype = 'LRlm';
const	OSType	templatetype = 'TMPL';
const	OSType	realmmaptype = 'RMap';
const	OSType	servermaptype = 'SMap';
#define kNumTemplates 4
#define kFirstTemplate 128
#define kMapResNum 1024


/* Lower level routines and data structures  */


/* Need to check this in each high-level routine, and call init_store
   if not set.  */
static	int		initialized_store = 0;		

static	char		fLRealm[REALM_SZ] = "";
static	Handle		fRealmMap = 0;
static	Handle		fServerMap = 0;
static	short		fPrefVRefNum;
static	long		fPrefDirID;
OSErr			fConstructErr = -1;

/* Current default user name (for prompts, etc).  */

static char gUserName[MAX_K_NAME_SZ]; 


/* Routines for dealing with the realm versus host database */

/*
 * krb_get_admhst
 *
 * Given a Kerberos realm, find a host on which the Kerberos database
 * administration server can be found.
 *
 * krb_get_admhst takes a pointer to be filled in, a pointer to the name
 * of the realm for which a server is desired, and an integer n, and
 * returns (in h) the nth administrative host entry from the configuration
 * file (KRB_CONF, defined in "krb.h") associated with the specified realm.
 * If ATHENA_CONF_FALLBACK is defined, also look in old location.
 *
 * On error, get_admhst returns KFAILURE. If all goes well, the routine
 * returns KSUCCESS.
 *
 * For the format of the KRB_CONF file, see comments describing the routine
 * krb_get_krbhst().
 *
 * This is a temporary hack to allow us to find the nearest system running
 * a Kerberos admin server.  In the long run, this functionality will be
 * provided by a nameserver.  (HAH!)
 */
int
krb_get_admhst (h, r, n)
	char *h;
	char *r;
	int n;
{
	if (!initialized_store) 
		if (init_store())
			return KFAILURE;
	if(GetNthServer(n, r, 1, h)) return KFAILURE;
	else return KSUCCESS;
}

/*
 * Given a Kerberos realm, find a host on which the Kerberos authenti-
 * cation server can be found.
 *
 * krb_get_krbhst takes a pointer to be filled in, a pointer to the name
 * of the realm for which a server is desired, and an integer, n, and
 * returns (in h) the nth entry from the configuration information
 * associated with the specified realm.
 *
 * If no info is found, krb_get_krbhst returns KFAILURE.  If n=1 and the
 * configuration file does not exist, krb_get_krbhst will return KRB_HOST
 * (defined in "krb.h").  If all goes well, the routine returnes
 * KSUCCESS.
 *
 * This is a temporary hack to allow us to find the nearest system running
 * kerberos.  In the long run, this functionality will be provided by a
 * nameserver.  (AH SO!)
 */
int	krb_get_krbhst(h, r, n)
	char *h;
	char *r;
	int n;
{
	if (!initialized_store) 
		if (init_store())
			return KFAILURE;
	if (GetNthServer(n, r, 0, h)) return KFAILURE;
	else return KSUCCESS;
}


/*
 * krb_get_lrealm takes a pointer to a string, and a number, n.  It fills
 * in the string, r, with the name of the local realm specified in
 * the local Kerberos configuration.
 * It returns 0 (KSUCCESS) on success, and KFAILURE on failure.  If the
 * config info does not exist, and if n=1, a successful return will occur
 * with r = KRB_REALM (also defined in "krb.h").  [FIXME -- not implem.]
 *
 * NOTE: for archaic & compatibility reasons, this routine will only return
 * valid results when n = 1.
 */

int	krb_get_lrealm(char *r, int n)
{
	if (!initialized_store) 
		if (init_store())
			return KFAILURE;
	if (n != 1)
		return KFAILURE;
	if (GetLocalRealm(r))
		return KFAILURE;
	return KSUCCESS;
}


/*
 * krb_realmofhost.
 * Given a fully-qualified domain-style primary host name,
 * return the name of the Kerberos realm for the host.
 * If the hostname contains no discernable domain, or an error occurs,
 * return the local realm name, as supplied by get_krbrlm().
 * If the hostname contains a domain, but no translation is found,
 * the hostname's domain is converted to upper-case and returned.
 *
 * In the database,
 * domain_name should be of the form .XXX.YYY (e.g. .LCS.MIT.EDU)
 * host names should be in the usual form (e.g. FOO.BAR.BAZ)
 */

char *krb_realmofhost(char *host)
{
	static char	realm[REALM_SZ];
	
	if (!initialized_store) 
		if (init_store())
			return 0;

	/* Store realm string through REALM pointer arg */
	GetRealm(host, realm);	
	return realm;
}


char * INTERFACE
krb_get_default_user (void)
{
    if (!initialized_store)
	if (init_store())
	    return 0;

    return gUserName;
}


int INTERFACE
krb_set_default_user (uName)
    char* uName;
{
    if (!initialized_store)
	if (init_store())
	    return KFAILURE;

    if( strcmp( gUserName, uName ) != 0 ) {
	strcpy( gUserName, uName );
	if (WriteUser() != 0)
	    return KFAILURE;
    }
    return KSUCCESS;
}



void GetPrefsFolder(short *vRefNumP, long *dirIDP)
{
	Boolean hasFolderMgr = false;
	long feature;
/*	
	FIXME Error:   Ô_GestaltDispatchÕ has not been declared - not needed now? - jcm
	if (TrapAvailable(_GestaltDispatch)) 
*/
	if (Gestalt(gestaltFindFolderAttr, &feature) == noErr) hasFolderMgr = true;
	if (!hasFolderMgr) {
		GetSystemFolder(vRefNumP, dirIDP);
		return;
		}
	else {
		if (FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder, vRefNumP, dirIDP) != noErr) {
			*vRefNumP = 0;
			*dirIDP = 0;
			}
		}
	}


/*
    init_store() is used to initialize the config store.  It opens the
    driver preferences file and reads the local realm, user name, and
    realm and server maps from resources in the prefs file into driver
    storage.  If the preferences file doesn't exist, init_store creates it.
    Returns 0 on success, or 1 if something goes wrong.
 */
int
init_store()
{
	short refnum;
	Handle	temp;
	int hasPrefFile;
	
	/* If a prefs file exists, load from it, otherwise load defaults from self */
	GetPrefsFolder(&fPrefVRefNum, &fPrefDirID);
	refnum = HOpenResFile(fPrefVRefNum, fPrefDirID, (unsigned char *)prefname, fsRdPerm);
	hasPrefFile = (refnum != -1); 		// did we open it?
	
	temp = GetResource(lrealmtype, kMapResNum);
	if(ResError() || !temp) {
		if(refnum != -1) CloseResFile(refnum);
		fConstructErr = cKrbCorruptedFile;
		return 1;
	}
	strcpy(fLRealm, *temp);
	ReleaseResource(temp);
	
	temp = GetResource(unametype, kMapResNum);
	if(ResError() || !temp) {
		if(refnum != -1) CloseResFile(refnum);
		fConstructErr = cKrbCorruptedFile;
		return 1;
	}
	strcpy(gUserName, *temp);
	ReleaseResource(temp);
	
	fRealmMap = GetResource(realmmaptype, kMapResNum);
	if(ResError() || !fRealmMap) {
		if(refnum != -1) CloseResFile(refnum);
		*fLRealm = 0;
		fConstructErr = cKrbCorruptedFile;
		return 1;
	}
	DetachResource(fRealmMap);
	
	fServerMap = GetResource(servermaptype, kMapResNum);
	if(ResError() || !fServerMap) {
		if(refnum != -1) CloseResFile(refnum);
		*fLRealm = 0;
		DisposeHandle(fRealmMap);
		fRealmMap = 0;
		fConstructErr = cKrbCorruptedFile;
		return 1;
	}
	DetachResource(fServerMap);
	
	if(refnum != -1) CloseResFile(refnum);
	fConstructErr = noErr;
	
	if (!hasPrefFile) {
		fConstructErr = CreatePrefFile();		// make prefs file if we need to
	}
	
	initialized_store = 1;
	return 0;
}


/****************Private routines******************/

OSErr	OpenPrefsFile(short *refnum)
{
	*refnum = HOpenResFile(fPrefVRefNum, fPrefDirID, (unsigned char *)prefname, fsRdWrPerm);
	
	if(ResError()) {	/* doesn't exist, create it */
		FInfo	fndrinfo;
		
		HCreateResFile(fPrefVRefNum, fPrefDirID, (unsigned char *)prefname);
		if(ResError()) {
			return ResError();
			}
		*refnum = HOpenResFile(fPrefVRefNum, fPrefDirID, (unsigned char *)prefname, fsRdWrPerm);
		if(ResError()) {
			return ResError();
			}
		HGetFInfo(fPrefVRefNum, fPrefDirID, (unsigned char *)prefname, &fndrinfo); 
		fndrinfo.fdCreator = prefcrea;
		fndrinfo.fdType = preftype;
		HSetFInfo(fPrefVRefNum, fPrefDirID, (unsigned char *)prefname, &fndrinfo); 
		}
	
	return noErr;
	}



OSErr	CreatePrefFile()
{
	short	refnum, i;
	OSErr	err;
	Handle	tmpls[ kNumTemplates ];

	// Get all the templates for ResEdit
	for( i = 0; i < kNumTemplates; i++ ) {
		tmpls[i] = GetResource( templatetype, kFirstTemplate + i );
		if( ResError() || !tmpls[i] ) return cKrbCorruptedFile;
	}
	
	err = OpenPrefsFile( &refnum );
	if( err ) return err;
	
	// write out the templates
	for( i = 0; i < kNumTemplates && !err; i++ ) {
		short	tmplid;
		ResType	theType;
		Str255	resName;

		GetResInfo( tmpls[i], &tmplid, &theType, resName );
		err = WritePref( refnum, tmpls[i], templatetype, tmplid, resName );	
		ReleaseResource( tmpls[i] );
	}

	if( !err )
		err = WritePref( refnum, fRealmMap, realmmaptype, kMapResNum, "\p" );	
	if( !err )
		err = WritePref( refnum, fServerMap, servermaptype, kMapResNum, "\p" );	
	if( !err )
		err = WritePrefStr( refnum, fLRealm, lrealmtype, kMapResNum, "\p" );	
	if( !err )
		err = WritePrefStr( refnum, gUserName, unametype, kMapResNum, "\p" );	

	CloseResFile( refnum );
	if( !err ) err = ResError();
	return err;
}

OSErr	WriteUser()
{
	short	refnum;
	OSErr	err;

	err = OpenPrefsFile( &refnum );
	if( err ) return err;

	err = WritePrefStr( refnum, gUserName, unametype, kMapResNum, "\p" );	

	CloseResFile( refnum );
	if( !err ) err = ResError();
	return err;
}

OSErr	WritePref( short refnum, Handle dataHandle, OSType mapType, short resID, Str255 resName )
{
	OSErr	err;
	Handle	resHandle;

	resHandle = Get1Resource( mapType, resID );
	if( !resHandle ) {								// create a new resource:
		resHandle = dataHandle;
		err = HandToHand( &resHandle );				// copy the data handle
		if( err != noErr ) return err;

		AddResource( resHandle, mapType, resID, resName );
		if( ( err = ResError() ) != noErr ) {
			DisposHandle( resHandle );
			return err;
		}
		SetResAttrs( resHandle, resSysHeap | GetResAttrs( resHandle ) );
	}
	else {											/* modify an existing resource: */
		Size handleSize = GetHandleSize( dataHandle );
		SetHandleSize( resHandle, handleSize );
		if( ( err = MemError() ) != noErr ) {
			ReleaseResource( resHandle );
			return err;
		}
		BlockMove( *dataHandle, *resHandle, handleSize );
		ChangedResource( resHandle );
		if( ( err = ResError() ) != noErr ) {
			ReleaseResource( resHandle );
			return err;
		}
	}

	UpdateResFile( refnum );
	err = ResError();
	ReleaseResource( resHandle );
	return err;
}

OSErr	WritePrefStr( short refnum, char *dataString, OSType mapType, short resID, Str255 resName )
{
	OSErr		err;
	Handle	dataHandle;

	err = PtrToHand( dataString, &dataHandle, strlen( dataString ) + 1 );
	if( err == noErr ) {
		err = WritePref( refnum, dataHandle, mapType, resID, resName );
		DisposHandle( dataHandle );
	}
	return err;
}
	
OSErr	WriteRealmMap()
{
	short	refnum;
	OSErr	err;
	
	err = OpenPrefsFile( &refnum );
	if( err ) return err;
		
 	err = WritePref( refnum, fRealmMap, realmmaptype, kMapResNum, "\p" );	

	CloseResFile( refnum );
	if( !err ) err = ResError();
	return err;
}

OSErr	WriteServerMap()
{
	short	refnum;
	OSErr	err;
	
	err = OpenPrefsFile(&refnum);
	if( err ) return err;
	
	err = WritePref( refnum, fServerMap, servermaptype, kMapResNum,"\p" );	

	CloseResFile( refnum );
	if( !err ) err = ResError();
	return err;
}

OSErr	GetLocalRealm(char *lrealm)
{
	if (!initialized_store)
		init_store();
	
	strcpy(lrealm, fLRealm);
	return noErr;
	}

OSErr	SetLocalRealm( const char *lrealm )
{
	short	refnum;
	OSErr	err;
		
	if (!initialized_store)
		init_store();
	
	strcpy( fLRealm, (char *) lrealm );
	
	err = OpenPrefsFile( &refnum );
	if( err ) return err;
	
	err = WritePrefStr( refnum, fLRealm, lrealmtype, kMapResNum, "\p" );	

	CloseResFile( refnum );
	if( !err ) err = ResError();
	return err;
}

OSErr	GetRealm(const char *host, char *realm)
{
	int	numrealms;
	char	*curnetorhost, *currealm;
	char	*domain;
	
	if (!initialized_store)
		init_store();
	
	numrealms = *((short *)*fRealmMap);
	GetLocalRealm(realm);
	
	domain = strchr( host, '.');
	if(!domain) return noErr;
	
	curnetorhost = (*fRealmMap) + 2;
	currealm = strchr(curnetorhost, '\0') + 1;
	for( ; numrealms > 0; numrealms--) {
		if(!strcasecmp(curnetorhost, host)) {
			strcpy(realm, currealm);
			return noErr;
			}
		if(!strcasecmp(curnetorhost, domain)) {
			strcpy(realm, currealm);
			}
		
		if(numrealms > 1) {
			curnetorhost = strchr(currealm, '\0') + 1;
			currealm = strchr(curnetorhost, '\0') + 1;
			}
		}
	
	return noErr;
	}

OSErr	AddRealmMap(const char *netorhost, const char *realm)
{
	int	numrealms;
	char	*curptr;
	
	SetHandleSize(fRealmMap, strlen(netorhost)+1 + strlen(realm)+1 +
										GetHandleSize(fRealmMap));
	if(MemError()) return MemError();
	
	numrealms = ++(*((short *)*fRealmMap));
	
	for(curptr = (*fRealmMap)+2; numrealms > 1; numrealms--) {
		curptr = strchr(curptr, '\0') + 1;
		curptr = strchr(curptr, '\0') + 1;
		}
	
	strcpy(curptr, netorhost);
	curptr = strchr(curptr, '\0') + 1;
	strcpy(curptr, realm);
	
	return WriteRealmMap();
	}

OSErr	DeleteRealmMap(const char *netorhost)
{
	int	numrealms = *((short *)*fRealmMap);
	char	*curptr, *fromptr, *nextptr;
		
	for(curptr = (*fRealmMap)+2; numrealms > 0; numrealms--) {
		if(!strcasecmp(curptr, netorhost)) break;	/* got it! */
		
		curptr = strchr(curptr, '\0') + 1;
		curptr = strchr(curptr, '\0') + 1;
		}
	
	if(numrealms == 0) return cKrbMapDoesntExist;
	
	*(short*)*fRealmMap -= 1;
	
	if(numrealms > 1) {
		fromptr = strchr(curptr, '\0') + 1;
		fromptr = strchr(fromptr, '\0') + 1;
		}
	
	for( ; numrealms > 1; numrealms--) {
		nextptr = strchr(fromptr, '\0') + 1;
		strcpy(curptr, fromptr);
		curptr = strchr(curptr, '\0') + 1;
		fromptr = nextptr;
		
		nextptr = strchr(fromptr, '\0') + 1;
		strcpy(curptr, fromptr);
		curptr = strchr(curptr, '\0') + 1;
		fromptr = nextptr;
		}
	
	SetHandleSize(fRealmMap, curptr-(*fRealmMap));
	if(MemError()) return MemError();
	return WriteRealmMap();
	}

OSErr	GetNthRealmMap(const int n, char *netorhost, char *realm)
{
	int	i;
	char	*curptr;
	
	if(n > *(short*)*fRealmMap) return cKrbMapDoesntExist;
	
	for(curptr = (*fRealmMap) + 2, i = 1; i < n; i++) {
		curptr = strchr(curptr, '\0') + 1;
		curptr = strchr(curptr, '\0') + 1;
		}
	
	strcpy(netorhost, curptr);
	curptr = strchr(curptr, '\0') + 1;
	strcpy(realm, curptr);
	
	return noErr;
	}

OSErr	GetNthServer(const int n, const char *realm, const int mustadmin,
										char *server)
{
	int	numservers = *(short*)*fServerMap, i = 0;
	char	*currealm, *curserver;
	
	currealm = (*fServerMap) + 2;
	curserver = strchr(currealm, '\0') + 1 + 1;
	for( ; numservers > 0; numservers--) {
		if(!strcmp(currealm, realm)) {
			if(!mustadmin || *(curserver-1)) i++;
			if(i >= n) {
				strcpy(server, curserver);
				return noErr;
				}
			}
		
		if(numservers > 1) {
			currealm = strchr(curserver, '\0') + 1;
			curserver = strchr(currealm, '\0') + 1 + 1;
			}
		}

	return cKrbMapDoesntExist;
	}

OSErr	AddServerMap(const char *realm, const char *server,
										const int isadmin)
{
	int	numservers;
	char	*curptr;
	
	SetHandleSize(fServerMap, strlen(realm)+1 + 1 + strlen(server)+1 +
										GetHandleSize(fServerMap));
	if(MemError()) return MemError();
	
	numservers = ++(*((short *)*fServerMap));
	
	for(curptr = (*fServerMap)+2; numservers > 1; numservers--) {
		curptr = strchr(curptr, '\0') + 1 + 1;
		curptr = strchr(curptr, '\0') + 1;
		}
	
	strcpy(curptr, realm);
	curptr = strchr(curptr, '\0') + 1;
	*curptr = (char) isadmin;
	curptr++;
	strcpy(curptr, server);
	
	return WriteServerMap();
	}

OSErr	DeleteServerMap(const char *realm, const char *server)
{
	int	numservers = *((short *)*fServerMap);
	char	*curptr, *fromptr, *nextptr;
		
	for(curptr = (*fServerMap)+2; numservers > 0; numservers--) {
		if(!strcmp(curptr, realm)) {
			nextptr = strchr(curptr, '\0') + 1 + 1;
			if(!strcasecmp(nextptr, server)) {
				break;	/* got it! */
				}
			}
		
		curptr = strchr(curptr, '\0') + 1 + 1;
		curptr = strchr(curptr, '\0') + 1;
		}
	
	if(numservers == 0) return cKrbMapDoesntExist;
	
	*(short*)*fServerMap -= 1;
	
	if(numservers > 1) {
		fromptr = strchr(curptr, '\0') + 1 + 1;
		fromptr = strchr(fromptr, '\0') + 1;
		}
	
	for( ; numservers > 1; numservers--) {
		nextptr = strchr(fromptr, '\0') + 1;
		strcpy(curptr, fromptr);
		curptr = strchr(curptr, '\0') + 1;
		fromptr = nextptr;
		
		*curptr = *fromptr;
		curptr++;
		fromptr++;
		
		nextptr = strchr(fromptr, '\0') + 1;
		strcpy(curptr, fromptr);
		curptr = strchr(curptr, '\0') + 1;
		fromptr = nextptr;
		}
	
	SetHandleSize(fServerMap, curptr-(*fServerMap));
	if(MemError()) return MemError();
	return WriteServerMap();
	}

OSErr	GetNthServerMap(const int n, char *realm, char *server, int *admin)
{
	int	i;
	char	*curptr;
	
	if(n > *(short*)*fServerMap) return cKrbMapDoesntExist;
	
	for(curptr = (*fServerMap) + 2, i = 1; i < n; i++) {
		curptr = strchr(curptr, '\0') + 1 + 1;
		curptr = strchr(curptr, '\0') + 1;
		}
	
	strcpy(realm, curptr);
	curptr = strchr(curptr, '\0') + 1;
	*admin = *curptr;
	curptr++;
	strcpy(server, curptr);
	
	return noErr;
}