int dump_registry_ignore_regex(syscheck_config *syscheck, char *regex, int arch) { OSMatch *mt_pt; int ign_size = 0; if (!syscheck->registry_ignore_regex) { os_calloc(2, sizeof(registry_regex), syscheck->registry_ignore_regex); syscheck->registry_ignore_regex[0].regex = NULL; syscheck->registry_ignore_regex[1].regex = NULL; } else { while (syscheck->registry_ignore_regex[ign_size].regex != NULL) { ign_size++; } os_realloc(syscheck->registry_ignore_regex, sizeof(registry_regex) * (ign_size + 2), syscheck->registry_ignore_regex); syscheck->registry_ignore_regex[ign_size + 1].regex = NULL; } os_calloc(1, sizeof(OSMatch), syscheck->registry_ignore_regex[ign_size].regex); if (!OSMatch_Compile(regex, syscheck->registry_ignore_regex[ign_size].regex, 0)) { mt_pt = syscheck->registry_ignore_regex[ign_size].regex; merror(REGEX_COMPILE, __local_name, regex, mt_pt->error); return (0); } syscheck->registry_ignore_regex[ign_size].arch = arch; return 1; }
/* Initialize the necessary information to process the syscheck information */ void SyscheckInit() { int i = 0; sdb.db_err = 0; for (; i <= MAX_AGENTS; i++) { sdb.agent_ips[i] = NULL; sdb.agent_fps[i] = NULL; sdb.agent_cp[i][0] = '0'; } /* Clear db memory */ memset(sdb.buf, '\0', OS_MAXSTR + 1); memset(sdb.comment, '\0', OS_MAXSTR + 1); memset(sdb.size, '\0', OS_FLSIZE + 1); memset(sdb.perm, '\0', OS_FLSIZE + 1); memset(sdb.owner, '\0', OS_FLSIZE + 1); memset(sdb.gowner, '\0', OS_FLSIZE + 1); memset(sdb.md5, '\0', OS_FLSIZE + 1); memset(sdb.sha1, '\0', OS_FLSIZE + 1); memset(sdb.mtime, '\0', OS_FLSIZE + 1); memset(sdb.inode, '\0', OS_FLSIZE + 1); /* Create decoder */ os_calloc(1, sizeof(OSDecoderInfo), sdb.syscheck_dec); sdb.syscheck_dec->id = getDecoderfromlist(SYSCHECK_MOD); sdb.syscheck_dec->name = SYSCHECK_MOD; sdb.syscheck_dec->type = OSSEC_RL; sdb.syscheck_dec->fts = 0; os_calloc(Config.decoder_order_size, sizeof(char *), sdb.syscheck_dec->fields); sdb.syscheck_dec->fields[SCK_FILE] = "file"; sdb.syscheck_dec->fields[SCK_SIZE] = "size"; sdb.syscheck_dec->fields[SCK_PERM] = "perm"; sdb.syscheck_dec->fields[SCK_UID] = "uid"; sdb.syscheck_dec->fields[SCK_GID] = "gid"; sdb.syscheck_dec->fields[SCK_MD5] = "md5"; sdb.syscheck_dec->fields[SCK_SHA1] = "sha1"; sdb.syscheck_dec->fields[SCK_UNAME] = "uname"; sdb.syscheck_dec->fields[SCK_GNAME] = "gname"; sdb.syscheck_dec->fields[SCK_INODE] = "inode"; sdb.id1 = getDecoderfromlist(SYSCHECK_MOD); sdb.id2 = getDecoderfromlist(SYSCHECK_MOD2); sdb.id3 = getDecoderfromlist(SYSCHECK_MOD3); sdb.idn = getDecoderfromlist(SYSCHECK_NEW); sdb.idd = getDecoderfromlist(SYSCHECK_DEL); debug1("%s: SyscheckInit completed.", ARGV0); }
void dump_registry_ignore(syscheck_config *syscheck, char *entry, int arch) { int ign_size = 0; if (syscheck->registry_ignore) { int ign_size; /* We do not add duplicated entries */ for (ign_size = 0; syscheck->registry_ignore[ign_size].entry; ign_size++) if (syscheck->registry_ignore[ign_size].arch == arch && strcmp(syscheck->registry_ignore[ign_size].entry, entry) == 0) return; os_realloc(syscheck->registry_ignore, sizeof(registry) * (ign_size + 2), syscheck->registry_ignore); syscheck->registry_ignore[ign_size + 1].entry = NULL; } else { ign_size = 0; os_calloc(2, sizeof(registry), syscheck->registry_ignore); syscheck->registry_ignore[0].entry = NULL; syscheck->registry_ignore[1].entry = NULL; } os_strdup(entry, syscheck->registry_ignore[ign_size].entry); syscheck->registry_ignore[ign_size].arch = arch; }
int radius_copy_class(struct radius_class_data *dst, const struct radius_class_data *src) { size_t i; if (src->attr == NULL) return 0; dst->attr = os_calloc(src->count, sizeof(struct radius_attr_data)); if (dst->attr == NULL) return -1; dst->count = 0; for (i = 0; i < src->count; i++) { dst->attr[i].data = os_malloc(src->attr[i].len); if (dst->attr[i].data == NULL) break; dst->count++; os_memcpy(dst->attr[i].data, src->attr[i].data, src->attr[i].len); dst->attr[i].len = src->attr[i].len; } return 0; }
void * tiz_os_calloc (const tiz_os_t * ap_os, size_t a_size) { assert (ap_os); assert (ap_os->p_soa); return os_calloc (ap_os->p_soa, a_size); }
OMX_ERRORTYPE tiz_os_init (tiz_os_t ** app_os, const OMX_HANDLETYPE ap_hdl, tiz_soa_t * ap_soa) { tiz_os_t * p_os = NULL; assert (app_os); assert (ap_hdl); TIZ_TRACE (ap_hdl, "Init"); if (NULL == (p_os = (tiz_os_t *) os_calloc (ap_soa, sizeof (tiz_os_t)))) { return OMX_ErrorInsufficientResources; } assert (p_os); if (OMX_ErrorNone != tiz_map_init (&(p_os->p_map), os_map_compare_func, os_map_free_func, NULL)) { os_free (ap_soa, p_os); p_os = NULL; return OMX_ErrorInsufficientResources; } p_os->p_hdl = ap_hdl; p_os->p_soa = ap_soa; *app_os = p_os; return OMX_ErrorNone; }
struct os_stream * os_str_stream_create(size_t size) { struct os_str_stream *stream; stream = (struct os_str_stream *)os_calloc(1, sizeof(*stream)); if(!stream) goto no_stream; stream->base.close = &os_str_stream_close; stream->base.write = &os_str_stream_write; stream->base.flush = &os_str_stream_flush; stream->base.vprintf = &os_default_stream_vprintf; stream->str = os_malloc(size); if(!stream->str) goto no_str; stream->size = size; return &stream->base; no_str: os_free(stream); no_stream: return NULL; }
/* os_get_unix_process_list: Get list of Unix processes */ void *os_get_process_list() { int i = 1; pid_t max_pid = MAX_PID; OSList *p_list = NULL; char ps[OS_SIZE_1024 +1]; /* Checking where ps is */ memset(ps, '\0', OS_SIZE_1024 +1); strncpy(ps, "/bin/ps", OS_SIZE_1024); if(!is_file(ps)) { strncpy(ps, "/usr/bin/ps", OS_SIZE_1024); if(!is_file(ps)) { merror("%s: ERROR: 'ps' not found.", ARGV0); return(NULL); } } /* Creating process list */ p_list = OSList_Create(); if(!p_list) { merror(LIST_ERROR, ARGV0); return(NULL); } for(i = 1; i<= max_pid; i++) { /* Checking if the pid is present. */ if((!((getsid(i) == -1)&&(errno == ESRCH))) && (!((getpgid(i) == -1)&&(errno == ESRCH)))) { Proc_Info *p_info; char *p_name; p_name = _os_get_runps(ps, (int)i); if(!p_name) { continue; } os_calloc(1, sizeof(Proc_Info), p_info); p_info->p_path = p_name; p_info->p_name = NULL; OSList_AddData(p_list, p_info); } } return((void *)p_list); }
static struct gas_dialog_info * gas_dialog_create(struct hostapd_data *hapd, const u8 *addr, u8 dialog_token) { struct sta_info *sta; struct gas_dialog_info *dia = NULL; int i, j; sta = ap_get_sta(hapd, addr); if (!sta) { /* * We need a STA entry to be able to maintain state for * the GAS query. */ wpa_printf(MSG_DEBUG, "ANQP: Add a temporary STA entry for " "GAS query"); sta = ap_sta_add(hapd, addr); if (!sta) { wpa_printf(MSG_DEBUG, "Failed to add STA " MACSTR " for GAS query", MAC2STR(addr)); return NULL; } sta->flags |= WLAN_STA_GAS; /* * The default inactivity is 300 seconds. We don't need * it to be that long. */ ap_sta_session_timeout(hapd, sta, 5); } else { ap_sta_replenish_timeout(hapd, sta, 5); } if (sta->gas_dialog == NULL) { sta->gas_dialog = os_calloc(GAS_DIALOG_MAX, sizeof(struct gas_dialog_info)); if (sta->gas_dialog == NULL) return NULL; } for (i = sta->gas_dialog_next, j = 0; j < GAS_DIALOG_MAX; i++, j++) { if (i == GAS_DIALOG_MAX) i = 0; if (sta->gas_dialog[i].valid) continue; dia = &sta->gas_dialog[i]; dia->valid = 1; dia->dialog_token = dialog_token; sta->gas_dialog_next = (++i == GAS_DIALOG_MAX) ? 0 : i; return dia; } wpa_msg(hapd->msg_ctx, MSG_ERROR, "ANQP: Could not create dialog for " MACSTR " dialog_token %u. Consider increasing " "GAS_DIALOG_MAX.", MAC2STR(addr), dialog_token); return NULL; }
/* OS_DBD: Monitor the alerts and insert them into the database. * Only return in case of error. */ void OS_DBD(DBConfig *db_config) { time_t tm; struct tm *p; file_queue *fileq; alert_data *al_data; /* Getting currently time before starting */ tm = time(NULL); p = localtime(&tm); /* Initating file queue - to read the alerts */ os_calloc(1, sizeof(file_queue), fileq); Init_FileQueue(fileq, p, 0); /* Creating location hash */ db_config->location_hash = OSHash_Create(); if(!db_config->location_hash) { ErrorExit(MEM_ERROR, ARGV0); } /* Getting maximum ID */ db_config->alert_id = OS_SelectMaxID(db_config); db_config->alert_id++; /* Infinite loop reading the alerts and inserting them. */ while(1) { tm = time(NULL); p = localtime(&tm); /* Get message if available (timeout of 5 seconds) */ al_data = Read_FileMon(fileq, p, 5); if(!al_data) { continue; } /* Inserting into the db */ OS_Alert_InsertDB(al_data, db_config); /* Clearing the memory */ FreeAlertData(al_data); } }
epbase *epoll_init(int size) { epbase *base = os_calloc(sizeof(epbase)); base->evsize = size; base->epfd = epoll_create(size); if (base->epfd < 0) { return NULL; } base->evlist = os_calloc(sizeof(struct epoll_event) * base->evsize); if (base->evlist == NULL) { return NULL; } base->eflags |= EPEDGE; // default using edge trigger. return base; }
static int radius_msg_initialize(struct radius_msg *msg) { msg->attr_pos = os_calloc(RADIUS_DEFAULT_ATTR_COUNT, sizeof(*msg->attr_pos)); if (msg->attr_pos == NULL) return -1; msg->attr_size = RADIUS_DEFAULT_ATTR_COUNT; msg->attr_used = 0; return 0; }
char *OS_AddNewAgent(const char *name, const char *ip, const char *id) { FILE *fp; os_md5 md1; os_md5 md2; char str1[STR_SIZE + 1]; char str2[STR_SIZE + 1]; char *muname; char *finals; char nid[9]; srandom_init(); muname = getuname(); snprintf(str1, STR_SIZE, "%d%s%d%s", (int)time(0), name, (int)random(), muname); snprintf(str2, STR_SIZE, "%s%s%ld", ip, id, (long int)random()); OS_MD5_Str(str1, md1); OS_MD5_Str(str2, md2); free(muname); nid[8] = '\0'; if (id == NULL) { int i = 1024; snprintf(nid, 6, "%d", i); while (IDExist(nid)) { i++; snprintf(nid, 6, "%d", i); if (i >= (MAX_AGENTS + 1024)) { return (NULL); } } id = nid; } fp = fopen(KEYSFILE_PATH, "a"); if (!fp) { return (NULL); } os_calloc(2048, sizeof(char), finals); if (ip == NULL) { snprintf(finals, 2048, "%s %s any %s%s", id, name, md1, md2); } else { snprintf(finals, 2048, "%s %s %s %s%s", id, name, ip, md1, md2); } fprintf(fp, "%s\n", finals); fclose(fp); return (finals); }
static dbus_bool_t _wpa_dbus_dict_entry_get_byte_array( DBusMessageIter *iter, struct wpa_dbus_dict_entry *entry) { dbus_uint32_t count = 0; dbus_bool_t success = FALSE; char *buffer, *nbuffer; entry->bytearray_value = NULL; entry->array_type = DBUS_TYPE_BYTE; buffer = os_calloc(BYTE_ARRAY_CHUNK_SIZE, BYTE_ARRAY_ITEM_SIZE); if (!buffer) return FALSE; entry->bytearray_value = buffer; entry->array_len = 0; while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_BYTE) { char byte; if ((count % BYTE_ARRAY_CHUNK_SIZE) == 0 && count != 0) { nbuffer = os_realloc_array( buffer, count + BYTE_ARRAY_CHUNK_SIZE, BYTE_ARRAY_ITEM_SIZE); if (nbuffer == NULL) { os_free(buffer); wpa_printf(MSG_ERROR, "dbus: _wpa_dbus_dict_" "entry_get_byte_array out of " "memory trying to retrieve the " "string array"); goto done; } buffer = nbuffer; } entry->bytearray_value = buffer; dbus_message_iter_get_basic(iter, &byte); entry->bytearray_value[count] = byte; entry->array_len = ++count; dbus_message_iter_next(iter); } /* Zero-length arrays are valid. */ if (entry->array_len == 0) { os_free(entry->bytearray_value); entry->bytearray_value = NULL; } success = TRUE; done: return success; }
void FillEvent(Eventinfo *lf, const char *f_name, const SyscheckSum *sum) { os_strdup(f_name, lf->filename); os_strdup(sum->size, lf->size_after); lf->perm_after = sum->perm; os_strdup(sum->uid, lf->owner_after); os_strdup(sum->gid, lf->gowner_after); os_strdup(sum->md5, lf->md5_after); os_strdup(sum->sha1, lf->sha1_after); if (sum->uname) os_strdup(sum->uname, lf->uname_after); if (sum->gname) os_strdup(sum->gname, lf->gname_after); lf->mtime_after = sum->mtime; lf->inode_after = sum->inode; /* Fields */ os_strdup(f_name, lf->fields[SCK_FILE]); os_strdup(sum->size, lf->fields[SCK_SIZE]); os_calloc(7, sizeof(char), lf->fields[SCK_PERM]); snprintf(lf->fields[SCK_PERM], 7, "%06o", sum->perm); os_strdup(sum->uid, lf->fields[SCK_UID]); os_strdup(sum->gid, lf->fields[SCK_GID]); os_strdup(sum->md5, lf->fields[SCK_MD5]); os_strdup(sum->sha1, lf->fields[SCK_SHA1]); if (sum->uname) os_strdup(sum->uname, lf->fields[SCK_UNAME]); if (sum->gname) os_strdup(sum->gname, lf->fields[SCK_GNAME]); if (sum->inode) { os_calloc(20, sizeof(char), lf->fields[SCK_INODE]); snprintf(lf->fields[SCK_INODE], 20, "%ld", sum->inode); } }
/** * hostapd_init - Allocate and initialize per-interface data * @config_file: Path to the configuration file * Returns: Pointer to the allocated interface data or %NULL on failure * * This function is used to allocate main data structures for per-interface * data. The allocated data buffer will be freed by calling * hostapd_cleanup_iface(). */ static struct hostapd_iface * hostapd_init(const char *config_file) { struct hostapd_iface *hapd_iface = NULL; struct hostapd_config *conf = NULL; struct hostapd_data *hapd; size_t i; hapd_iface = os_zalloc(sizeof(*hapd_iface)); if (hapd_iface == NULL) goto fail; hapd_iface->config_fname = os_strdup(config_file); if (hapd_iface->config_fname == NULL) goto fail; conf = hostapd_config_read(hapd_iface->config_fname); if (conf == NULL) goto fail; hapd_iface->conf = conf; hapd_iface->num_bss = conf->num_bss; hapd_iface->bss = os_calloc(conf->num_bss, sizeof(struct hostapd_data *)); if (hapd_iface->bss == NULL) goto fail; for (i = 0; i < conf->num_bss; i++) { hapd = hapd_iface->bss[i] = hostapd_alloc_bss_data(hapd_iface, conf, &conf->bss[i]); if (hapd == NULL) goto fail; hapd->msg_ctx = hapd; hapd->setup_complete_cb = hostapd_setup_complete_cb; } return hapd_iface; fail: wpa_printf(MSG_ERROR, "Failed to set up interface with %s", config_file); if (conf) hostapd_config_free(conf); if (hapd_iface) { os_free(hapd_iface->config_fname); os_free(hapd_iface->bss); os_free(hapd_iface); } return NULL; }
/* Initialize an storage object */ OS_ACM_Store * InitACMStore() { OS_ACM_Store *obj; os_calloc(1, sizeof(OS_ACM_Store), obj); obj->timestamp = 0; obj->srcuser = NULL; obj->dstuser = NULL; obj->srcip = NULL; obj->dstip = NULL; obj->srcport = NULL; obj->dstport = NULL; obj->data = NULL; return obj; }
/** * hostapd_init - Allocate and initialize per-interface data * @config_file: Path to the configuration file * Returns: Pointer to the allocated interface data or %NULL on failure * * This function is used to allocate main data structures for per-interface * data. The allocated data buffer will be freed by calling * hostapd_cleanup_iface(). */ static struct hostapd_iface * hostapd_init(const char *config_file) { struct hostapd_iface *hapd_iface = NULL; struct hostapd_config *conf = NULL; struct hostapd_data *hapd; size_t i; hapd_iface = os_zalloc(sizeof(*hapd_iface)); if (hapd_iface == NULL) goto fail; hapd_iface->config_fname = os_strdup(config_file); if (hapd_iface->config_fname == NULL) goto fail; conf = hostapd_config_read(hapd_iface->config_fname); if (conf == NULL) goto fail; hapd_iface->conf = conf; hapd_iface->num_bss = conf->num_bss; hapd_iface->bss = os_calloc(conf->num_bss, sizeof(struct hostapd_data *)); if (hapd_iface->bss == NULL) goto fail; for (i = 0; i < conf->num_bss; i++) { hapd = hapd_iface->bss[i] = hostapd_alloc_bss_data(hapd_iface, conf, &conf->bss[i]); if (hapd == NULL) goto fail; hapd->msg_ctx = hapd; } return hapd_iface; fail: if (conf) hostapd_config_free(conf); if (hapd_iface) { os_free(hapd_iface->config_fname); os_free(hapd_iface->bss); os_free(hapd_iface); } return NULL; }
static int hostapd_global_init(struct hapd_interfaces *interfaces, const char *entropy_file) { int i; os_memset(&global, 0, sizeof(global)); hostapd_logger_register_cb(hostapd_logger_cb); if (eap_server_register_methods()) { wpa_printf(MSG_ERROR, "Failed to register EAP methods"); return -1; } if (eloop_init()) { wpa_printf(MSG_ERROR, "Failed to initialize event loop"); return -1; } random_init(entropy_file); #ifndef CONFIG_NATIVE_WINDOWS eloop_register_signal(SIGHUP, handle_reload, interfaces); eloop_register_signal(SIGUSR1, handle_dump_state, interfaces); #endif /* CONFIG_NATIVE_WINDOWS */ eloop_register_signal_terminate(handle_term, interfaces); /*Timeout event is triggered after 5 seconds of start of hostapd. The parameters are pulled after the event is triggered in the handler*/ // eloop_register_timeout(5, 0, get_params_handler, &ctx, NULL); #ifndef CONFIG_NATIVE_WINDOWS openlog("hostapd", 0, LOG_DAEMON); #endif /* CONFIG_NATIVE_WINDOWS */ for (i = 0; wpa_drivers[i]; i++) global.drv_count++; if (global.drv_count == 0) { wpa_printf(MSG_ERROR, "No drivers enabled"); return -1; } global.drv_priv = os_calloc(global.drv_count, sizeof(void *)); if (global.drv_priv == NULL) return -1; return 0; }
static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface, struct wpa_driver_scan_params *params) { /* Scan only the affected frequency range */ int pri_freq, sec_freq; int affected_start, affected_end; int i, pos; struct hostapd_hw_modes *mode; if (iface->current_mode == NULL) { return; } pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel); if (iface->conf->secondary_channel > 0) { sec_freq = pri_freq + 20; } else { sec_freq = pri_freq - 20; } /* * Note: Need to find the PRI channel also in cases where the affected * channel is the SEC channel of a 40 MHz BSS, so need to include the * scanning coverage here to be 40 MHz from the center frequency. */ affected_start = (pri_freq + sec_freq) / 2 - 40; affected_end = (pri_freq + sec_freq) / 2 + 40; wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz", affected_start, affected_end); mode = iface->current_mode; params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); if (params->freqs == NULL) { return; } pos = 0; for (i = 0; i < mode->num_channels; i++) { struct hostapd_channel_data *chan = &mode->channels[i]; if (chan->flag & HOSTAPD_CHAN_DISABLED) { continue; } if (chan->freq < affected_start || chan->freq > affected_end) { continue; } params->freqs[pos++] = chan->freq; } }
static void wnm_set_scan_freqs(struct wpa_supplicant *wpa_s) { int *freqs; int num_freqs = 0; unsigned int i; if (!wpa_s->wnm_neighbor_report_elements) return; if (wpa_s->hw.modes == NULL) return; os_free(wpa_s->next_scan_freqs); wpa_s->next_scan_freqs = NULL; freqs = os_calloc(wpa_s->wnm_num_neighbor_report + 1, sizeof(int)); if (freqs == NULL) return; for (i = 0; i < wpa_s->wnm_num_neighbor_report; i++) { struct neighbor_report *nei; nei = &wpa_s->wnm_neighbor_report_elements[i]; if (nei->freq <= 0) { wpa_printf(MSG_DEBUG, "WNM: Unknown neighbor operating frequency for " MACSTR " - scan all channels", MAC2STR(nei->bssid)); os_free(freqs); return; } if (chan_supported(wpa_s, nei->freq)) add_freq(freqs, &num_freqs, nei->freq); } if (num_freqs == 0) { os_free(freqs); return; } wpa_printf(MSG_DEBUG, "WNM: Scan %d frequencies based on transition candidate list", num_freqs); wpa_s->next_scan_freqs = freqs; }
static int hostapd_global_init(struct hapd_interfaces *interfaces, const char *entropy_file) { int i; //重只global变量 os_memset(&global, 0, sizeof(global)); hostapd_logger_register_cb(hostapd_logger_cb); //注册eap server的加密方法 if (eap_server_register_methods()) { wpa_printf(MSG_ERROR, "Failed to register EAP methods"); return -1; } if (eloop_init()) { wpa_printf(MSG_ERROR, "Failed to initialize event loop"); return -1; } random_init(entropy_file); #ifndef CONFIG_NATIVE_WINDOWS eloop_register_signal(SIGHUP, handle_reload, interfaces); eloop_register_signal(SIGUSR1, handle_dump_state, interfaces); #endif /* CONFIG_NATIVE_WINDOWS */ eloop_register_signal_terminate(handle_term, interfaces); #ifndef CONFIG_NATIVE_WINDOWS openlog("hostapd", 0, LOG_DAEMON); #endif /* CONFIG_NATIVE_WINDOWS */ for (i = 0; wpa_drivers[i]; i++) global.drv_count++; if (global.drv_count == 0) { wpa_printf(MSG_ERROR, "No drivers enabled"); return -1; } global.drv_priv = os_calloc(global.drv_count, sizeof(void *)); if (global.drv_priv == NULL) return -1; return 0; }
void OS_RemoveAgentTimestamp(const char *id) { FILE *fp; char *buffer; char line[OS_BUFFER_SIZE]; int idlen = strlen(id); int pos = 0; struct stat fp_stat; if (stat(AUTH_FILE, &fp_stat) < 0) { return; } fp = fopen(TIMESTAMP_FILE, "r"); if (!fp) { return; } os_calloc(fp_stat.st_size + 1, sizeof(char), buffer); while (fgets(line, OS_BUFFER_SIZE, fp)) { if (strncmp(id, line, idlen)) { strncpy(&buffer[pos], line, fp_stat.st_size - pos); pos += strlen(line); } } fclose(fp); fp = fopen(TIMESTAMP_FILE, "w"); if (!fp) { merror("%s: ERROR: Couldn't open timetamp file.", ARGV0); free(buffer); return; } fprintf(fp, "%s", buffer); fclose(fp); free(buffer); }
/* SyscheckInit * Initialize the necessary information to process the syscheck information */ void SyscheckInit() { int i = 0; sdb.db_err = 0; for(;i <= MAX_AGENTS;i++) { sdb.agent_ips[i] = NULL; sdb.agent_fps[i] = NULL; sdb.agent_cp[i][0] = '0'; } /* Clearing db memory */ memset(sdb.buf, '\0', OS_MAXSTR +1); memset(sdb.comment, '\0', OS_MAXSTR +1); memset(sdb.size, '\0', OS_FLSIZE +1); memset(sdb.perm, '\0', OS_FLSIZE +1); memset(sdb.owner, '\0', OS_FLSIZE +1); memset(sdb.gowner, '\0', OS_FLSIZE +1); memset(sdb.md5, '\0', OS_FLSIZE +1); memset(sdb.sha1, '\0', OS_FLSIZE +1); /* Creating decoder */ os_calloc(1, sizeof(OSDecoderInfo), sdb.syscheck_dec); sdb.syscheck_dec->id = getDecoderfromlist(SYSCHECK_MOD); sdb.syscheck_dec->name = SYSCHECK_MOD; sdb.syscheck_dec->type = OSSEC_RL; sdb.syscheck_dec->fts = 0; sdb.id1 = getDecoderfromlist(SYSCHECK_MOD); sdb.id2 = getDecoderfromlist(SYSCHECK_MOD2); sdb.id3 = getDecoderfromlist(SYSCHECK_MOD3); sdb.idn = getDecoderfromlist(SYSCHECK_NEW); sdb.idd = getDecoderfromlist(SYSCHECK_DEL); debug1("%s: SyscheckInit completed.", ARGV0); return; }
static char * os_strndup (tiz_soa_t * p_soa, const char * s, size_t n) { char * result; size_t len = strlen (s); assert (p_soa); if (n < len) { len = n; } if (NULL == (result = (char *) os_calloc (p_soa, len + 1))) { return NULL; } result[len] = '\0'; return (char *) memcpy (result, s, len); }
static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface, struct wpa_driver_scan_params *params) { /* Scan only the affected frequency range */ int pri_freq; int affected_start, affected_end; int i, pos; struct hostapd_hw_modes *mode; if (iface->current_mode == NULL) { return; } pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel); if (iface->conf->secondary_channel > 0) { affected_start = pri_freq - 10; affected_end = pri_freq + 30; } else { affected_start = pri_freq - 30; affected_end = pri_freq + 10; } wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz", affected_start, affected_end); mode = iface->current_mode; params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); if (params->freqs == NULL) { return; } pos = 0; for (i = 0; i < mode->num_channels; i++) { struct hostapd_channel_data *chan = &mode->channels[i]; if (chan->flag & HOSTAPD_CHAN_DISABLED) { continue; } if (chan->freq < affected_start || chan->freq > affected_end) { continue; } params->freqs[pos++] = chan->freq; } }
/* Initialize the necessary information to process the rootcheck information */ void RootcheckInit() { int i = 0; rk_err = 0; for (; i < MAX_AGENTS; i++) { rk_agent_ips[i] = NULL; rk_agent_fps[i] = NULL; } /* Zero decoder */ os_calloc(1, sizeof(OSDecoderInfo), rootcheck_dec); rootcheck_dec->id = getDecoderfromlist(ROOTCHECK_MOD); rootcheck_dec->type = OSSEC_RL; rootcheck_dec->name = ROOTCHECK_MOD; rootcheck_dec->fts = 0; debug1("%s: RootcheckInit completed.", ARGV0); return; }
static int acs_request_scan(struct hostapd_iface *iface) { struct wpa_driver_scan_params params; struct hostapd_channel_data *chan; int i, *freq; os_memset(¶ms, 0, sizeof(params)); params.freqs = os_calloc(iface->current_mode->num_channels + 1, sizeof(params.freqs[0])); if (params.freqs == NULL) return -1; freq = params.freqs; for (i = 0; i < iface->current_mode->num_channels; i++) { chan = &iface->current_mode->channels[i]; if (chan->flag & HOSTAPD_CHAN_DISABLED) continue; *freq++ = chan->freq; } *freq = 0; iface->scan_cb = acs_scan_complete; wpa_printf(MSG_DEBUG, "ACS: Scanning %d / %d", iface->acs_num_completed_scans + 1, iface->conf->acs_num_scans); if (hostapd_driver_scan(iface->bss[0], ¶ms) < 0) { wpa_printf(MSG_ERROR, "ACS: Failed to request initial scan"); acs_cleanup(iface); os_free(params.freqs); return -1; } os_free(params.freqs); return 0; }
OS_DECLARE(os_status_t) os_mutex_create(os_mutex_t **mutex) { os_status_t status = OS_FAIL; #ifndef WIN32 pthread_mutexattr_t attr; #endif os_mutex_t *check = NULL; check = (os_mutex_t *)os_calloc(1, sizeof(**mutex)); if (!check) goto done; #ifdef WIN32 InitializeCriticalSection(&check->mutex); #else if (pthread_mutexattr_init(&attr)) goto done; if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) goto fail; if (pthread_mutex_init(&check->mutex, &attr)) goto fail; goto success; fail: pthread_mutexattr_destroy(&attr); goto done; success: #endif *mutex = check; status = OS_SUCCESS; done: return status; }
static void wpa_setband_scan_freqs_list(struct wpa_supplicant *wpa_s, enum hostapd_hw_mode band, struct wpa_driver_scan_params *params) { /* Include only supported channels for the specified band */ struct hostapd_hw_modes *mode; int count, i; mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band); if (mode == NULL) { /* No channels supported in this band - use empty list */ params->freqs = os_zalloc(sizeof(int)); return; } params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); if (params->freqs == NULL) return; for (count = 0, i = 0; i < mode->num_channels; i++) { if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) continue; params->freqs[count++] = mode->channels[i].freq; } }