/* change password or add user to S/KEY authentication system.
* S/KEY is a tradmark of Bellcore */
int skeylookup
__P((struct skey
*mp
,char *name
));
int rval
,n
,nn
,i
,defaultsetup
;
char seed
[18],tmp
[80],key
[8];
struct passwd
*ppuser
,*pp
;
char defaultseed
[17], passwd
[256],passwd2
[256] ;
#if 0 /* Choose a more random seed */
strftime(tbuf
, sizeof(tbuf
), "%M%j", tm
);
sprintf(tbuf
, "%05ld", (long) (now
% 100000));
gethostname(defaultseed
,NAMELEN
);
strcpy(&defaultseed
[NAMELEN
],tbuf
);
pp
= ppuser
= getpwuid(getuid());
if(strcmp("-s", argv
[1]) == 0)
printf("User unknown\n");
if(strcmp( pp
->pw_name
,me
) != 0){
/* Only root can change other's passwds */
printf("Permission denied.\n");
rval
= skeylookup(&skey
,pp
->pw_name
);
perror("error in opening database");
printf("Updating %s:\n",pp
->pw_name
);
printf("Old key: %s\n",skey
.seed
);
/* lets be nice if they have a skey.seed that ends in 0-8 just add one*/
if( isdigit(lastc
) && lastc
!= '9' ){
strcpy(defaultseed
, skey
.seed
);
defaultseed
[l
-1] = lastc
+ 1;
if( isdigit(lastc
) && lastc
== '9' && l
< 16){
strcpy(defaultseed
, skey
.seed
);
printf("Adding %s:\n",pp
->pw_name
);
printf("Reminder you need the 6 english words from the skey command.\n");
printf("Enter sequence count from 1 to 10000: ");
fgets(tmp
,sizeof(tmp
),stdin
);
printf("Count must be > 0 and < 10000\n");
printf("Enter new key [default %s]: ", defaultseed
);
fgets(seed
,sizeof(seed
),stdin
);
printf("Seed truncated to 16 chars\n");
if( seed
[0] == '\0') strcpy(seed
,defaultseed
);
printf("s/key %d %s\ns/key access password: ",n
,seed
);
fgets(tmp
,sizeof(tmp
),stdin
);
printf("Enter 6 English words from secure S/Key calculation.\n");
if(etob(key
,tmp
) == 1 || atob8(key
,tmp
) == 0)
break; /* Valid format */
printf("Invalid format, try again with 6 English words.\n");
/* Get user's secret password */
fprintf(stderr
,"Reminder - Only use this method if you are directly connected.\n");
fprintf(stderr
,"If you are using telnet or rlogin exit with no password and use keyinit -s.\n");
fprintf(stderr
,"Enter secret password: ");
readpass(passwd
,sizeof(passwd
));
fprintf(stderr
,"Again secret password: ");
readpass(passwd2
,sizeof(passwd
));
if(strlen(passwd
) < 4 && strlen(passwd2
) < 4) {
fprintf(stderr
, "Sorry your password must be longer\n\r");
if(strcmp(passwd
,passwd2
) == 0) break;
fprintf(stderr
, "Sorry no match\n");
strcpy(seed
,defaultseed
);
/* Crunch seed and password into starting key */
if(keycrunch(key
,seed
,passwd
) != 0){
fprintf(stderr
,"%s: key crunch failed\n",argv
[0]);
strftime(tbuf
, sizeof(tbuf
), " %b %d,%Y %T", tm
);
skey
.val
= (char *) malloc(16+1);
fprintf(skey
.keyfile
,"%s %04d %-16s %s %-21s\n",pp
->pw_name
,n
,
printf("\nID %s s/key is %d %s\n",pp
->pw_name
,n
,seed
);
printf("%s\n",btoe(buf
,key
));
printf("%s\n",put8(buf
,key
));