static void auth_ok(void *data) { struct dialog *dlg = (struct dialog *)data; struct auth_entry *entry = (struct auth_entry *)dlg->udata2; struct session *ses = (struct session *)dlg->udata; entry->blocked = 0; entry->valid = auth_entry_has_userinfo(entry); #ifdef CONFIG_FORMHIST if (get_opt_bool((const unsigned char *)"document.browse.forms.show_formhist", ses)) { unsigned char *url = get_uri_string(entry->uri, URI_HTTP_AUTH); if (url) { struct form form = {}; form.action = url; INIT_LIST_OF(struct submitted_value, submit); struct submitted_value *user, *password; user = init_submitted_value((unsigned char *)"user", entry->user, FC_TEXT, NULL, 0); if (user) { add_to_list(submit, user); } password = init_submitted_value((unsigned char *)"password", entry->password, FC_PASSWORD, NULL, 0); if (password) { add_to_list(submit, password); } memorize_form(ses, &submit, &form); done_submitted_value_list(&submit); mem_free(url); } } #endif if (entry->valid && have_location(ses)) { struct location *loc = cur_loc(ses); struct uri *uri = loc->vs.uri; /* Make a 'fake' redirect to a URI without user/password so that * the user/password from the URI will not override what the * user just entered in the dialog. */ if ((uri->userlen && strlcmp(entry->user, -1, uri->user, uri->userlen)) || (uri->password && strlcmp(entry->password, -1, uri->password, uri->passwordlen))) { uri = get_composed_uri(uri, URI_HTTP_AUTH | URI_DATA | URI_POST); if (uri) { goto_uri_frame(ses, uri, NULL, CACHE_MODE_INCREMENT); done_uri(uri); return; } } } reload(ses, CACHE_MODE_INCREMENT); }
RSDPDescriptor* ACPI_findRSDP() { // 0x000E0000 to 0x000FFFFF for(int i = 0xE0000; i < 0xFFFFF; i+=16) { if(strlcmp((char*)i, "RSD PTR ", 8)) // string length compare { //if(i & 0x10 == 0x10) return (RSDPDescriptor*)i; } } return 0; }
/* It returns a base 64 encoded user + pass suitable to use in Authorization * header, or NULL on failure. */ struct auth_entry * find_auth(struct uri *uri) { struct auth_entry *entry = NULL; #ifdef DEBUG_HTTP_AUTH DBG("find_auth: newurl=%s uri=%p", newurl, uri); #endif entry = find_auth_entry(uri, NULL); /* Check is user/pass info is in url. */ if (uri->userlen || uri->passwordlen) { /* Add a new entry either to save the user/password info from the URI * so it is available if we later get redirected to a URI with * the user/password stripped. Else if update with entry with * the user/password from the URI. */ if (!entry || (uri->userlen && strlcmp(entry->user, -1, uri->user, uri->userlen)) || (uri->password && strlcmp(entry->password, -1, uri->password, uri->passwordlen))) { entry = add_auth_entry(uri, NULL, NULL, NULL, 0); } } /* No entry found or waiting for user/password in dialog. */ if (!entry || entry->blocked) return NULL; /* Sanity check. */ if (!auth_entry_has_userinfo(entry)) { del_auth_entry(entry); return NULL; } return entry; }
/* * Parse the word "include". * * If the next word on the line is "include", parse_include() updates * *line to point one character past "include" and returns 1. Otherwise, * it leaves *line unmodified and returns 0. */ static int parse_include(char **line) { char *b, *e; for (b = *line; *b && is_lws(*b); ++b) /* nothing */ ; if (!*b) { *line = b; return (-1); } for (e = b; *e && !is_lws(*e); ++e) /* nothing */ ; if (e == b) return (0); if (strlcmp("include", b, e - b) != 0) return (0); *line = e; return (1); }
/* * Look for the symbol in the symbol table. If is is found, we return * the symbol table index, else we return -1. */ static int findsym(const char *str) { const char *cp; int symind; cp = skipsym(str); if (cp == str) return (-1); if (symlist) { printf("%.*s\n", (int)(cp-str), str); /* we don't care about the value of the symbol */ return (0); } for (symind = 0; symind < nsyms; ++symind) { if (strlcmp(symname[symind], str, cp-str) == 0) { debug("findsym %s %s", symname[symind], value[symind] ? value[symind] : ""); return (symind); } } return (-1); }
// update_default_properties_in_gzip - updates the default property file found in <boot_image_file> // boot_image_file - A valid android boot image which must contain a valid ramdisk. // ramdisk_size - The size of the gzipped ramdisk in boot_image_file // default_properties - a list of properties to written into the updated default.prop // default_properties_total - the total number of default properties in the <default_properties> list // gzipped_ramdisk_size (out) - the size of the data returned // Return - a pointer to the start of a gzip stream containing the updated default.prop byte_p update_default_properties_in_gzip(FILE* boot_image_file,size_t ramdisk_size ,default_property_list_t** default_properties,int default_properties_total,size_t*gzipped_ramdisk_size){ size_t default_prop_size=0;int i ; size_t uncompressed_ramdisk_size=0; int cpio_entries_total=0; byte_p default_prop_stream = get_contiguous_default_properties(default_properties,default_properties_total,&default_prop_size); cpio_entry_list_t** cpio_entries = get_cpio_entries_from_file(boot_image_file,ramdisk_size ,&uncompressed_ramdisk_size,&cpio_entries_total); //fprintf(stderr,"ramdisk size: %u uncompressed_ramdisk_size: %u gzipped_ramdisk_size: %u default_prop_size:%u\n ",ramdisk_size,uncompressed_ramdisk_size,gzipped_ramdisk_size,default_prop_size); for(i=0;i<cpio_entries_total;i++){ if(!strlcmp("default.prop", cpio_entries[i]->name)){ sprintf(cpio_entries[i]->start.cpio_header->c_filesize,"%08x",default_prop_size); cpio_entries[i]->data=default_prop_stream; uncompressed_ramdisk_size-=cpio_entries[i]->data_size; cpio_entries[i]->data_size=default_prop_size+(((4 - (default_prop_size) % 4)) % 4); uncompressed_ramdisk_size+=cpio_entries[i]->data_size; break; } } //fprintf(stderr,"ramdisk size: %u uncompressed_ramdisk_size: %u gzipped_ramdisk_size: %u default_prop_size:%u\n ",ramdisk_size,uncompressed_ramdisk_size,gzipped_ramdisk_size,default_prop_size); byte_p ramdisk_gzip_data = compress_cpio_entries_to_gzip( cpio_entries,cpio_entries_total,uncompressed_ramdisk_size,gzipped_ramdisk_size); //fprintf(stderr,"ramdisk size: %u uncompressed_ramdisk_size: %u gzipped_ramdisk_size: %u default_prop_size:%u\n ",ramdisk_size,uncompressed_ramdisk_size,gzipped_ramdisk_size,default_prop_size); free(default_prop_stream); free_cpio_entry_memory(cpio_entries,cpio_entries_total) ; return ramdisk_gzip_data; }
/* * Parse the control flag. * * Returns the corresponding pam_control_t value, or -1 if the end of the * string was reached, a disallowed non-whitespace character was * encountered, or the first word was not a recognized control flag. * * If parse_control_flag() is successful, it updates *line to point one * character past the end of the control flag. If it reaches the end of * the string, it updates *line to point to the terminating NUL character. * In all other cases, it leaves *line unmodified. */ static pam_control_t parse_control_flag(char **line) { char *b, *e; int i; for (b = *line; *b && is_lws(*b); ++b) /* nothing */ ; if (!*b) { *line = b; return ((pam_control_t)-1); } for (e = b; *e && !is_lws(*e); ++e) /* nothing */ ; if (e == b) return ((pam_control_t)-1); for (i = 0; i < PAM_NUM_CONTROL_FLAGS; ++i) if (strlcmp(pam_control_flag_name[i], b, e - b) == 0) break; if (i == PAM_NUM_CONTROL_FLAGS) return ((pam_control_t)-1); *line = e; return (i); }
/* * Parse the facility name. * * Returns the corresponding pam_facility_t value, or -1 if the end of the * string was reached, a disallowed non-whitespace character was * encountered, or the first word was not a recognized facility name. * * If parse_facility_name() is successful, it updates *line to point one * character past the end of the facility name. If it reaches the end of * the string, it updates *line to point to the terminating NUL character. * In all other cases, it leaves *line unmodified. */ static pam_facility_t parse_facility_name(char **line) { char *b, *e; int i; for (b = *line; *b && is_lws(*b); ++b) /* nothing */ ; if (!*b) { *line = b; return ((pam_facility_t)-1); } for (e = b; *e && !is_lws(*e); ++e) /* nothing */ ; if (e == b) return ((pam_facility_t)-1); for (i = 0; i < PAM_NUM_FACILITIES; ++i) if (strlcmp(pam_facility_name[i], b, e - b) == 0) break; if (i == PAM_NUM_FACILITIES) return ((pam_facility_t)-1); *line = e; return (i); }
static int qsort_comparer(const void* a, const void* b) { return strlcmp(*(const char**)a, *(const char**)b); }
/* * Parse a line and determine its type. We keep the preprocessor line * parser state between calls in the global variable linestate, with * help from skipcomment(). */ static Linetype get_line(void) { const char *cp; int cursym; int kwlen; Linetype retval; Comment_state wascomment; if (fgets(tline, MAXLINE, input) == NULL) return (LT_EOF); retval = LT_PLAIN; wascomment = incomment; cp = skipcomment(tline); if (linestate == LS_START) { if (*cp == '#') { linestate = LS_HASH; cp = skipcomment(cp + 1); } else if (*cp != '\0') linestate = LS_DIRTY; } if (!incomment && linestate == LS_HASH) { keyword = tline + (cp - tline); cp = skipsym(cp); kwlen = cp - keyword; /* no way can we deal with a continuation inside a keyword */ if (strncmp(cp, "\\\n", 2) == 0) Eioccc(); if (strlcmp("ifdef", keyword, kwlen) == 0 || strlcmp("ifndef", keyword, kwlen) == 0) { cp = skipcomment(cp); if ((cursym = findsym(cp)) < 0) retval = LT_IF; else { retval = (keyword[2] == 'n') ? LT_FALSE : LT_TRUE; if (value[cursym] == NULL) retval = (retval == LT_TRUE) ? LT_FALSE : LT_TRUE; if (ignore[cursym]) retval = (retval == LT_TRUE) ? LT_TRUEI : LT_FALSEI; } cp = skipsym(cp); } else if (strlcmp("if", keyword, kwlen) == 0) retval = ifeval(&cp); else if (strlcmp("elif", keyword, kwlen) == 0) retval = ifeval(&cp) - LT_IF + LT_ELIF; else if (strlcmp("else", keyword, kwlen) == 0) retval = LT_ELSE; else if (strlcmp("endif", keyword, kwlen) == 0) retval = LT_ENDIF; else { linestate = LS_DIRTY; retval = LT_PLAIN; } cp = skipcomment(cp); if (*cp != '\0') { linestate = LS_DIRTY; if (retval == LT_TRUE || retval == LT_FALSE || retval == LT_TRUEI || retval == LT_FALSEI) retval = LT_IF; if (retval == LT_ELTRUE || retval == LT_ELFALSE) retval = LT_ELIF; } if (retval != LT_PLAIN && (wascomment || incomment)) { retval += LT_DODGY; if (incomment) linestate = LS_DIRTY; } /* skipcomment should have changed the state */ if (linestate == LS_HASH) abort(); /* bug */ } if (linestate == LS_DIRTY) { while (*cp != '\0') cp = skipcomment(cp + 1); } debug("parser %s comment %s line", comment_name[incomment], linestate_name[linestate]); return (retval); }
/* * Parse a line and determine its type. We keep the preprocessor line * parser state between calls in the global variable linestate, with * help from skipcomment(). */ static Linetype parseline(void) { const char *cp; int cursym; int kwlen; Linetype retval; Comment_state wascomment; linenum++; if (fgets(tline, MAXLINE, input) == NULL) { if (ferror(input)) err(2, "can't read %s", filename); else return (LT_EOF); } if (newline == NULL) { if (strrchr(tline, '\n') == strrchr(tline, '\r') + 1) newline = newline_crlf; else newline = newline_unix; } retval = LT_PLAIN; wascomment = incomment; cp = skipcomment(tline); if (linestate == LS_START) { if (*cp == '#') { linestate = LS_HASH; firstsym = true; cp = skipcomment(cp + 1); } else if (*cp != '\0') linestate = LS_DIRTY; } if (!incomment && linestate == LS_HASH) { keyword = tline + (cp - tline); cp = skipsym(cp); kwlen = cp - keyword; /* no way can we deal with a continuation inside a keyword */ if (strncmp(cp, "\\\r\n", 3) == 0 || strncmp(cp, "\\\n", 2) == 0) Eioccc(); if (strlcmp("ifdef", keyword, kwlen) == 0 || strlcmp("ifndef", keyword, kwlen) == 0) { cp = skipcomment(cp); if ((cursym = findsym(cp)) < 0) retval = LT_IF; else { retval = (keyword[2] == 'n') ? LT_FALSE : LT_TRUE; if (value[cursym] == NULL) retval = (retval == LT_TRUE) ? LT_FALSE : LT_TRUE; if (ignore[cursym]) retval = (retval == LT_TRUE) ? LT_TRUEI : LT_FALSEI; } cp = skipsym(cp); } else if (strlcmp("if", keyword, kwlen) == 0) retval = ifeval(&cp); else if (strlcmp("elif", keyword, kwlen) == 0) retval = linetype_if2elif(ifeval(&cp)); else if (strlcmp("else", keyword, kwlen) == 0) retval = LT_ELSE; else if (strlcmp("endif", keyword, kwlen) == 0) retval = LT_ENDIF; else { linestate = LS_DIRTY; retval = LT_PLAIN; } cp = skipcomment(cp); if (*cp != '\0') { linestate = LS_DIRTY; if (retval == LT_TRUE || retval == LT_FALSE || retval == LT_TRUEI || retval == LT_FALSEI) retval = LT_IF; if (retval == LT_ELTRUE || retval == LT_ELFALSE) retval = LT_ELIF; } if (retval != LT_PLAIN && (wascomment || incomment)) { retval = linetype_2dodgy(retval); if (incomment) linestate = LS_DIRTY; } /* skipcomment normally changes the state, except if the last line of the file lacks a newline, or if there is too much whitespace in a directive */ if (linestate == LS_HASH) { size_t len = cp - tline; if (fgets(tline + len, MAXLINE - len, input) == NULL) { if (ferror(input)) err(2, "can't read %s", filename); /* append the missing newline at eof */ strcpy(tline + len, newline); cp += strlen(newline); linestate = LS_START; } else { linestate = LS_DIRTY; } } } if (linestate == LS_DIRTY) { while (*cp != '\0') cp = skipcomment(cp + 1); } debug("parser line %d state %s comment %s line", linenum, comment_name[incomment], linestate_name[linestate]); return (retval); }
/* Returns the new entry or updates an existing one. Sets the @valid member if * updating is required so it can be tested if the user should be queried. */ struct auth_entry * add_auth_entry(struct uri *uri, unsigned char *realm, unsigned char *nonce, unsigned char *opaque, unsigned int digest) { struct auth_entry *entry; #ifdef DEBUG_HTTP_AUTH DBG("add_auth_entry: newurl=%s realm=%s uri=%p", newurl, realm, uri); #endif /* Is host/realm already known ? */ entry = find_auth_entry(uri, realm); if (entry) { /* Waiting for user/pass in dialog. */ if (entry->blocked) return NULL; /* In order to use an existing entry it has to match exactly. * This is done step by step. If something isn't equal the * entry is updated and marked as invalid. */ /* If only one realm is defined or they don't compare. */ if ((!!realm ^ !!entry->realm) || (realm && entry->realm && strcmp(realm, entry->realm))) { entry->valid = 0; mem_free_set(&entry->realm, NULL); if (realm) { entry->realm = stracpy(realm); if (!entry->realm) { del_auth_entry(entry); return NULL; } if (nonce) { mem_free_set(&entry->nonce, stracpy(nonce)); if (!entry->nonce) { del_auth_entry(entry); return NULL; } } if (opaque) { mem_free_set(&entry->opaque, stracpy(opaque)); if (!entry->opaque) { del_auth_entry(entry); return NULL; } } entry->digest = digest; } } if (!*entry->user || (!uri->user || !uri->userlen || strlcmp(entry->user, -1, uri->user, uri->userlen))) { entry->valid = 0; set_auth_user(entry, uri); } if (!*entry->password || (!uri->password || !uri->passwordlen || strlcmp(entry->password, -1, uri->password, uri->passwordlen))) { entry->valid = 0; set_auth_password(entry, uri); } } else { /* Create a new entry. */ entry = init_auth_entry(uri, realm); if (!entry) return NULL; add_to_list(auth_entry_list, entry); if (nonce) { entry->nonce = stracpy(nonce); if (!entry->nonce) { del_auth_entry(entry); return NULL; } } if (opaque) { entry->opaque = stracpy(opaque); if (!entry->opaque) { del_auth_entry(entry); return NULL; } } entry->digest = digest; } /* Only pop up question if one of the protocols requested it */ if (entry && !entry->valid && entry->realm) add_questions_entry(do_auth_dialog, entry); return entry; }
/* * Initializes an OATH key with the parameters from a Google otpauth URI. * * https://github.com/google/google-authenticator/wiki/Key-Uri-Format */ int oath_key_from_uri(oath_key *key, const char *uri) { char name[64], value[256]; size_t namelen, valuelen; const char *p, *q, *r; uintmax_t n; char *e; memset(key, 0, sizeof *key); /* check method */ p = uri; if (strlcmp("otpauth://", p, 10) != 0) goto invalid; p += 10; /* check mode (hotp = event, totp = time-sync) */ if ((q = strchr(p, '/')) == NULL) goto invalid; if (strlcmp("hotp", p, q - p) == 0) { key->mode = om_hotp; } else if (strlcmp("totp", p, q - p) == 0) { key->mode = om_totp; } else { goto invalid; } p = q + 1; /* extract label */ if ((q = strchr(p, '?')) == NULL) goto invalid; key->labellen = sizeof key->label; if (percent_decode(p, q - p, key->label, &key->labellen) != 0) goto invalid; p = q + 1; /* extract parameters */ key->counter = UINT64_MAX; key->lastused = UINT64_MAX; while (*p != '\0') { /* locate name-value separator */ if ((q = strchr(p, '=')) == NULL) goto invalid; q = q + 1; /* locate end of value */ if ((r = strchr(p, '&')) == NULL) r = strchr(p, '\0'); if (r < q) /* & before = */ goto invalid; /* decode name and value*/ namelen = sizeof name; valuelen = sizeof value; if (percent_decode(p, q - p - 1, name, &namelen) != 0 || percent_decode(q, r - q, value, &valuelen) != 0) goto invalid; if (strcmp("secret", name) == 0) { if (key->keylen != 0) /* dupe */ goto invalid; key->keylen = sizeof key->key; if (base32_decode(value, valuelen, key->key, &key->keylen) != 0) goto invalid; } else if (strcmp("algorithm", name) == 0) { if (key->hash != oh_undef) /* dupe */ goto invalid; if (strcmp("SHA1", value) == 0) key->hash = oh_sha1; else if (strcmp("SHA256", value) == 0) key->hash = oh_sha256; else if (strcmp("SHA512", value) == 0) key->hash = oh_sha512; else if (strcmp("MD5", value) == 0) key->hash = oh_md5; else goto invalid; } else if (strcmp("digits", name) == 0) { if (key->digits != 0) /* dupe */ goto invalid; n = strtoumax(value, &e, 10); if (e == value || *e != '\0' || n < OATH_MIN_DIGITS || n > OATH_MAX_DIGITS) goto invalid; key->digits = n; } else if (strcmp("counter", name) == 0) { if (key->counter != UINT64_MAX) /* dupe */ goto invalid; n = strtoumax(value, &e, 10); if (e == value || *e != '\0' || n >= UINT64_MAX) goto invalid; key->counter = (uint64_t)n; } else if (strcmp("lastused", name) == 0) { if (key->lastused != UINT64_MAX) /* dupe */ goto invalid; n = strtoumax(value, &e, 10); if (e == value || *e != '\0' || n >= UINT64_MAX) goto invalid; key->lastused = (uint64_t)n; } else if (strcmp("period", name) == 0) { if (key->timestep != 0) /* dupe */ goto invalid; n = strtoumax(value, &e, 10); if (e == value || *e != '\0' || n > OATH_MAX_TIMESTEP) goto invalid; key->timestep = n; } else if (strcmp("issuer", name) == 0) { key->issuerlen = strlcpy(key->issuer, value, sizeof key->issuer); if (key->issuerlen >= sizeof key->issuer) goto invalid; } else { goto invalid; } /* final parameter? */ if (*r == '\0') break; /* skip & and continue */ p = r + 1; } /* sanity checks and default values */ if (key->mode == om_hotp) { if (key->counter == UINT64_MAX) key->counter = 0; if (key->timestep != 0) goto invalid; if (key->lastused != UINT64_MAX) goto invalid; } else if (key->mode == om_totp) { if (key->counter != UINT64_MAX) goto invalid; if (key->timestep == 0) key->timestep = OATH_DEF_TIMESTEP; if (key->lastused == UINT64_MAX) key->lastused = 0; } else { /* unreachable */ goto invalid; } if (key->hash == oh_undef) key->hash = oh_sha1; if (key->digits == 0) key->digits = 6; if (key->keylen == 0) goto invalid; return (0); invalid: memset(key, 0, sizeof *key); return (-1); }
static Linetype parseline(void) { const char *cp; int cursym; int kwlen; Linetype retval; Comment_state wascomment; linenum++; if (fgets(tline, MAXLINE, input) == NULL) return (LT_EOF); if (newline == NULL) { if (strrchr(tline, '\n') == strrchr(tline, '\r') + 1) newline = newline_crlf; else newline = newline_unix; } retval = LT_PLAIN; wascomment = incomment; cp = skipcomment(tline); if (linestate == LS_START) { if (*cp == '#') { linestate = LS_HASH; firstsym = true; cp = skipcomment(cp + 1); } else if (*cp != '\0') linestate = LS_DIRTY; } if (!incomment && linestate == LS_HASH) { keyword = tline + (cp - tline); cp = skipsym(cp); kwlen = cp - keyword; if (strncmp(cp, "\\\r\n", 3) == 0 || strncmp(cp, "\\\n", 2) == 0) Eioccc(); if (strlcmp("ifdef", keyword, kwlen) == 0 || strlcmp("ifndef", keyword, kwlen) == 0) { cp = skipcomment(cp); if ((cursym = findsym(cp)) < 0) retval = LT_IF; else { retval = (keyword[2] == 'n') ? LT_FALSE : LT_TRUE; if (value[cursym] == NULL) retval = (retval == LT_TRUE) ? LT_FALSE : LT_TRUE; if (ignore[cursym]) retval = (retval == LT_TRUE) ? LT_TRUEI : LT_FALSEI; } cp = skipsym(cp); } else if (strlcmp("if", keyword, kwlen) == 0) retval = ifeval(&cp); else if (strlcmp("elif", keyword, kwlen) == 0) retval = ifeval(&cp) - LT_IF + LT_ELIF; else if (strlcmp("else", keyword, kwlen) == 0) retval = LT_ELSE; else if (strlcmp("endif", keyword, kwlen) == 0) retval = LT_ENDIF; else { linestate = LS_DIRTY; retval = LT_PLAIN; } cp = skipcomment(cp); if (*cp != '\0') { linestate = LS_DIRTY; if (retval == LT_TRUE || retval == LT_FALSE || retval == LT_TRUEI || retval == LT_FALSEI) retval = LT_IF; if (retval == LT_ELTRUE || retval == LT_ELFALSE) retval = LT_ELIF; } if (retval != LT_PLAIN && (wascomment || incomment)) { retval += LT_DODGY; if (incomment) linestate = LS_DIRTY; } if (linestate == LS_HASH) { size_t len = cp - tline; if (fgets(tline + len, MAXLINE - len, input) == NULL) { strcpy(tline + len, newline); cp += strlen(newline); linestate = LS_START; } else { linestate = LS_DIRTY; } } } if (linestate == LS_DIRTY) { while (*cp != '\0') cp = skipcomment(cp + 1); } debug("parser line %d state %s comment %s line", linenum, comment_name[incomment], linestate_name[linestate]); return (retval); }
int main(int argc, char** argv){ char* filename; char* ramdisk_filename; boot_image image; fprintf(stderr,"\nBoot image ramdisk extract and unpack test\n"); if(argc == 1){ fprintf(stderr,"No filename : using default boot.img\n"); filename="boot.img"; fprintf(stderr,"No radisk_filename : using default init.rc\n"); ramdisk_filename="init.rc"; }else{ fprintf(stderr,"filename %s\n",argv[1]); filename=argv[1]; } if(argc == 2){ fprintf(stderr,"No ramdisk filename : using default.prop\n"); ramdisk_filename="default.prop"; }else{ if(!ramdisk_filename) ramdisk_filename = argv[2]; } int return_value = load_boot_image(filename,&image); fprintf(stderr,"load_boot_image function returns %d %s\n",return_value,strerror(return_value)); if(return_value != 0){ if(image.start_addr != NULL ) free(image.start_addr); return return_value; } ramdisk_image rimage; return_value = load_ramdisk_image(image.ramdisk_addr,image.ramdisk_size,&rimage); fprintf(stderr,"load_ramdisk_image function returns %d %s\n",return_value,strerror(return_value)); if(return_value != 0){ if(rimage.start_addr != NULL ) free(rimage.start_addr); return return_value; } fprintf(stderr,"\nramdisk_image struct values:\n"); fprintf(stderr," start_addr :%p\n",rimage.start_addr); fprintf(stderr," size :%u\n",rimage.size); fprintf(stderr," compression_type :%s\n",str_ramdisk_compression(rimage.compression_type)); fprintf(stderr," type :%s\n",str_ramdisk_type(rimage.type)); fprintf(stderr," entry_count :%u\n",rimage.entry_count); fprintf(stderr," entries :%p\n",rimage.entries); unsigned counter = 0; fprintf(stderr,"\nramdisk_entries struct values:\n"); for(counter = 0 ; counter < rimage.entry_count ; counter++){ // fprintf(stderr," rimage.entries[%02u].name :%s\n",counter,rimage.entries[counter]->name_addr); if(!strlcmp(rimage.entries[counter]->name_addr,ramdisk_filename)){ fprintf(stderr," rimage.entries[%02u] :%p\n",counter,rimage.entries[counter]); fprintf(stderr," rimage.entries[%02u].start_addr :%p\n",counter,rimage.entries[counter]->start_addr); fprintf(stderr," rimage.entries[%02u].name_addr :%p\n",counter,rimage.entries[counter]->name_addr); fprintf(stderr," rimage.entries[%02u].data_addr :%p\n",counter,rimage.entries[counter]->data_addr); fprintf(stderr," rimage.entries[%02u].next_addr :%p\n",counter,rimage.entries[counter]->next_addr); fprintf(stderr," rimage.entries[%02u].mode :%u\n",counter,rimage.entries[counter]->mode); fprintf(stderr," rimage.entries[%02u].name_size :%u\n",counter,rimage.entries[counter]->name_size); fprintf(stderr," rimage.entries[%02u].name_padding :%u\n",counter,rimage.entries[counter]->name_padding); fprintf(stderr," rimage.entries[%02u].name :%s\n",counter,rimage.entries[counter]->name_addr); fprintf(stderr," rimage.entries[%02u].data_size :%u\n",counter,rimage.entries[counter]->data_size); fprintf(stderr," rimage.entries[%02u].data_padding :%u\n",counter,rimage.entries[counter]->data_padding); fprintf(stderr,"\ncontents of %s:\n\n",rimage.entries[counter]->name_addr); FILE *fp = fopen(ramdisk_filename,"wb"); fwrite(rimage.entries[counter]->data_addr,rimage.entries[counter]->data_size,1,fp); fclose(fp); break; } } //fprintf(stderr," config_size :%u\n",kimage.config_size); //fprintf(stderr," version :%s\n",kimage.version); //fprintf(stderr,"\nSaving ramdisk entries disk\n"); //save_ramdisk_entries_to_disk(&rimage,"ramdisk"); //FILE* fp = fopen("unpacked_kernel","w+b"); //fwrite(kimage.start_addr,kimage.size,1,fp); //fclose(fp); //fprintf(stderr,"Saving kernel config.gz to config.gz\n"); //fp = fopen("config.gz","w+b"); //fwrite(kimage.config_addr,kimage.config_size,1,fp); //fclose(fp); free(rimage.entries); free(rimage.start_addr); free(image.start_addr); return 0; }
/* * Extracts given chains from a policy file. */ static int openpam_parse_chain(pam_handle_t *pamh, const char *service, pam_facility_t facility, const char *filename, openpam_style_t style) { pam_chain_t *this, **next; pam_facility_t fclt; pam_control_t ctlf; char *line0, *line, *str, *name; char *option, **optv; int len, lineno, ret; FILE *f; if ((f = fopen(filename, "r")) == NULL) { openpam_log(errno == ENOENT ? PAM_LOG_DEBUG : PAM_LOG_NOTICE, "%s: %m", filename); return (PAM_SUCCESS); } if (openpam_check_desc_owner_perms(filename, fileno(f)) != 0) { fclose(f); return (PAM_SYSTEM_ERR); } this = NULL; name = NULL; lineno = 0; while ((line0 = line = openpam_readline(f, &lineno, NULL)) != NULL) { /* get service name if necessary */ if (style == pam_conf_style) { if ((len = parse_service_name(&line, &str)) == 0) { openpam_log(PAM_LOG_NOTICE, "%s(%d): invalid service name (ignored)", filename, lineno); FREE(line0); continue; } if (strlcmp(service, str, len) != 0) { FREE(line0); continue; } } /* get facility name */ if ((fclt = parse_facility_name(&line)) == (pam_facility_t)-1) { openpam_log(PAM_LOG_ERROR, "%s(%d): missing or invalid facility", filename, lineno); goto fail; } if (facility != fclt && facility != PAM_FACILITY_ANY) { FREE(line0); continue; } /* check for "include" */ if (parse_include(&line)) { if ((len = parse_service_name(&line, &str)) == 0) { openpam_log(PAM_LOG_ERROR, "%s(%d): missing or invalid filename", filename, lineno); goto fail; } if ((name = strndup(str, len)) == NULL) goto syserr; if (parse_eol(&line) != 0) { openpam_log(PAM_LOG_ERROR, "%s(%d): garbage at end of line", filename, lineno); goto fail; } ret = openpam_load_chain(pamh, name, fclt); FREE(name); if (ret != PAM_SUCCESS) goto fail; FREE(line0); continue; } /* get control flag */ if ((ctlf = parse_control_flag(&line)) == (pam_control_t)-1) { openpam_log(PAM_LOG_ERROR, "%s(%d): missing or invalid control flag", filename, lineno); goto fail; } /* get module name */ if ((len = parse_filename(&line, &str)) == 0) { openpam_log(PAM_LOG_ERROR, "%s(%d): missing or invalid module name", filename, lineno); goto fail; } if ((name = strndup(str, len)) == NULL) goto syserr; /* allocate new entry */ if ((this = calloc(1, sizeof *this)) == NULL) goto syserr; this->flag = ctlf; /* get module options */ if ((this->optv = malloc(sizeof *optv)) == NULL) goto syserr; this->optc = 0; while ((option = parse_option(&line)) != NULL) { optv = realloc(this->optv, (this->optc + 2) * sizeof *optv); if (optv == NULL) goto syserr; this->optv = optv; this->optv[this->optc++] = option; } this->optv[this->optc] = NULL; if (*line != '\0') { openpam_log(PAM_LOG_ERROR, "%s(%d): syntax error in module options", filename, lineno); goto fail; } /* load module */ this->module = openpam_load_module(name); FREE(name); if (this->module == NULL) goto fail; /* hook it up */ for (next = &pamh->chains[fclt]; *next != NULL; next = &(*next)->next) /* nothing */ ; *next = this; this = NULL; /* next please... */ FREE(line0); } if (!feof(f)) goto syserr; fclose(f); return (PAM_SUCCESS); syserr: openpam_log(PAM_LOG_ERROR, "%s: %m", filename); fail: if (this && this->optc) { while (this->optc--) FREE(this->optv[this->optc]); FREE(this->optv); } FREE(this); FREE(line0); FREE(name); fclose(f); return (PAM_SYSTEM_ERR); }