1: static char sccsid[] = "@(#)environ.c 4.1 (Berkeley) 9/12/82";
2:
3: /* sccs id variable */
4: static char *env_sid = "@(#)environ.c 1.2";
5:
6: # include "defs.h"
7:
8: /*
9: environ.c
10:
11: examine the environment variables and see if they
12: have network login name and password information
13: */
14:
15: envloginpasswd(mch,sn,spasswd)
16: register char *sn, *spasswd;{
17: register char *senv;
18: char stemp[30], fgetlogin;
19: char *envlook();
20: # ifdef V6
21: return; /* doesn't work on V6 */
22: # endif
23: senv = envlook(mch);
24: if(senv == NULL)return;
25: if(!isalpha(senv[0]))return; /* not login name, ignore */
26: fgetlogin = (sn[0] == 0);
27: while(*senv && *senv != ','){
28: if(fgetlogin)*sn++ = *senv;
29: else if(*sn++ != *senv)return;
30: senv++;
31: }
32: strcpy(stemp,++senv);
33: mkpwclear(stemp,mch,spasswd);
34: }
35: extern char **environ;
36: char *envlook(mch){
37: static char svalue[100];
38: register char *s, *sv, **env;
39: env = environ;
40: while(*env != NULL){
41: s = *env++;
42: if(s[0] == 'M' && s[1] == 'A' && s[2] == 'C' && s[3] == 'H'){
43: sv = s+4;
44: while(*sv && *sv != '=')sv++;
45: *sv++ = 0;
46: if(lookup(s+4) == mch){
47: strcpy(svalue,sv);
48: return(svalue);
49: }
50: }
51: }
52: return(NULL);
53: }
54: /*
55: reverse the sfrom string, copying into sto.
56: sfrom and sto may not be the same string
57: */
58: sreverse(sto,sfrom)
59: register char *sto, *sfrom;
60: {
61: register int i;
62: i = strlen(sfrom);
63: while(i >= 0)
64: *sto++ = sfrom[i--];
65: }
66: /*
67: mkenvkey
68:
69: make key to encrypt environment passwds.
70: return NULL if error
71: */
72: static char *mkenvkey(mch)
73: char mch;
74: {
75: static char skey[40];
76: register struct utmp *putmp;
77: char stemp[40], stemp1[40], sttyname[30];
78: register char *sk,*p;
79:
80: if(isatty(2))strcpy(sttyname,ttyname(2));
81: else if(isatty(0))strcpy(sttyname,ttyname(0));
82: else if(isatty(1))strcpy(sttyname,ttyname(1));
83: else return(NULL);
84: putmp = getutmp(sttyname);
85: if(putmp == NULL) return(NULL);
86: sk = skey;
87: p = putmp->ut_line;
88: while(*p)*sk++ = *p++;
89: *sk++ = mch;
90: sprintf(stemp,"%ld",putmp->ut_time);
91: sreverse(stemp1,stemp);
92: p = stemp1;
93: while(*p)*sk++ = *p++;
94: *sk = 0;
95: return(skey);
96: }
97: /*
98: make an encrypted passwd
99: */
100: mkpwunclear(spasswd,mch,sencpasswd)
101: char mch,*spasswd,*sencpasswd;
102: {
103: register char *skey;
104: if(spasswd[0] == 0){
105: sencpasswd[0] = 0;
106: return;
107: }
108: skey = mkenvkey(mch);
109: if(skey == NULL){
110: fprintf(stderr,"Can't make key\n");
111: exit(EX_OSERR);
112: }
113: nbsencrypt(spasswd,skey,sencpasswd);
114: }
115: /*
116: make an unecrypted passwd
117: */
118: mkpwclear(sencpasswd,mch,spasswd)
119: char mch,*spasswd,*sencpasswd;
120: {
121: register char *skey;
122: if(sencpasswd[0] == 0){
123: spasswd[0] = 0;
124: return;
125: }
126: skey = mkenvkey(mch);
127: if(skey == NULL){
128: fprintf(stderr,"Can't make key\n");
129: exit(EX_OSERR);
130: }
131: nbsdecrypt(sencpasswd,skey,spasswd);
132: }
Defined functions
Defined variables
sccsid
defined in line
1;
never used