|
|
1.1 root 1: #ifndef lint
2: static char *rcsid = "$Header: CHusername.c,v 1.1 87/05/11 09:59:41 ed Exp $";
3: #endif lint
4:
5: /* contains:
6: * CH_NameToUser
7: */
8:
9: #ifndef CHUSERIDFILE
10: #define CHUSERIDFILE "/usr/new/lib/xnscourier/chusermap"
11: #endif
12:
13: #include <stdio.h>
14: #include <sys/types.h>
15: #include <netns/ns.h>
16: #include <xnscourier/Clearinghouse2.h>
17: #include <ctype.h>
18: #include <ndbm.h>
19: extern char *rindex(), *CH_NameToString();
20:
21: /*
22: * produce a UNIX user name by table lookup given a CHS name
23: */
24: char *
25: CH_NameToUser(chs_name)
26: Clearinghouse2_ThreePartName chs_name;
27: {
28: static char userid[12];
29: DBM *db;
30: datum cptr, uptr;
31: register char *ptr;
32: Clearinghouse2_ObjectName chdefault;
33: FILE *dbf;
34: char charbuf[100];
35: int n;
36:
37: uptr.dptr = NULL;
38: cptr.dptr = CH_NameToString(chs_name);
39: for (ptr =cptr.dptr; *ptr != '\0'; ptr++)
40: if (islower(*ptr)) *ptr = toupper(*ptr);
41:
42: /* lookup user id in hashed database */
43: if ( (db= dbm_open(CHUSERIDFILE, 0, 0)) != (DBM*)0 ) {
44: cptr.dsize = strlen(cptr.dptr);
45: uptr = dbm_fetch(db, cptr);
46: dbm_close(db);
47: }
48: /* lookup user id in text database using linear search */
49: else if ( (dbf = fopen(CHUSERIDFILE, 0)) >= 0 ) {
50: while ((n=fscanf(dbf, "%[^\t\n]\t%s\n",charbuf,userid)) >= 0) {
51: if (n != 2) continue;
52: for (ptr=charbuf; *ptr != '\0'; ptr++)
53: if (islower(*ptr)) *ptr = toupper(*ptr);
54: if (strcmp(charbuf,cptr.dptr) == 0) {
55: uptr.dptr = userid;
56: break; /* found it! */
57: }
58: }
59: fclose(dbf);
60: }
61: if (uptr.dptr != NULL) return(uptr.dptr);
62:
63: /* default case */
64: chdefault.object = chdefault.domain = chdefault.organization = NULL;
65: CH_NameDefault(&chdefault);
66: if ( strcmp(chs_name.domain,chdefault.domain) != 0 ||
67: strcmp(chs_name.organization,chdefault.organization) != 0)
68: return("nobody");
69: else if ( (ptr= rindex(chs_name.object, ' ')) == 0 )
70: return(chs_name.object);
71: else
72: return(ptr+1);
73: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.