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

Defined functions

envlook defined in line 30; used 2 times
mkenvkey defined in line 66; used 2 times
mkpwclear defined in line 112; used 1 times
  • in line 27
mkpwunclear defined in line 94; used 1 times
sreverses defined in line 52; never used
Last modified: 1980-07-16
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 965
Valid CSS Valid XHTML 1.0 Strict