/** * Start SSL support library. It has to be run before the SSL support * can be used. * @return TRUE, or FALSE if an error has occured. */ static int start_ssl() { if (! ssl_initialized) { int i; int locks = CRYPTO_num_locks(); #ifdef OPENSSL_FIPS if (Run.fipsEnabled) enable_fips_mode(); #endif ssl_initialized = TRUE; ERR_load_crypto_strings(); ssl_mutex_table = xcalloc(locks, sizeof(pthread_mutex_t)); for (i = 0; i < locks; i++) pthread_mutex_init(&ssl_mutex_table[i], NULL); CRYPTO_set_id_callback(ssl_thread_id); CRYPTO_set_locking_callback(ssl_mutex_lock); SSL_library_init(); if (file_exist(URANDOM_DEVICE)) { return(RAND_load_file(URANDOM_DEVICE, RANDOM_BYTES)==RANDOM_BYTES); } else if (file_exist(RANDOM_DEVICE)) { DEBUG("Gathering entropy from the random device\n"); return(RAND_load_file(RANDOM_DEVICE, RANDOM_BYTES)==RANDOM_BYTES); } return FALSE; } return TRUE; }
/** * Search the system for the monit control file. Try first ~/.monitrc, * if that fails try /etc/monitrc, then SYSCONFDIR/monitrc (default: * /usr/local/etc/monitrc) and finally ./monitrc. * Exit the application if the control file was not found. * @return The location of monits control file (monitrc) */ char *file_findControlFile() { char *rcfile= xcalloc(sizeof(char), STRLEN + 1); snprintf(rcfile, STRLEN, "%s/.%s", Run.Env.home, MONITRC); if(file_exist(rcfile)) { return (rcfile); } memset(rcfile, 0, STRLEN); snprintf(rcfile, STRLEN, "/etc/%s", MONITRC); if(file_exist(rcfile)) { return (rcfile); } memset(rcfile, 0, STRLEN); snprintf(rcfile, STRLEN, "%s/%s", SYSCONFDIR, MONITRC); if(file_exist(rcfile)) { return (rcfile); } memset(rcfile, 0, STRLEN); snprintf(rcfile, STRLEN, "/usr/local/etc/%s", MONITRC); if(file_exist(rcfile)) { return (rcfile); } if(file_exist(MONITRC)) { memset(rcfile, 0, STRLEN); snprintf(rcfile, STRLEN, "%s/%s", Run.Env.cwd, MONITRC); return (rcfile); } LogError("%s: Cannot find the control file at " "~/.%s, /etc/%s, %s/%s, /usr/local/etc/%s or at ./%s \n", prog, MONITRC, MONITRC, SYSCONFDIR, MONITRC, MONITRC, MONITRC); exit(1); }
Read buf_next_line() { if (Read::Eof == this->mwrm_reader.read_meta_line(this->meta_line)) { return Read::Eof; } if (!file_exist(this->meta_line.filename)) { char original_path[1024] = {}; char basename[1024] = {}; char extension[256] = {}; char filename[2048] = {}; canonical_path( this->meta_line.filename , original_path, sizeof(original_path) , basename, sizeof(basename) , extension, sizeof(extension)); std::snprintf(filename, sizeof(filename), "%s%s%s", this->meta_path, basename, extension); if (file_exist(filename)) { strcpy(this->meta_line.filename, filename); } } return Read::Ok; }
int ntk_load_maps(void) { if (file_exist(server_opt.int_map_file) && (me.int_map = load_map(server_opt.int_map_file, &me.cur_node))) debug(DBG_NORMAL, "Internal map loaded"); else me.int_map = init_map(0); #if 0 /* Don't load the bnode map, it's useless */ if ((me.bnode_map = load_bmap(server_opt.bnode_map_file, me.ext_map, FAMILY_LVLS, &me.bmap_nodes))) { debug(DBG_NORMAL, "Bnode map loaded"); } else #endif bmap_levels_init(BMAP_LEVELS(FAMILY_LVLS), &me.bnode_map, &me.bmap_nodes); bmap_counter_init(BMAP_LEVELS(FAMILY_LVLS), &me.bmap_nodes_closed, &me.bmap_nodes_opened); if (file_exist(server_opt.ext_map_file) && (me.ext_map = load_extmap(server_opt.ext_map_file, &me.cur_quadg))) debug(DBG_NORMAL, "External map loaded"); else me.ext_map = init_extmap(FAMILY_LVLS, 0); return 0; }
void check_conflicting_options(void) { #define FATAL_NOT_SPECIFIED(str) fatal("You didn't specified the `%s' " \ "option in netsukuku.conf", \ (str)); \ if (!server_opt.pid_file) FATAL_NOT_SPECIFIED("pid_file"); if (!server_opt.inet_hosts && server_opt.restricted) FATAL_NOT_SPECIFIED("internet_ping_hosts"); if (server_opt.restricted && server_opt.share_internet && !file_exist(server_opt.ip_masq_script)) fatal("ip_masquerade_script \"%s\" is inexistent", server_opt.ip_masq_script); if (server_opt.shape_internet && !file_exist(server_opt.tc_shaper_script)) fatal("tc_shaper_script \"%s\" is inexistent", server_opt.ip_masq_script); if (!server_opt.restricted && server_opt.inet_connection) fatal("inet_connection=1 but ntk_restricted_mode=0. If you " "want to be compatible with the Internet, " "set the restricted mode in the options"); if (!server_opt.restricted && (server_opt.share_internet)) fatal("You want to share your Internet connection," "but I am not running in restricted mode (-r), " "'cause I'm not sure of what you want... " "I'm aborting."); if (server_opt.share_internet && me.my_bandwidth < MIN_CONN_BANDWIDTH) fatal("You want to share your Internet connection but " "your bandwidth is just TOO small. Do not share " "it, or your connection will be saturated"); if (!server_opt.inet_connection && server_opt.share_internet) { loginfo("You want to share your Internet connection," "but `internet_connection' is set to 0." "We are assuming it is 1"); server_opt.inet_connection = 1; } if (server_opt.shape_internet && !server_opt.inet_connection) fatal("The Internet traffic shaping option is set, but " "the `internet_connection' is set to 0, please check " "your options."); #ifdef IPV6_DISABLED if (server_opt.inet_gw.family == AF_INET6) fatal("Ipv6 is not supported"); #endif }
/** * Check if we should update current services with persistent state * information. The logic is as follows: Iff a state file is present * *and* older than the running monit daemon's lock file we have had a * crash and should update data from the state file. * @return TRUE if the state should be updated otherwise FALSE */ int State_shouldUpdate() { if(file_exist(Run.statefile) && file_exist(Run.pidfile)) { return (file_getTimestamp(Run.pidfile, S_IFREG) > file_getTimestamp(Run.statefile, S_IFREG)); } return FALSE; }
int main(int argc, char **argv) { if (argc != 3) { printf("ERROR: Incorrect number of inputs.\n"); exit(0); } char *index_file = argv[1]; char input[MAX_LEN]; if (file_exist(index_file)) { do { printf("There is already a file named \"%s\", would you like to overwrite this file? Enter yes/no:\n", index_file); scanf("%s", input); if (strcasecmp(input, "yes") == 0) { break; } else if (strcasecmp(input, "no") == 0) { do { printf("Choose another name: \n"); scanf("%s", input); index_file = input; } while(file_exist(index_file)); break; } } while (1); } StrMap *hashmap = sm_new(40); DIR *dir; struct dirent *dp; if ((dir = opendir(argv[2])) == NULL) { //if file FILE *fp = fopen(argv[2], "r"); filetok(fp, hashmap, argv[2]); printf("done\n"); fclose(fp); exit(0); } char *path = (char*)malloc(sizeof(argv[2]) + sizeof(char)); path = argv[2]; strcat(path, "/"); traverse(dir, path, hashmap); int x = sm_get_count(hashmap); printf("THIS IS HTE COUNT: %d\n", x); return 0; }
std::string findcow(const std::vector<std::string> &cowpath, const std::string &cow) { if (file_exist(cow)) return cow; for (auto i = cowpath.cbegin(); i < cowpath.cend(); ++i) { std::string check = *i + "/" + cow; if (file_exist(check)) return check; } if (endswith(cow, ".cow")) throw std::string("Cow exists not: ") + cow; return findcow(cowpath, cow + ".cow"); }
void mod_manager::load_mods_from(std::string path) { for( auto &mod_file : get_files_from_path(MOD_SEARCH_FILE, path, true) ) { load_mod_info( mod_file ); } if (file_exist(FILENAMES["mods-dev-default"])) { load_mod_info(FILENAMES["mods-dev-default"]); } if (file_exist(FILENAMES["mods-user-default"])) { load_mod_info(FILENAMES["mods-user-default"]); } }
void mod_manager::load_mods_from(std::string path) { std::vector<std::string> mod_files = file_finder::get_files_from_path(MOD_SEARCH_FILE, path, true); for (size_t i = 0; i < mod_files.size(); ++i) { load_mod_info(mod_files[i]); } if (file_exist(FILENAMES["mods-dev-default"])) { load_mod_info(FILENAMES["mods-dev-default"]); } if (file_exist(FILENAMES["mods-user-defaults"])) { load_mod_info(FILENAMES["mods-user-defaults"]); } }
void mod_manager::load_mods_from(std::string path) { std::vector<std::string> mod_files = file_finder::get_files_from_path(MOD_SEARCH_FILE, path, true); for (int i = 0; i < mod_files.size(); ++i) { load_mod_info(mod_files[i]); } if (file_exist(MOD_DEV_DEFAULT_PATH)) { load_mod_info(MOD_DEV_DEFAULT_PATH); } if (file_exist(MOD_USER_DEFAULT_PATH)) { load_mod_info(MOD_USER_DEFAULT_PATH); } }
std::string PATH_INFO::find_translated_file( const std::string &pathid, const std::string &extension, const std::string &fallbackid ) { const std::string base_path = FILENAMES[pathid]; #if defined LOCALIZE && ! defined __CYGWIN__ std::string loc_name; if( get_option<std::string>( "USE_LANG" ).empty() ) { #if (defined _WIN32 || defined WINDOWS) loc_name = getLangFromLCID( GetUserDefaultLCID() ); if( !loc_name.empty() ) { const std::string local_path = base_path + loc_name + extension; if( file_exist( local_path ) ) { return local_path; } } #endif const char *v = setlocale( LC_ALL, NULL ); if( v != NULL ) { loc_name = v; } } else { loc_name = get_option<std::string>( "USE_LANG" ); } if( loc_name == "C" ) { loc_name = "en"; } if( !loc_name.empty() ) { const size_t dotpos = loc_name.find( '.' ); if( dotpos != std::string::npos ) { loc_name.erase( dotpos ); } // complete locale: en_NZ const std::string local_path = base_path + loc_name + extension; if( file_exist( local_path ) ) { return local_path; } const size_t p = loc_name.find( '_' ); if( p != std::string::npos ) { // only the first part: en const std::string local_path = base_path + loc_name.substr( 0, p ) + extension; if( file_exist( local_path ) ) { return local_path; } } } #endif (void) extension; return FILENAMES[fallbackid]; }
void initalize_data(shdata *data, int room_size) { int log_fd, i; char buf[] = "when | who | what | result\n"; strcpy(data[0].filename, data[0].room); strcat(data[0].filename, ".log"); if (file_exist(data[0].filename)) unlink(data[0].filename); log_fd = open(data[0].filename, O_RDWR | O_CREAT, 0666); write(log_fd, buf, sizeof(buf) - 1); close(log_fd); for (i = 0; i < 6; i++) memset(data[0].tablecards[i], '\0', sizeof(data[0].tablecards[i])); data[0].deck_size = 52; data[0].nplayers = room_size; data[0].in = 0; data[0].tablein = 0; data[0].turn = -1; data[0].roundnumber = 0; data[0].dealer = 0; data[0].changed = 0; data[0].roundtimer = time(NULL); data[0].timer = time(NULL); }
int check_cdrom_file_exists ( const char *filename ) { int count; char path[1024]; if ( !cdrom_finder_initialised ) { initialise_cdrom_finder (); } for ( count = 0; count < number_of_cdrom_drives; count++ ) { sprintf ( path, "%c:\\%s", cdrom_drives[count], filename ); if ( file_exist ( path ) ) { cdrom_file_drive_index = count; return ( cdrom_drives[count] ); } } return ( FALSE ); }
static bool reload_nmbd_services(bool test) { bool ret; set_remote_machine_name("nmbd", False); if ( lp_loaded() ) { const char *fname = lp_configfile(); if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) { set_dyn_CONFIGFILE(fname); test = False; } } if ( test && !lp_file_list_changed() ) return(True); ret = lp_load_global(get_dyn_CONFIGFILE()); /* perhaps the config filename is now set */ if ( !test ) { DEBUG( 3, ( "services not loaded\n" ) ); reload_nmbd_services( True ); } return(ret); }
/* Get a file from another point of filesystem =D and copy * it into slackyd's dir. */ int get_file_over_fs (net_t *netpolicy) { const char *destpath = netpolicy->destpath; const char *hostname = netpolicy->hostname; const char *message = netpolicy->msg; char srcpath[BUFFSIZE0]; char buffer[HUGE0]; FILE *fdsrc = NULL; int rval; slassert (netpolicy != NULL); /* Fix local path: * If we are using a local mirror, hostname will be base path. * Ex: using mirror "/mnt/data/slackware/" `hostname' will be "mnt". */ snprintf (srcpath, BUFFSIZE, "/%s/%s", hostname, netpolicy->srcpath); fprintf (stdout, message); fflush (stdout); if (!netpolicy->savepart) slassert (!netpolicy->checkstamp); /* check for overwrite */ if (!netpolicy->overwrite && file_exist (destpath, NULL, true)) /* regular file exist */ { return shutdown_net_t (netpolicy, FILE_DOWNLOADED, "Already downloaded"); } /* Check for timestamp */ if (netpolicy->checkstamp && (fdsrc = fopen (srcpath, "rb")) && (netpolicy->fddest = fopen (destpath, "rb")) && fread (netpolicy->stampdata, 1, STAMPSZ, fdsrc) == STAMPSZ && fread (netpolicy->stamprecv, 1, STAMPSZ, netpolicy->fddest) == STAMPSZ && memcmp (netpolicy->stampdata, netpolicy->stamprecv, STAMPSZ) == 0) { fclose (fdsrc); return shutdown_net_t (netpolicy, FILE_ALREADY_UPDATE, "Already update"); } if (fdsrc) fclose (fdsrc); if (netpolicy->fddest) fclose (netpolicy->fddest); netpolicy->fddest = fopen (destpath, "wb"); __act (netpolicy->fddest, -1, destpath); __act (fdsrc = fopen (srcpath, "rb"), -1, srcpath); while ((rval = fread (buffer, 1, HUGE, fdsrc)) > 0) { fwrite (buffer, 1, rval, netpolicy->fddest); } fclose (fdsrc); return shutdown_net_t (netpolicy, FILE_DOWNLOADED, "done"); }
void set_xclip(int linenr, char *cmd, char *par) { if (file_exist(par) == -1) error_exit(TRUE, FALSE, "xclip binary '%s' does not exist"); xclip = strdup(par); }
mod_manager::mod_manager() { // Insure mod_replacements is initialized. if( mod_replacements.empty() && file_exist(FILENAMES["mods-replacements"]) ) { load_replacement_mods(FILENAMES["mods-replacements"]); } }
void load_global_options_data (void) { FILE *file_ptr; int size; if (!file_exist (global_options_filename)) { return; } if (!(file_ptr = fopen (global_options_filename, "rb"))) { debug_fatal ("Global: Error loading global options data (file : %s)", global_options_filename); } // // We have to be able to read in previous version of the global options file. // size = file_size (global_options_filename); #ifdef DEBUG if (size != sizeof (global_options)) { debug_fatal ("Global: Global options file has changed size (file : %s) - Please delete it", global_options_filename); } #endif if (size > sizeof (global_options)) { debug_fatal ("Global: Global options file is oversized (file : %s) - Please delete it", global_options_filename); } fread (&global_options, size, 1, file_ptr); fclose (file_ptr); // // Need to upgrade the version number ( possibly ) // if ( ( get_global_version_number () != application_version_number ) || ( size != sizeof ( global_options ) ) ) { debug_log ( "Upgrading application version number" ); initialise_global_options_data_version2 (); } set_global_version_number (application_version_number); }
//Respond to client, let them know we have the command. int svPipeSend(int pipedirection, char *message, ...){ int num; va_list ap; FILE *pipefile; char DIRCHECKER[PATH_MAX]; char formatuffer[128] = {0}; va_start(ap, message); vsnprintf(formatuffer, 128, message, ap); va_end(ap); sprintf( DIRCHECKER, "%s/%d.%s", TMPDIR, options.port[PORT_HTTP], ( pipedirection ? "pipe" : "client.pipe" ) ); if( file_exist(DIRCHECKER) && strlen(formatuffer) ) { if( ( pipefile = fopen(DIRCHECKER, "w") ) < 0) { loghandle(LOG_ERR, errno, "Piping Error: unable to open pipe for write: %s", DIRCHECKER ); return 0; } if( ( num = fprintf(pipefile, "%s\r\n", formatuffer) ) < 0) { loghandle(LOG_ERR, errno, "Piping Responce Error: unable to write to pipe: %s", DIRCHECKER ); return 0; } fflush(pipefile); fclose(pipefile); } else { loghandle(LOG_ERR, false, "%s", "Piping Error: message to send but no pipe avaliable" ); return 0; } if( options.verbose ) fflush(stdout); return 1; }
idn_result_t idn_converter_initialize(void) { idn_result_t r; idn__strhash_t hash; idn__aliaslist_t list; #ifndef WITHOUT_ICONV const char *fname; #endif TRACE(("idn_converter_initialize()\n")); if (encoding_name_hash == NULL) { if ((r = idn__strhash_create(&hash)) != idn_success) goto ret; encoding_name_hash = hash; r = register_standard_encoding(); } if (encoding_alias_list == NULL) { if ((r = idn__aliaslist_create(&list)) != idn_success) goto ret; encoding_alias_list = list; #ifndef WITHOUT_ICONV fname = get_system_aliasfile(); if (fname != NULL && file_exist(fname)) idn_converter_aliasfile(fname); #endif } r = idn_success; ret: TRACE(("idn_converter_initialize(): %s\n", idn_result_tostring(r))); return (r); }
bool load_proxy_config() { if (file_exist(PROXY_CONF)) { int i; char *line; string_list_t *lines; lines = sl_load_file(PROXY_CONF); if (lines == NULL) { fprintf(stderr, "Could not load file %s: %s", PROXY_CONF, strerror(errno)); return false; } for (i = 0; i < lines->count; i++) { line = str_strip(lines->data[i]); if (*line) { sl_append(Config.proxy_list, strdup(line)); } } string_list_free(lines); if (Config.proxy_list->count == 0) { fprintf(stderr, "%s has no proxy servers", PROXY_CONF); return false; } } else { sl_append(Config.proxy_list, strdup(HOST)); } return true; }
bool update_password_config() { bool ok; header_list_t *list; log_info("Update password configuration, updating password is done"); if (file_exist(Config.config_file)) { list = hl_load_config(Config.config_file); if (list == NULL) { log_error("Could not load configuration"); return false; } } else { list = header_list_new(); } hl_set(list, "update_password", "no", rel_none); ok = hl_write_config(Config.config_file, list); if (!ok) { log_error("Could not write configuration"); return false; } header_list_free(list); return true; }
static int get_boot_info(struct boot_context *context, char *rootdir, char *subsys) { char initiator_dir[FILENAMESZ]; int rc = ENODEV; int nic_idx = -1, tgt_idx = -1; memset(&initiator_dir, 0 , FILENAMESZ); snprintf(initiator_dir, FILENAMESZ, "%sinitiator", rootdir); nic_cnt = 0; tgt_cnt = 0; if (file_exist(initiator_dir)) { /* Find the targets and the ethernets */ rc = nftw(rootdir, find_sysfs_dirs, 20, 1); /* Find wihch target and which ethernet have the boot flag set. */ rc = find_boot_flag(subsys, nic_list, nic_cnt, &nic_idx); if (rc) goto free; rc = find_boot_flag(subsys, target_list, tgt_cnt, &tgt_idx); if (rc) goto free; /* Fill in the context values */ rc = fill_nic_context(subsys, nic_list[nic_idx], context); rc |= fill_tgt_context(subsys, target_list[tgt_idx], context); fill_initiator_context(subsys, context); } free: deallocate_lists(); return rc; }
int cfg_load(void) { huuma_cfg_t cfg; const char *cfg_fn = CFG_FN; if(file_exist(cfg_fn)) { file_ropen(cfg_fn); file_read(&cfg, sizeof(cfg)); rank = cfg.opts.rank; snd_bgm_mode = cfg.opts.bgm_mode; bombs = cfg.opts.bombs; lives = cfg.opts.lives; mikoconfig_sgm = cfg.resident_sgm; if(!mikoconfig_sgm) { return 1; } mikoconfig = MK_FP(mikoconfig_sgm, 0); mikoconfig->perf = cfg.opts.perf; mikoconfig->debug = cfg.debug; file_close(); if(snd_bgm_mode == SND_BGM_OFF) { snd_fm_possible = 0; snd_active = 0; } else if(snd_bgm_mode == SND_BGM_FM) { snd_midi_active = 0; snd_determine_mode(); } else { snd_midi_active = snd_midi_possible; snd_determine_mode(); } return 0; } return 1; }
static BOOL reload_nmbd_services(BOOL test) { BOOL ret; set_remote_machine_name("nmbd", False); if ( lp_loaded() ) { pstring fname; pstrcpy( fname,lp_configfile()); if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) { pstrcpy(dyn_CONFIGFILE,fname); test = False; } } if ( test && !lp_file_list_changed() ) return(True); ret = lp_load( dyn_CONFIGFILE, True , False, False, True); /* perhaps the config filename is now set */ if ( !test ) { DEBUG( 3, ( "services not loaded\n" ) ); reload_nmbd_services( True ); } return(ret); }
const int MemBlockDevice::LoadFromFile(const std::string & path) { FILE* filePtr; if (!file_exist(path)) return -1; Format(); fopen_s(&filePtr, path.c_str(), "rb"); char arr[blocksize]; for (int i = 0; i < nrOfBlocks; i++) { fread(arr, blocksize, 1, filePtr); memBlocks[i].writeBlock(arr, blocksize, 0); } int size = nrOfBlocks*sizeof(int); int point = 0; for (int i = 0; i < mFillSize; i++) { int s = (size < blocksize) ? size : blocksize; memcpy(mFreeBlocks + point, memBlocks[1 + i * 2].toString().c_str(), s); memcpy(mFilledBlocks + point, memBlocks[2 + i * 2].toString().c_str(), s); point += s/sizeof(int); size -= blocksize; } return GetStart(); }
void busy_wait_for_sync() { while(1) { if (file_exist(SYNC_FILENAME)) return; } }
static bool reload_services_file(const char *lfile) { bool ret; if (lp_loaded()) { char *fname = lp_configfile(talloc_tos()); if (file_exist(fname) && !strcsequal(fname,get_dyn_CONFIGFILE())) { set_dyn_CONFIGFILE(fname); } TALLOC_FREE(fname); } /* if this is a child, restore the logfile to the special name - <domain>, idmap, etc. */ if (lfile && *lfile) { lp_set_logfile(lfile); } reopen_logs(); ret = lp_load_global(get_dyn_CONFIGFILE()); reopen_logs(); load_interfaces(); return(ret); }
void *safe_mopen (char *filename) { void *ptr; ASSERT (filename); ptr = mopen (filename); if ( !ptr ) { if ( file_exist ( filename ) ) { debug_fatal ( "Unable to map file %s\n\nThis may be due to lack of virtual memory", filename ); } else { debug_fatal ( "Unable to load file %s", filename ); } } safe_memory_mapped_file_counter++; return (ptr); }