Пример #1
0
void
config_reader::read_config(debug_info& dbg_info, const char* file_nm){
#ifdef FULL_DEBUG
	bj_ostream& os = bj_out;
	CONFIG_CK(file_nm != NULL_PT);

	CONFIG_CK(dbg_info.dbg_start_dbg_entries.is_empty());
	CONFIG_CK(dbg_info.dbg_stop_dbg_entries.is_empty());
	CONFIG_CK(dbg_config_line.is_empty());

	//mini_test();

	std::ifstream in_stm;

	in_stm.open(file_nm, std::ios::binary);
	if(!in_stm.good() || !in_stm.is_open()){
		os << "NO " << file_nm << " FILE FOUND." << bj_eol;
		return;
	}

	ch_string str_ln;

	while(! in_stm.eof()){
		std::getline(in_stm, str_ln);
		
		add_config_line(dbg_info, str_ln);
	}
	in_stm.close();

	dbg_config_line.clear(false, true);

	dbg_info.dbg_start_dbg_entries.mix_sort(cmp_dbg_entries);
	dbg_info.dbg_stop_dbg_entries.mix_sort(cmp_dbg_entries);
	
	/*
	os << " FULL_DBG_CONFIG\n";
	os << dbg_info;
	os << " END_OF_FULL_DBG_CONFIG\n";
	*/
#endif
}
Пример #2
0
int do_useradd( u_info *user_info){
       
        FILE *fp;
        FILE *fp_out;
        char f_out[MAX_LINE ];
        char BUFFER[MAX_LINE ];
        
   if (user_info->login == NULL || *(user_info->login) == 0) {
        fprintf(stderr, "Missing login\n");
        return -1 ;
    }
        
    if (user_info->home == NULL || *(user_info->home) == 0) {
        fprintf(stderr, "Missing home directory\n");
        return -1 ;
    }
    sprintf(f_out,"%s%s",user_info->fconf,".tmp");
 
    if ((user_info->pwd = do_get_passwd()) == NULL) {
        fprintf(stderr, "Error with entering password - aborting\n");        
        return -1 ;
    }
     char *cleartext = user_info->pwd;

      user_info->pwd = ifw_crypt(cleartext);


    fp_out = fopen(f_out, "w+"); 
     if (!fp_out) {
         printf("\a error to open the temp file \n");
         return -1;
    }
 

    fp= fopen(user_info->fconf, "r");
       
      if (!fp) {
         printf("\a error to open the configuration file -> %s \n",user_info->fconf );
         return -1;
    }
 
    
 
     while (!feof(fp))
    {
     fscanf(fp, "%s\n", BUFFER);
     fprintf(fp_out, "%s\n", BUFFER);
    }
    
    if(add_config_line(fp_out, user_info) != 0) {
        fprintf(stderr, "Unable to append a line\n");
        fclose(fp);
        return -1;
    }
    
     fclose(fp_out);
     fclose(fp);
     
     rename(f_out,user_info->fconf);
     
      return 0;    
}
Пример #3
0
static int do_usermod(u_info *user_info)
{
 FILE *fp;
        FILE *fp_out;
        char f_out[MAX_LINE ];
        char BUFFER[MAX_LINE ];
        u_info tmp_u_info;
        static char line[MAX_LINE];

  if (user_info->login == NULL || *(user_info->login) == 0) {
        fprintf(stderr, "Missing login\n");
        return -1;
    }
    if (user_info->fconf == NULL) {
        fprintf(stderr, "Missing configuration file\n");
        return -1 ;
    }
    if (fetch_conf_account(user_info->fconf,&tmp_u_info, line, sizeof line,user_info->login) != 0) {
        fprintf(stderr, "Unable to fetch info about user [%s] in file [%s]\n",
                user_info->login, user_info->fconf);
        return -1;
    }

      
     do_userdel(user_info);


    if (user_info->pwd != NULL) {
        char *cleartext = user_info->pwd;

        tmp_u_info.pwd = ifw_crypt(cleartext);
        if (*cleartext != 0) {
            memset(cleartext, 0, strlen(cleartext));
        }        
    }

    if (user_info->uid > (uid_t) 0) {
        tmp_u_info.uid = user_info->uid;
    }
    if (user_info->gid > (gid_t) 0) {
        tmp_u_info.gid = user_info->gid;
    }
    if (user_info->home != NULL) {
        tmp_u_info.home = user_info->home;
    }
    
      sprintf(f_out,"%s%s",user_info->fconf,".tmp");

        fp_out = fopen(f_out, "w+"); 
     if (!fp_out) {
         printf("\a error to open the temp file \n");
         return -1;
    }
 

    fp= fopen(user_info->fconf, "r");
       
      if (!fp) {
         printf("\a error to open the configuration file -> %s \n",user_info->fconf );
         return -1;
    }
 
    
 
     while (!feof(fp))
    {
     fscanf(fp, "%s\n", BUFFER);
     fprintf(fp_out, "%s\n", BUFFER);
    }
    
    if(add_config_line(fp_out, &tmp_u_info) != 0) {
        fprintf(stderr, "Unable to append a line\n");
        fclose(fp);
        return -1;
    }
    
     fclose(fp_out);
     fclose(fp);
     
     rename(f_out,user_info->fconf);
     
      return 0; 

}