/* Setup/teardown for this suite */ static int init_suite(void) { char *xmlstr; xmlstr = file_to_str(xmlfile); schema = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !schema ) return 1; xmlstr = file_to_str(xmlfile_xy); schema_xy = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !schema_xy ) return 1; xmlstr = file_to_str(xmlfile_xyz); schema_xyz = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !schema_xyz ) return 1; xmlstr = file_to_str(xmlfile_xym); schema_xym = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !schema_xym ) return 1; xmlstr = file_to_str(xmlfile_xyzm); schema_xyzm = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !schema_xyzm ) return 1; return 0; }
/* Setup/teardown for this suite */ static int init_suite(void) { char *xmlstr = file_to_str(xmlfile); schema = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !schema ) return 1; xmlstr = file_to_str(simplexmlfile); simpleschema = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !simpleschema ) return 1; xmlstr = file_to_str(simplexmlfile_nointensity); simpleschema_nointensity = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !simpleschema_nointensity ) return 1; xmlstr = file_to_str(lasxmlfile); lasschema = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !lasschema ) return 1; xmlstr = file_to_str(simplelazxmlfile); simplelazschema = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !simplelazschema ) return 1; return 0; }
/* Setup/teardown for this suite */ static int init_suite(void) { char *xmlstr = file_to_str(simplexmlfile); simpleschema = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !simpleschema ) return 1; xmlstr = file_to_str(multipledimxmlfile); multipledimschema = pc_schema_from_xml(xmlstr); pcfree(xmlstr); if ( !multipledimschema ) return 1; return 0; }
/* Setup/teardown for this suite */ static int init_suite(void) { char *xmlstr = file_to_str(schemafile); if ( ! xmlstr ) return GHT_ERROR; return ght_schema_from_xml_str(xmlstr, &simpleschema); }
/* Setup/teardown for this suite */ static int init_suite(void) { char *xmlstr = file_to_str(xmlfile); int rv = pc_schema_from_xml(xmlstr, &schema); pcfree(xmlstr); return rv == PC_FAILURE ? -1 : 0; }
/* Setup/teardown for this suite */ static int init_suite(void) { GhtErr result; char *xmlstr = file_to_str("test/data/simple-schema.xml"); result = ght_schema_from_xml_str(xmlstr, &schema); ght_free(xmlstr); return result; }
GhtNodeList * tsv_file_to_node_list(const char *fname, const GhtSchema *schema) { GhtNodeList *nodelist; char *ptr_start, *ptr_end, *tmp; char *filestr = file_to_str(fname); double dblval[16]; /* Only going to handle files 16 columns wide */ int field_num = 0; if ( ! filestr ) return NULL; ght_nodelist_new(16, &nodelist); ptr_start = ptr_end = filestr; while( 1 ) { if ( *ptr_end == '\t' || *ptr_end == '\n' || *ptr_end == '\0' ) { char ptr_tmp = *ptr_end; *ptr_end = '\0'; dblval[field_num] = atof(ptr_start); *ptr_end = ptr_tmp; ptr_start = ptr_end; if ( *ptr_end == '\n' || ! ptr_end ) { int i; GhtCoordinate coord; GhtNode *node; if ( schema->num_dims != field_num + 1 ) return NULL; coord.x = dblval[0]; coord.y = dblval[1]; ght_node_new_from_coordinate(&coord, 16, &node); for ( i = 2; i < schema->num_dims; i++ ) { GhtAttribute *a; ght_attribute_new_from_double(schema->dims[i], dblval[i], &a); ght_node_add_attribute(node, a); } ght_nodelist_add_node(nodelist, node); field_num = 0; } else field_num++; /* All done! */ if ( *ptr_end == '\0' ) break; } ptr_end++; } return nodelist; }
/* Setup/teardown for this suite */ static int init_suite(void) { GhtErr result; schema = NULL; xmlstr = file_to_str(xmlfile); result = ght_schema_from_xml_str(xmlstr, &schema); return result; }
/* Setup/teardown for this suite */ static int init_suite(void) { char *xmlstr = file_to_str(xmlfile); int rv = pc_schema_from_xml(xmlstr, &schema); pcfree(xmlstr); if ( rv == PC_FAILURE ) return 1; xmlstr = file_to_str(simplexmlfile); rv = pc_schema_from_xml(xmlstr, &simpleschema); pcfree(xmlstr); if ( rv == PC_FAILURE ) return 1; xmlstr = file_to_str(lasxmlfile); rv = pc_schema_from_xml(xmlstr, &lasschema); pcfree(xmlstr); if ( rv == PC_FAILURE ) return 1; return 0; }
static void test_schema_compression_lazperf(void) { PCSCHEMA *myschema = NULL; char *myxmlfile = "data/simple-schema-laz.xml"; char *xmlstr = file_to_str(myxmlfile); myschema = pc_schema_from_xml(xmlstr); CU_ASSERT_PTR_NOT_NULL(myschema); int compression = myschema->compression; CU_ASSERT_EQUAL(compression, PC_LAZPERF); pc_schema_free(myschema); pcfree(xmlstr); }
static void test_schema_from_xml() { static PCSCHEMA *myschema = NULL; char *xmlstr = file_to_str(xmlfile); int rv = pc_schema_from_xml(xmlstr, &myschema); pcfree(xmlstr); // char *schemastr = pc_schema_to_json(schema); // printf("ndims %d\n", schema->ndims); // printf("name0 %s\n", schema->dims[0]->name); // printf("%s\n", schemastr); CU_ASSERT(myschema != NULL); pc_schema_free(myschema); }
int check_loader_nt() { // load boot.ini into a string char *boot_ini = boot_ini_path(); if(!boot_ini) return 0; FILE *f = fopen(boot_ini, "r"); free(boot_ini); if(!f) return 0; char *boot = file_to_str(f); fclose(f); char *pupldr = strstr(boot, "pupldr"); free(boot); return pupldr != NULL; }
int has_valuable_info(const char *menu) { FILE *f = fopen(menu, "r"); if(!f) return 1; char *menu_contents = file_to_str(f); fclose(f); section_node_t *secs = get_sections(menu_contents); for(section_node_t *cur = secs; cur; cur = cur->next) { section_t *sec = cur->val; if(sec->type != S_HEADER && sec->type != S_FOOTER) { free_section_node_t(secs); free(menu_contents); return 1; } } free_section_node_t(secs); free(menu_contents); return 0; }
int fix_grub2_inner(lickdir_t *lick, grub2_fix_function function, char original_drive) { char drive = original_drive; if(!drive) { drive = mount_uefi_partition(); if(!drive) { lick->err = strdup2("Could not mount UEFI partition."); return 0; } } char *lick_grub = strdup2("?:/efi/lick/" GRUB2_EFI); char *lick_shim = strdup2("?:/efi/lick/shim.efi"); char *lick_mokmanager = strdup2("?:/efi/lick/" MOKMANAGER_EFI); char *boot_grub = strdup2("?:/efi/boot/" GRUB2_EFI); char *boot_shim = strdup2("?:/efi/boot/shim.efi"); char *boot_mokmanager = strdup2("?:/efi/boot/" MOKMANAGER_EFI); char *boot_file = strdup("?:/efi/boot/bootx64.efi"); char *boot_file_backup = strdup2("?:/efi/boot/bootx64-orig.efi"); char *ms_loader = strdup2("?:/efi/microsoft/boot/bootmgfw.efi"); char *ms_loader_backup = strdup2("?:/efi/microsoft/boot/bootmgfw-backup.efi"); char *grub_cfg = unix_path(concat_strs(2, lick->drive, "/lickgrub.cfg")); char *grub_menu = NULL; lick_grub[0] = drive; lick_shim[0] = drive; lick_mokmanager[0] = drive; boot_grub[0] = drive; boot_shim[0] = drive; boot_mokmanager[0] = drive; ms_loader[0] = drive; ms_loader_backup[0] = drive; boot_file[0] = drive; boot_file_backup[0] = drive; const char *fatal_warning = "WARNING! The fix has only been half applied.\n" "The system may not boot when rebooted.\n" "Find out why renaming files on the UEFI partition is not working,\n" "then move `/EFI/Microsoft` to `/EFI/Microsoft-backup`."; grub2_fix_status status = GRUB2_FIX_UNINSTALLED; if(path_exists(boot_grub) || path_exists(boot_mokmanager) || path_exists(ms_loader_backup) || path_exists(boot_file_backup)) { if(path_exists(boot_grub) && path_exists(boot_mokmanager) && path_exists(ms_loader_backup) && path_exists(boot_file_backup)) status = GRUB2_FIX_INSTALLED; else status = GRUB2_FIX_PARTLY_INSTALLED; } int ret = 0; if(function == GRUB2_FIX_CHECK) { if(status == GRUB2_FIX_INSTALLED) ret = 1; } else if(status == GRUB2_FIX_PARTLY_INSTALLED) lick->err = strdup2("Partial boot fix applied."); else if(function == GRUB2_FIX_INSTALL && status == GRUB2_FIX_INSTALLED) lick->err = strdup2("Boot fix already applied!"); else if(function == GRUB2_FIX_UNINSTALL && status == GRUB2_FIX_UNINSTALLED) ret = 1; else if(function == GRUB2_FIX_INSTALL) { /* Steps: * 1) Copy `/EFI/LICK/{grubx64,shim,MokManager}.efi` to `/EFI/Boot/` * 2) Rename `/EFI/Boot/bootx64.efi` to `bootx64-orig.efi` * 3) Rename `/EFI/Boot/shim.efi` to `bootx64.efi` * 4) Rename `/EFI/Microsoft/Boot/bootmgfw.efi` to `bootmgfw-backup.efi` */ do { int fail = 1; do { if(!copy_file(boot_grub, lick_grub)) break; if(!copy_file(boot_shim, lick_shim)) break; if(!copy_file(boot_mokmanager, lick_mokmanager)) break; if(!copy_file(boot_file_backup, boot_file)) break; attrib_t boot_attrs = attrib_open(boot_file); if(!replace_file(boot_file, boot_shim)) { attrib_save(boot_file, boot_attrs); lick->err = strdup2("Could not overwrite boot file."); break; } if(!rename_file(ms_loader_backup, ms_loader)) { // Try to restore the backup. if(!replace_file(boot_file, boot_file_backup)) { // At this point we are stuck with the fix being // half applied. Realistically, this should never occur. attrib_save(boot_file, boot_attrs); lick->err = strdup2(fatal_warning); fail = 0; break; } lick->err = strdup2("Could not rename directory."); break; } attrib_save(boot_file_backup, boot_attrs); fail = 0; } while(0); if(fail) { unlink_file(boot_grub); unlink_file(boot_shim); unlink_file(boot_mokmanager); unlink_file(boot_file_backup); if(!lick->err) lick->err = strdup2("Could not copy files on EFI partition."); break; } // Edit grub menu. FILE *f = fopen(grub_cfg, "r"); if(!f) { if(!lick->err) lick->err = strdup2("Successfully installed, but could not modify configuration file."); break; } grub_menu = file_to_str(f); fclose(f); char *grub_menu_lower = lower_str(strdup2(grub_menu)); // Search for `/efi/microsoft` (case insensitive) // and replace with `/efi/microsoft-backup` // First, find the number of `/efi/microsoft` size_t cnt = 0; const char *str = grub_menu_lower; const char *needle = "/efi/microsoft/boot/bootmgfw.efi"; const char *replacement = "/efi/microsoft/boot/bootmgfw-backup.efi"; for(;;) { str = strstr(str, needle); if(!str) break; ++cnt; ++str; // Increment string to find the next occurrance. } if(cnt > 0) { /* Here, there are 3 strings: * - The original menu, grub_menu. * This is pointed to by start and str_normal. * - The lowercase menu, grub_menu_lower. * This is pointed to by str. * - The new menu, new_grub_menu. * This is pointed to by dst. */ size_t newsize = strlen(grub_menu) + cnt * (strlen(replacement) - strlen(needle)) + 1; char *new_grub_menu = malloc(newsize); char *dst = new_grub_menu; const char *start = grub_menu; str = grub_menu_lower; for(size_t i = 0; i < cnt; ++i) { str = strstr(str, needle); const char *str_normal = str - grub_menu_lower + grub_menu; // Print everything from start to str. size_t len = str_normal - start; memcpy(dst, start, len); dst += len; strcpy(dst, replacement); str += strlen(needle); dst += strlen(replacement); start = str_normal + strlen(needle); } strcpy(dst, start); grub_menu[newsize - 1] = '\0'; f = fopen(grub_cfg, "w"); if(!f) { if(!lick->err) lick->err = strdup2("Successfully installed, but could not modify configuration file."); free(new_grub_menu); free(grub_menu_lower); break; } fprintf(f, "%s", new_grub_menu); fclose(f); free(new_grub_menu); free(grub_menu_lower); } ret = 1; } while(0); } else { /* Steps: * 1) Rename `/EFI/Microsoft/Boot/bootmgfw-backup.efi` to `bootmgfw.efi` * 2) Rename `/EFI/Boot/bootx64-orig.efi` to `bootx64.efi` * 3) Delete `/EFI/Boot/{grubx64,MokManager}.efi` */ do { if(!rename_file(ms_loader, ms_loader_backup)) { lick->err = strdup2("Could not rename directory."); break; } attrib_t boot_attrs = attrib_open(boot_file_backup); if(!replace_file(boot_file, boot_file_backup)) { attrib_save(boot_file_backup, boot_attrs); if(!rename_file(ms_loader_backup, ms_loader)) { lick->err = strdup2(fatal_warning); break; } lick->err = strdup2("Could not replace boot file."); break; } attrib_save(boot_file, boot_attrs); unlink_file(boot_grub); unlink_file(boot_mokmanager); ret = 1; } while(0); } if(!original_drive) unmount_uefi_partition(drive); free(lick_grub); free(lick_shim); free(lick_mokmanager); free(boot_grub); free(boot_shim); free(boot_mokmanager); free(ms_loader); free(ms_loader_backup); free(boot_file); free(boot_file_backup); free(grub_cfg); free(grub_menu); return ret; }