/** * Create a linked list of crash entries as found in CRASH_DIR. If * the previous_flag parameter is set, the list will include crash * entries that include the SUCCESSFULLY_PROCESSED_TAGFILE file. If * the parameter is set to zero, then the list will include crash * entries that do NOT include the tag file. * * \param previous_flag If set, require the * \returns Linked list of entries found, or NULL if none. */ static llist* find_crash_entries(int previous_flag) { llist* l = NULL; DIR *dp = NULL; struct dirent *ep = NULL; struct stat sb; char crash_dir[PATH_MAX]; memset(&sb, 0, sizeof(struct stat)); get_crash_dir(crash_dir, PATH_MAX); if (does_exist(crash_dir)) { debug_log("Crash directory exists (%s), examining for candidates to process.", crash_dir); dp = opendir(crash_dir); if (NULL != dp) { while ((ep = readdir(dp))) { if ((strcmp(".", ep->d_name) == 0) || (strcmp("..", ep->d_name) == 0)) { continue; } /* verify that the subdirectory contains a vmcore file */ if (is_crash_dir(crash_dir, ep->d_name)) { char touch_file[PATH_MAX]; int stat_result = 0; memset(touch_file, 0, PATH_MAX); snprintf(touch_file, PATH_MAX-1, "%s/%s/%s", crash_dir, ep->d_name, SUCCESSFULLY_PROCESSED_TAGFILE); stat_result = stat(touch_file, &sb); if (previous_flag && !stat_result) { // looking for previous, and found one l = insert_item(ep->d_name, l); debug_log("Adding previously processed: %s/%s.", crash_dir, ep->d_name); } else { if (!previous_flag && stat_result) { // looking for new, and did not find touch file l = insert_item(ep->d_name, l); debug_log("Adding candidate: %s/%s.", crash_dir, ep->d_name); } } } else { /* skip if there is no vmcore file */ debug_log ("Skipping: %s (no vmcore found).", ep->d_name); } } closedir(dp); } else { perror ("Couldn't open crash directory."); } } else { debug_log ("Crash directory does not exist (%s), skipping.", crash_dir); } return l; }
/** * Perform the crash check. This is the primary function of the * kdump_watcher program. It builds lists of current crash * directories, and previously seen crash directories. If a new one * is found, we perform a few bits of data extraction and log the * results to Recorder. * * \returns 0 on success, non-zero otherwise * */ void LOG_PROCESS_CRASHES(void) { int rc = 0; llist* current_crash_entries = NULL; llist* previous_crash_entries = NULL; struct stat sb; /* enable debugging based on a trigger file, rather than command * line option */ memset(&sb, 0, sizeof(struct stat)); if (does_exist(DEBUG_TRIGGER_FILE)) { debug = 1; debug_log ("Found %s, enabling debugging", DEBUG_TRIGGER_FILE); } memset(&dep, 0, sizeof(os_dep_config)); get_os_deps(&dep); debug_log ("Loaded OS dependencies."); /* List entries in crash directory */ current_crash_entries = find_current_crash_entries(); if (NULL != current_crash_entries) { /* List entries in previous crash list */ previous_crash_entries = find_previous_crash_entries(); /* Process any NEW crashes that we have not seen before */ rc = process_new_crashes(current_crash_entries, previous_crash_entries); if (!rc) { /* update previous_crash_entries file */ rc = update_previous_crash_entries(current_crash_entries, previous_crash_entries); } else { debug_log("Failed to process one or more crashes. Not updating crash list."); } } else { debug_log("No crashes found."); } close_debug_log(); free_list(current_crash_entries); free_list(previous_crash_entries); return; }
/** * Determine the name of the crash directory. If the user has * specified value in /etc/kdump.conf, use it. Otherwise, use * the default value as defined in DEFAULT_CRASH_DIR. * * \param buf Character buffer to store the crash directory string in * \param bufsz Size of character buffer * \returns 0 on success, -1 on error (buffer was invalid) * */ static int get_crash_dir(char *buf, int bufsz) { char buffer[BUFSIZ]; memset(buffer, 0, BUFSIZ); if (NULL != buf) { memset(buf, 0, bufsz); if (does_exist(dep.kdump_conf)) { /* kdump.conf exists, look for path value */ int rc = get_path_value_from_file(dep.kdump_conf, buffer, BUFSIZ); if (rc) { /* failed to obtain a path from the kdump config, use * default */ debug_log("Did not find path value in %s, using default value: %s", dep.kdump_conf, dep.crash_dir); strncpy(buf, dep.crash_dir, bufsz-1); } else { /* obtained a path from the kdump config, copy it into * the result buffer */ debug_log("Found path value in %s, using: %s", dep.kdump_conf, buffer); strncpy(buf, buffer, bufsz-1); } } else { /* no kdump.conf, use default */ debug_log("No %s file found, using default: %s", dep.kdump_conf, dep.crash_dir); strncpy(buf, dep.crash_dir, bufsz-1); } } else { /* buf is NULL, so do nothing, just return error value */ return -1; } return 0; }
void * recv_data(void * args) { int check ; //USED FOR RECHECKING WHETHER THE CONNECTION IS PROPERLY ESTABLISHED OR NOT struct recv_thread_init * pass_data = (struct recv_thread_init *)(args); //ARGUMENTS GIVEN ON THREAD INITATION int new_fd = pass_data -> new_fd ; struct ser_client_trans_header transfer_header ; struct ser_user_db user_info; struct book_info book_data ; FILE * fp_user_req_file ; FILE * fp_server_users_db ; int data_code; //BIG MAIN LOOP RECEIVING THE DATA AND THEN PROCESSING IT while(1) { check = recv(new_fd,&transfer_header,sizeof(struct ser_client_trans_header),0); if(check < 0) { perror("Sending failed"); exit(0); } data_code = transfer_header.data_code ; switch(data_code) { case NOT_REG_USER : { user_info.user_id = allocate_user_id(); //ALLOCATING THE USER ID TO THE USER user_info.num_requests = INITIALISED_TO_ZERO; fp_server_users_db = fopen("server_users_db","r+b"); flock(fileno(fp_server_users_db),LOCK_EX); fseek(fp_server_users_db,0,SEEK_END); //WRITING ABOUT THE USER INFO AT THE END OF THE FILE fwrite(&user_info, sizeof(ser_user_db), 1,fp_server_users_db); flock(fileno(fp_server_users_db),LOCK_UN); fclose(fp_server_users_db); transfer_header.user_id = user_info.user_id; //TRANSFERRING THE USER HIS USER ID check = send(new_fd,&transfer_header,sizeof(struct ser_client_trans_header),0); if(check < 0) { perror("Sending failed"); exit(0); } fp_user_req_file = fopen(filename((char *)"user",user_info.user_id),"wb"); //FINALLY CREATING THE FILE FOR THE NON REGISTERED USER fclose(fp_user_req_file); break ; } case REG_USER : { bool user_id_exist = does_exist(transfer_header.user_id,fp_server_users_db); //SEARCHING FOR THE USER ID IN THE DATABASE if(user_id_exist == true) { transfer_header.data_code = USER_ID_EXISTS; check = send(new_fd,&transfer_header,sizeof(struct ser_client_trans_header),0); if(check < 0) { perror("Sending failed"); //USER ID EXISTS AND INFORMING THE SAME TO THE CLIENT exit(0); } user_info.user_id = transfer_header.user_id; //STORING THE USER ID TO WHICH WE ARE COMMUNICATING } else { transfer_header.data_code = USER_ID_NOT_EXISTS; check = send(new_fd,&transfer_header,sizeof(struct ser_client_trans_header),0); if(check < 0) { perror("Sending failed"); //USER ID DOES NOT EXIST AND INFORMING THE SAME TO THE CLIENT exit(0); } } break; } case TYPICAL_BOOK: { check = recv(new_fd,&book_data,sizeof(struct book_info),0); //DOING THE BOOKING HERE if(check < 0) { perror("Sending failed"); exit(0); } ps_typical_req(new_fd,&book_data,&user_info,pass_data->rooms_llist); //PROCESSING THE BOOKING HERE break ; } case CANCEL: { int request_id ; check = recv(new_fd,&request_id,sizeof(int),0); //TAKING THE REQUEST ID WHICH WE HAVE TO CANCEL if(check < 0) { perror("Sending failed"); exit(0); } ps_cancel_request(new_fd,&user_info,pass_data->rooms_llist,request_id); break ; } case REQ_STATUS: { int request_id ; check = recv(new_fd,&request_id,sizeof(int),0); //TAKING THE REQUEST ID WHICH WE HAVE TO TELL THE REQUEST STATUS if(check < 0) { perror("Sending failed"); exit(0); } ps_req_status(new_fd,&user_info,request_id); break ; } case HIGH_PRIOR_BOOK: { check = recv(new_fd,&book_data,sizeof(struct book_info),0); //DOING THE HIGH_PRIOR BOOKING HERE if(check < 0) { perror("Sending failed"); exit(0); } ps_hprior_req(new_fd,&book_data,&user_info,pass_data->rooms_llist); //PROCESSING THE HIGH_PRIOR_REQUEST break ; } } } }
void analyze_malloc_xref_ex(char *name, ea_t xref_addr, int push_count) { qstring buffer; int value = 0; int type; op_t memory_size_var; if(is_trampoline(xref_addr)){ func_t *func = get_func(xref_addr); //msg("analyze_malloc_xref: %s %a - trampoline!\n", name, xref_addr); //too easy, how about mov ebp,esp jmp:malloc? if(func){ qstring buff; get_short_name(&buff, func->startEA); //get_long_name(BADADDR, func->startEA, buffer, MAXSTR); TFuncMallocWrapper new_malloc = TFuncMallocWrapper((char *)buff.c_str(), name, push_count, xref_addr, TRAMPOLINE); if(!does_exist(new_malloc)) funcMalloc_wrappers.push_back(new_malloc); } else{ TFuncMallocWrapper new_malloc = TFuncMallocWrapper("new malloc", name, push_count, xref_addr, TRAMPOLINE); if(!does_exist(new_malloc)) funcMalloc_wrappers.push_back(new_malloc); } } ea_t push_malloc_size_addr = find_instruction_N_times_backward(xref_addr, NN_push, push_count); if(push_malloc_size_addr != BADADDR){ memory_size_var = get_first_operand_new(push_malloc_size_addr); //Allocation of const memory size if(memory_size_var.type == o_imm){ //msg("analyze_malloc_xref: %s %a - immediate!\n", name, push_malloc_size_addr); Malloc_calls.push_back(TFuncMalloc_call(xref_addr, CONSTVALUE, memory_size_var.value)); //msg("analyze_malloc_xref: %s Malloc_call_list.size() = %d!\n", name, Malloc_calls.size()); return; } //Allocation of var memory size //Allocation of var by register if(memory_size_var.type == o_reg){ ea_t addr_of_src = find_instruction_that_changes_operand_backward_smart(push_malloc_size_addr, memory_size_var); msg("analyze_malloc_xref: %s %a - var!\n", name, push_malloc_size_addr); if(addr_of_src != BADADDR){ type = assign_type(addr_of_src, &value); Malloc_calls.push_back(TFuncMalloc_call(xref_addr, type, value, addr_of_src)); } else Malloc_calls.push_back(TFuncMalloc_call(xref_addr, UNDEFINED)); msg("analyze_malloc_xref: %s Malloc_call_list.size() = %d!\n", name, Malloc_calls.size()); return; } //Allocation of var by argument - new trampoline //TODO: better algo! if( (memory_size_var.type == o_displ) && (memory_size_var.reg == 5) && (memory_size_var.phrase == 5) && (memory_size_var.value == 0) && ( (int)memory_size_var.addr > 0) ){ func_t *func = get_func(xref_addr); //too easy, how about mov ebp,esp call:malloc? if(func) get_short_name(&buffer, func->startEA); //get_long_name(BADADDR, func->startEA, buffer, MAXSTR); TFuncMallocWrapper new_malloc = TFuncMallocWrapper((char *)buffer.c_str(), name, memory_size_var.addr / sizeof(ea_t) - 1, func->startEA, WRAPPER); if(!does_exist(new_malloc)) funcMalloc_wrappers.push_back(new_malloc); //funcMalloc.push_back(TFuncMalloc("here var name", memory_size_var.addr / sizeof(ea_t),func->startEA, WRAPPER)); else{ TFuncMallocWrapper new_malloc = TFuncMallocWrapper("new malloc", name, memory_size_var.addr / sizeof(ea_t) - 1, xref_addr, WRAPPER);//maybetter name malloc_at_%a? if(!does_exist(new_malloc)) funcMalloc_wrappers.push_back(new_malloc); //funcMalloc.push_back(TFuncMalloc("here name of addr", memory_size_var.addr / sizeof(ea_t), xref_addr, WRAPPER)); } return; msg("analyze_malloc_xref: %s Malloc_call_list.size() = %d!\n", name, Malloc_calls.size()); } else{ Malloc_calls.push_back(TFuncMalloc_call(xref_addr, VARVALUE)); } } else{ Malloc_calls.push_back(TFuncMalloc_call(xref_addr, UNDEFINED)); } msg("analyze_malloc_xref: %s Malloc_call_list.size() = %d!\n", name, Malloc_calls.size()); }
static int seq_init (struct msgs *mp, char *name, char *field) { unsigned int i; int j, k, is_current; char *cp, **ap; /* * Check if this is "cur" sequence, * so we can do some special things. */ is_current = !strcmp (current, name); /* * Search for this sequence name to see if we've seen * it already. If we've seen this sequence before, * then clear the bit for this sequence from all the * mesages in this folder. */ for (i = 0; i < svector_size (mp->msgattrs); i++) { if (!strcmp (svector_at (mp->msgattrs, i), name)) { for (j = mp->lowmsg; j <= mp->hghmsg; j++) clear_sequence (mp, i, j); break; } } /* * If we've already seen this sequence name, just free the * name string. Else add it to the list of sequence names. */ if (svector_at (mp->msgattrs, i)) { free (name); } else { svector_push_back (mp->msgattrs, name); } /* * Split up the different message ranges at whitespace */ for (ap = brkstring (field, " ", "\n"); *ap; ap++) { if ((cp = strchr(*ap, '-'))) *cp++ = '\0'; if ((j = m_atoi (*ap)) > 0) { k = cp ? m_atoi (cp) : j; /* * Keep mp->curmsg and "cur" sequence in synch. Unlike * other sequences, this message doesn't need to exist. * Think about the series of command (rmm; next) to * understand why this can be the case. But if it does * exist, we will still set the bit flag for it like * other sequences. */ if (is_current) mp->curmsg = j; /* * We iterate through messages in this range * and flip on bit for this sequence. */ for (; j <= k; j++) { if (j >= mp->lowmsg && j <= mp->hghmsg && does_exist(mp, j)) add_sequence (mp, i, j); } } } free (field); /* free string containing message ranges */ return i; }