|
|
1.1 root 1:
2: /* $Header: simpleauth.c,v 2.3 87/03/23 10:29:12 ed Exp $
3:
4: /* this module of authentication support contains:
5: * MakeSimpleCredsAndVerifier
6: * GetSimpleCredsAndVerifier
7: * MakeSimpleVerifier
8: */
9:
10: /* $Log: simpleauth.c,v $
11: * Revision 2.3 87/03/23 10:29:12 ed
12: * Added alternate GetSimpleCredsAndVerifier to interface with
13: * environment variable credentials.
14: *
15: * Revision 2.2 86/12/10 17:00:49 ed
16: * Create MakeSimpleVerifier as separate routine.
17: *
18: * Revision 2.1 86/06/30 12:22:25 jqj
19: * convert to Authentication v 2.
20: *
21: * Revision 2.0 85/11/21 07:22:26 jqj
22: * 4.3BSD standard release
23: *
24: * Revision 1.1 85/03/26 06:29:11 jqj
25: * Initial revision
26: *
27: * Revision 1.1 85/03/26 06:29:11 jqj
28: * Initial revision
29: *
30: */
31:
32: #include <xnscourier/Authentication2.h>
33: #include <ctype.h>
34:
35: Cardinal
36: hashpass(hpw)
37: char *hpw;
38: {
39: register unsigned long hash;
40: register char c;
41:
42: hash = 0;
43: while ((c = *hpw++) != '\0') {
44: hash = (hash<<16) + (isupper(c) ? tolower(c) : c);
45: hash %= 65357;
46: }
47: return((Cardinal) hash);
48: }
49:
50:
51: /*
52: * Given an XNS name and password, return the appropriate
53: * credentials and verifier associated with that name.
54: * Per Authentication Protocol, XSIS ....
55: */
56:
57: MakeSimpleCredsAndVerifier(name, pwd, credentials, verifier)
58: Authentication2_Clearinghouse_Name *name;
59: /* the XNS user, in 3 fields */
60: char *pwd; /* password, a UNIX string */
61: Authentication2_Credentials *credentials;
62: /* the simple credentials to be returned */
63: Authentication2_Verifier *verifier;
64: /* associated verifier, i.e. HashedPassword */
65: {
66: Cardinal length;
67: Unspecified *data, *buf, *seq;
68: static Authentication2_Clearinghouse_Name nullname = {"","",""};
69:
70: /* first, validate arguments */
71: if (name == 0) name = &nullname;
72: if (pwd == 0) pwd="";
73: /* note we do NOT check that things are of appropriate types */
74:
75: if (credentials != 0) {
76: credentials->type = Authentication2_simpleCredentials;
77: length = sizeof_Authentication2_Clearinghouse_Name(name);
78: data = Allocate(length);
79: (void) externalize_Authentication2_Clearinghouse_Name(name,data);
80: seq = credentials->value.sequence = Allocate(length);
81: credentials->value.length = length;
82: buf = data;
83: for ( ; length > 0; length--, seq++)
84: buf += internalize_Unspecified(seq, buf);
85: free(data);
86: }
87: if (verifier != 0) {
88: verifier->length = 1;
89: verifier->sequence = Allocate(sizeof_Unspecified(0));
90: verifier->sequence[0] = (Unspecified) hashpass(pwd);
91: }
92: }
93:
94:
95: /*
96: * new style: name and pwd are returned
97: */
98:
99: GetSimpleCredsAndVerifier(name, pwd, credentials, verifier)
100: Authentication2_Clearinghouse_Name *name;
101: /* the XNS user, in 3 fields */
102: Cardinal *pwd; /* password, a hashed Cardinal */
103: Authentication2_Credentials *credentials;
104: /* the simple credentials to be returned */
105: Authentication2_Verifier *verifier;
106: /* associated verifier, i.e. HashedPassword */
107: {
108: Cardinal length;
109: char *uname;
110: Cardinal *upwd, dummypwd;
111: Unspecified *data, *buf, *seq;
112: Unspecified buff[100];
113: static Authentication2_Clearinghouse_Name username;
114: static Authentication2_Clearinghouse_Name dummyname = {"","",""};
115: Authentication2_Clearinghouse_Name defaultobjname, CH_StringToName();
116:
117: if (name == 0) name= &dummyname;
118: if (pwd == 0) pwd= &dummypwd;
119: /* note we do NOT check that things are of appropriate types */
120:
121: CH_NameDefault(&defaultobjname);
122: getXNSuser(&uname, &upwd);
123: username= CH_StringToName(uname, &defaultobjname);
124:
125: externalize_Authentication2_Clearinghouse_Name(&username, buff);
126: internalize_Authentication2_Clearinghouse_Name(name, buff);
127: *pwd= *upwd;
128:
129: if (credentials != 0) {
130: credentials->type = Authentication2_simpleCredentials;
131: length = sizeof_Authentication2_Clearinghouse_Name(&username);
132: data = Allocate(length);
133: (void) externalize_Authentication2_Clearinghouse_Name(&username,data);
134: seq = credentials->value.sequence = Allocate(length);
135: credentials->value.length = length;
136: buf = data;
137: for ( ; length > 0; length--, seq++)
138: buf += internalize_Unspecified(seq, buf);
139: free(data);
140: }
141: if (verifier != 0) {
142: verifier->length = 1;
143: verifier->sequence = Allocate(sizeof_Unspecified(0));
144: verifier->sequence[0] = (Unspecified) *upwd;
145: }
146: }
147:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.