Ejemplo n.º 1
0
static char *do_get_passwd(void)
{
    static char pwd[LINE_MAX];
    char pwd2[LINE_MAX];    
    int tries = MAX_PASSWD_CHANGE_TRIES;
       
    *pwd = 0;
    *pwd2 = 0;
    
    again:
    printf("Password: "******"\nEnter it again: ");
    fflush(stdout);
    disable_echo();
    if (fgets(pwd2, (int) (sizeof pwd2 - 1U), stdin) == NULL) {
        enable_echo();
        return NULL;
    }
    strip_lf(pwd2);
    puts("");
    if (strcmp(pwd, pwd2) != 0) {
        if (*pwd2 != 0) {
            memset(pwd2, 0, strlen(pwd2));
        }
        if (*pwd != 0) {
            memset(pwd, 0, strlen(pwd));
        }
        puts("You didn't enter the same password");
        if (--tries > 0) {
            goto again;
        }
        enable_echo();
        
        return NULL;
    }
    if (*pwd2 != 0) {
        memset(pwd2, 0, strlen(pwd2));
    }
    enable_echo();
    
    return pwd;
}
Ejemplo n.º 2
0
static int do_list(const char * const file)
{
    FILE *fp;
    PWInfo pwinfo;
    char line[LINE_MAX];    
    
    if (file == NULL) {
        fprintf(stderr, "missing file to list accounts\n");
        return PW_ERROR_MISSING_PASSWD_FILE;
    }
    if ((fp = fopen(file, "r")) == NULL) {
        perror("Unable to open the passwd file");
        return PW_ERROR_MISSING_PASSWD_FILE;        
    }
    while (fgets(line, (int) sizeof line - 1U, fp) != NULL) {
        strip_lf(line);
        if (*line == 0 || *line == PW_LINE_COMMENT) {
            continue;
        }
        if (parse_pw_line(line, &pwinfo) != 0) {
            fprintf(stderr, "Warning: invalid line [%s]\n", line);
            continue;
        }
        if (isatty(1)) {
            printf("%-19s %-39s %-19s\n", pwinfo.login, pwinfo.home, pwinfo.gecos);
        } else {
            printf("%s\t%s\t%s\n", pwinfo.login, pwinfo.home, pwinfo.gecos);            
        }
    }
    fclose(fp);

    return 0;
}
Ejemplo n.º 3
0
void hot_reg(char *block)
{
 char *nptr;
 int i;

 strip_lf(block);
 nptr=block;
 if(!stricmp(block, special_key))
  in_key=0;
 for(i=0; i<8; i++)
 {
  nptr=ltrim(nptr);
  *(long *)&regdata[REG_HDR_SHIFT+i*4]=strtoul(nptr, &nptr, 10);
 }
 nptr=ltrim(nptr);
 for(i=0; *nptr!=' '&&*nptr!='\0'&&i<REG_KEY1_LEN; i++)
  regdata[REG_KEY1_SHIFT+i]=*nptr++;
 regdata[REG_KEY1_SHIFT+i]='\0';
 nptr=ltrim(nptr);
 for(i=0; *nptr!=' '&&*nptr!='\0'&&i<REG_KEY2_LEN; i++)
  regdata[REG_KEY2_SHIFT+i]=*nptr++;
 regdata[REG_KEY2_SHIFT+i]='\0';
 nptr=ltrim(nptr);
 for(i=0; *nptr!='\0'&&i<REG_NAME_LEN; i++)
  regdata[REG_NAME_SHIFT+i]=*nptr++;
 regdata[REG_NAME_SHIFT+i]='\0';
 alltrim(regdata+REG_KEY1_SHIFT);
}
Ejemplo n.º 4
0
static int do_list(u_info *user_info)
{
    FILE *fp;
    u_info tmp_u_info ;
    char line[MAX_LINE];    
    
    if (user_info->fconf == NULL) {
        fprintf(stderr, "missing file to list accounts\n");
        return -1;
    }
    if ((fp = fopen(user_info->fconf, "r")) == NULL) {
        perror("error to open the configuration file ... ");
        return -1;        
    }
    while (fgets(line, (int) sizeof line - 1U, fp) != NULL) {
        strip_lf(line);
        if (*line == 0 || *line == '#') {
            continue;
        }
        if (parse_config_line(line, &tmp_u_info) != 0) {
            fprintf(stderr, "Warning: invalid line [%s]\n", line);
            continue;
        }
        if (isatty(1)) {
            printf("%-19s %-39s \n", tmp_u_info.login, tmp_u_info.home);
        } else {
            printf("%s\t%s\n", tmp_u_info.login, tmp_u_info.home);            
        }
    }
    fclose(fp);

    return 0;
}
Ejemplo n.º 5
0
int do_userdel( u_info *user_info){
    
        FILE *fp;
        FILE *fp_out;
        char fout  [MAX_LINE];
        char buffer[MAX_LINE];
        char tmp   [MAX_LINE];

 
    sprintf(fout,"%s%s",user_info->fconf,".tmp");
  

    fp_out = fopen(fout, "w"); 
     if (!fp_out) {
         printf("\a error : not open temp file \n");
         return -1;
    }
    

    fp= fopen(user_info->fconf, "r");
       
    if (!fp) {
         printf(" error : not open config file \n");
         return -1;
    }
    
       while(fgets(tmp, sizeof(tmp),fp)) {
       char *line, *c ;
 
        strip_lf(c);

        strcpy(buffer,tmp);
        /* find the word in the buffer */
        line = tmp;

   if ((line = strtok(line,":")) == NULL || *line == 0)   /* account */
        return -1;
   
    if(strcmp(line,user_info->login)) 
           fprintf(fp_out, "%s\n", buffer); 
          
            
     }
            
    fclose(fp_out);
    fclose(fp);
    rename(fout,user_info->fconf);
    return 0;

}
Ejemplo n.º 6
0
static int fetch_pw_account(const char * const file, PWInfo * const pwinfo,
                            char * const line, const size_t sizeof_line,
                            const char * const login)
{
    FILE *fp;
    int ret = -1;
    
    if (file == NULL || pwinfo == NULL || line == NULL ||
        sizeof_line < (size_t) 2U || login == NULL ||
        *login == 0) {
        fprintf(stderr, "bad arguments to fetch account\n");
        return -1;
    }
    if ((fp = fopen(file, "r")) == NULL) {
        perror("Unable to open the passwd file");
        return -1;
    }
    while (fgets(line, (int) sizeof_line - 1U, fp) != NULL) {
        strip_lf(line);
        if (*line == 0 || *line == PW_LINE_COMMENT) {
            continue;
        }
        if (parse_pw_line(line, pwinfo) != 0) {
            fprintf(stderr, "Warning: invalid line [%s]\n", line);
            continue;
        }
        if (strcmp(login, pwinfo->login) != 0) {
            continue;
        }
        ret = 0;
        break;
    }
    fclose(fp);

    return ret;
}
Ejemplo n.º 7
0
static int do_mkdb(const char *dbfile, const char * const file)
{
    FILE *fp;
    char *index_dbfile;
    size_t sizeof_index_dbfile;
    char *data_dbfile;
    size_t sizeof_data_dbfile;
    char *s;
    PureDBW dbw;
    int ret = PW_ERROR_UNEXPECTED_ERROR;
    char line[LINE_MAX];
    
    if (dbfile == NULL || *dbfile == 0) {
        char *dbfile_;
        
        if ((dbfile_ = getenv(ENV_DEFAULT_PW_DB)) != NULL && *dbfile_ != 0) {
            dbfile = dbfile_;
        } else {        
            dbfile = DEFAULT_PW_DB;
        }
    }
    if (file == NULL) {
        fprintf(stderr, "Missing passwd file\n");
        return PW_ERROR_MISSING_PASSWD_FILE;
    }    
    if ((fp = fopen(file, "r")) == NULL) {
        perror("Unable to open the passwd file");
        return PW_ERROR_MISSING_PASSWD_FILE;
    }
    sizeof_index_dbfile = strlen(dbfile) + sizeof NEWPASSWD_INDEX_SUFFIX;
    if ((index_dbfile = ALLOCA(sizeof_index_dbfile)) == NULL) {
        fclose(fp);
        no_mem();
    }
    sizeof_data_dbfile = strlen(dbfile) + sizeof NEWPASSWD_DATA_SUFFIX;
    if ((data_dbfile = ALLOCA(sizeof_data_dbfile)) == NULL) {
        fclose(fp);
        ALLOCA_FREE(index_dbfile);
        no_mem();
    }
    snprintf(index_dbfile, sizeof_index_dbfile, "%s%s",
             dbfile, NEWPASSWD_INDEX_SUFFIX);
    snprintf(data_dbfile, sizeof_data_dbfile, "%s%s",
             dbfile, NEWPASSWD_DATA_SUFFIX);
    if (puredbw_open(&dbw, index_dbfile, data_dbfile, dbfile) != 0) {
        perror("Unable to create the database");
        goto err;
    }
    while (fgets(line, (int) sizeof line - 1U, fp) != NULL) {
        strip_lf(line);
        if (*line == PW_LINE_COMMENT) {
            continue;
        }
        if (*line == 0 || (s = strchr(line, *PW_LINE_SEP)) == NULL ||
            s[1] == 0) {
            continue;
        }
        *s++ = 0;
        if (puredbw_add_s(&dbw, line, s) != 0) {
            perror("Error while indexing a new entry");
            goto err;
        }
    }
    if (puredbw_close(&dbw) != 0) {
        perror("Unable to close the database");
    } else {
        ret = 0;
    }
    err:
    puredbw_free(&dbw);
    ALLOCA_FREE(index_dbfile);
    ALLOCA_FREE(data_dbfile);    
    fclose(fp);
    
    return ret;
}
Ejemplo n.º 8
0
static void cnv_cmdline_fnm(char *name)
{
 strip_lf(name);
 alltrim(name);
}