mirror of
https://github.com/GnoConsortium/gno.git
synced 2024-06-01 06:41:31 +00:00
newuser.c:
reformatted source; no substantive changes
This commit is contained in:
parent
d9d4770f9f
commit
68d2224e5b
|
@ -79,21 +79,18 @@ void time_out(void)
|
|||
|
||||
/* Borrowed from Eric's passwd.cc */
|
||||
|
||||
void makesalt(char *salt, long seed)
|
||||
|
||||
void
|
||||
makesalt(char *salt, long seed)
|
||||
{
|
||||
int num = 2;
|
||||
while (--num >= 0)
|
||||
|
||||
{
|
||||
while (--num >= 0) {
|
||||
*salt++ = salttab[seed&0x3f];
|
||||
seed >= 6;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int get_next_uid(void)
|
||||
|
||||
int
|
||||
get_next_uid(void)
|
||||
{
|
||||
FILE *FPtr;
|
||||
int uid;
|
||||
|
@ -107,8 +104,8 @@ int get_next_uid(void)
|
|||
return(uid);
|
||||
}
|
||||
|
||||
void getpassword(char *password, char *salt, char *passstring)
|
||||
|
||||
void
|
||||
getpassword(char *password, char *salt, char *passstring)
|
||||
{
|
||||
char *pass, *passcode;
|
||||
|
||||
|
@ -117,8 +114,8 @@ void getpassword(char *password, char *salt, char *passstring)
|
|||
strcpy(password,passcode);
|
||||
}
|
||||
|
||||
int bad_name(char *acct_name)
|
||||
|
||||
int
|
||||
bad_name(char *acct_name)
|
||||
{
|
||||
if (!isalpha(*acct_name++))
|
||||
return(TRUE);
|
||||
|
@ -130,8 +127,8 @@ int bad_name(char *acct_name)
|
|||
return(FALSE);
|
||||
}
|
||||
|
||||
void myfgets(char *string, int maxchar, FILE *FilePtr)
|
||||
|
||||
void
|
||||
myfgets(char *string, int maxchar, FILE *FilePtr)
|
||||
{
|
||||
int last_char;
|
||||
char *tmp_buf;
|
||||
|
@ -156,27 +153,26 @@ void myfgets(char *string, int maxchar, FILE *FilePtr)
|
|||
|
||||
/* try multiple times to open /etc/passwd file */
|
||||
|
||||
FILE *smartopen(char *file, char *mode)
|
||||
|
||||
FILE *
|
||||
smartopen(char *file, char *mode)
|
||||
{
|
||||
FILE *FOutPtr;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < MAX_TRIES; i++)
|
||||
|
||||
{
|
||||
for (i = 0; i < MAX_TRIES; i++) {
|
||||
FOutPtr = fopen(file,mode);
|
||||
if (FOutPtr == NULL)
|
||||
if (FOutPtr == NULL) {
|
||||
sleep(1);
|
||||
else
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return(FOutPtr);
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
int validate, uid;
|
||||
FILE *FInPtr, *FOutPtr;
|
||||
|
@ -207,18 +203,14 @@ int main (int argc, char **argv)
|
|||
|
||||
/* Make sure all required files exist before going any further */
|
||||
|
||||
if ((FInPtr = fopen(NEWID_FILE,"r+")) == NULL)
|
||||
|
||||
{
|
||||
if ((FInPtr = fopen(NEWID_FILE,"r+")) == NULL) {
|
||||
fprintf(stderr,"unable to open %s; exiting.\n",NEWID_FILE);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fclose(FInPtr);
|
||||
|
||||
if ((FInPtr = fopen(NEWGSHRC_FILE,"r+")) == NULL)
|
||||
|
||||
{
|
||||
if ((FInPtr = fopen(NEWGSHRC_FILE,"r+")) == NULL) {
|
||||
fprintf(stderr,"unable to open %s; exiting.\n",NEWGSHRC_FILE);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -238,25 +230,20 @@ int main (int argc, char **argv)
|
|||
/* must start with a character and may only contain letters */
|
||||
/* and numbers. */
|
||||
|
||||
while(1)
|
||||
|
||||
{
|
||||
while(1) {
|
||||
printf("Login Name: ");
|
||||
myfgets(acct_name,ACCT_NAME_LEN,stdin);
|
||||
printf("\n\n(login name: '%s')\n\n",acct_name);
|
||||
if (getpwnam(acct_name) != NULL)
|
||||
if (getpwnam(acct_name) != NULL) {
|
||||
printf("Duplicate username: please choose another.\n");
|
||||
else if (bad_name(acct_name))
|
||||
|
||||
{
|
||||
} else if (bad_name(acct_name)) {
|
||||
printf("\n** Invalid username: please choose a name comprised of\n");
|
||||
printf(" alphanumeric characters which starts with an alphabetic\n");
|
||||
printf(" character.\n");
|
||||
}
|
||||
|
||||
else
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Terminal Type: ");
|
||||
myfgets(term_type,TERM_TYPE_LEN,stdin);
|
||||
|
@ -264,16 +251,15 @@ int main (int argc, char **argv)
|
|||
/* Get password of > 4 chars, with verification */
|
||||
|
||||
makesalt(salt, rand());
|
||||
while(1)
|
||||
|
||||
{
|
||||
while(1) {
|
||||
getpassword(pass1,salt,"Password: ");
|
||||
getpassword(pass2,salt,"Verify: ");
|
||||
if (!strcmp(pass1,pass2) && (strlen(pass1) > 4))
|
||||
if (!strcmp(pass1,pass2) && (strlen(pass1) > 4)) {
|
||||
break;
|
||||
else
|
||||
} else {
|
||||
printf("*** Failed verification.\n");
|
||||
}
|
||||
}
|
||||
|
||||
uid = get_next_uid(); /* get and update next free ID# */
|
||||
|
||||
|
@ -290,32 +276,30 @@ int main (int argc, char **argv)
|
|||
|
||||
FInPtr = fopen(NEWGSHRC_FILE,"r");
|
||||
|
||||
while(fgets(buffer,80,FInPtr) != NULL)
|
||||
while(fgets(buffer,80,FInPtr) != NULL) {
|
||||
fputs(buffer,FOutPtr);
|
||||
}
|
||||
fclose(FInPtr);
|
||||
|
||||
/* update default gshrc to have correct $home, $user, and $term */
|
||||
|
||||
/* Phil asked that this be removed, so... :)
|
||||
/* Phil asked that this be removed, so... :) */
|
||||
#if 0
|
||||
fprintf(FOutPtr,"set home=/user/%s\n",acct_name);
|
||||
fprintf(FOutPtr,"set user=%s\n",acct_name);
|
||||
*/
|
||||
|
||||
#endif
|
||||
fprintf(FOutPtr,"set term=%s\n",term_type);
|
||||
|
||||
/*
|
||||
#if 0
|
||||
fprintf(FOutPtr,"export home user term\n");
|
||||
*/
|
||||
#else
|
||||
fprintf(FOutPtr,"export term\n");
|
||||
#endif
|
||||
fclose(FOutPtr);
|
||||
|
||||
if (!validate) /* no validation, so append new entry to /etc/passwd */
|
||||
|
||||
{
|
||||
if (!validate) { /* no validation, so append new entry to /etc/passwd */
|
||||
FOutPtr = smartopen("/etc/passwd","a");
|
||||
if (FOutPtr == NULL)
|
||||
|
||||
{
|
||||
if (FOutPtr == NULL) {
|
||||
fprintf(stderr,"Trouble opening /etc/passwd file.\nExiting\n");
|
||||
exit(1);
|
||||
}
|
||||
|
@ -324,11 +308,9 @@ int main (int argc, char **argv)
|
|||
uid,DEFAULT_GID,name,acct_name);
|
||||
fclose(FOutPtr);
|
||||
printf("You may now log in.\n");
|
||||
}
|
||||
|
||||
else /* validation selected -- so append new entry to NEWUSERS_FILE */
|
||||
} else { /* validation selected -- so append new entry to NEWUSERS_FILE */
|
||||
|
||||
{
|
||||
FOutPtr = fopen(NEWUSERS_FILE,"a");
|
||||
fprintf(FOutPtr,"%s:%s:%d:0:%s:/user/%s:/bin/gsh\n",acct_name,pass1,
|
||||
uid,name,acct_name);
|
||||
|
|
Loading…
Reference in New Issue
Block a user