Exemple #1
0
int __cdecl main(int argc, char *argv[])
{
	int ID;
	char *image;
	
	printf("GhostTool version %s\n", GHOST_VERSION);

	if (argc < 3) {
		print_help();
		return 0;
	}

	ID = (int)argv[2][0] - 0x30;
	if (ID < 0 || ID > 9) {
		printf("Error: ID must be between 0 and 9\n");
		return -1;
	}

	if (!strcmp(argv[1], "mount")) {
		/* we are going to mount an image */
		mount_image(ID);
	}
	else if (!strcmp(argv[1], "umount")) {
		/* we have to umount an image */
		umount_image(ID);
	}
	else {
		print_help();
	}

	return 0;
}
//int build_glance_image_policy(char * uuid,void ** boot_pcrs, void ** running_pcrs,int devno,void ** policy)
int build_glance_image_policy(char * uuid,void ** boot_pcrs, void ** running_pcrs,void ** policy)
{

	char cmd[512];
	char desc[512];
	char namebuf[512];
	char digest[DIGEST_SIZE];
	struct policy_file * pfile;
	struct vm_policy * image_policy;
	void * struct_template;
	int ret;
	void * sec_respool;
	void * sec_res;

	struct tcm_pcr_set * image_boot_pcrs;
	struct tcm_pcr_set * image_running_pcrs;


        sprintf(namebuf,"/var/lib/glance/images/%s",uuid);

	char dev[DIGEST_SIZE*2];
	char part_dev[DIGEST_SIZE*2];
	char mountpoint[DIGEST_SIZE*2];

	/*

	sprintf(dev,"/dev/nbd%d",devno);
	sprintf(mountpoint,"./mnt%d",devno);
	*/
	sec_respool=find_sec_respool("image_mntpoint");
	ret=sec_respool_getres(sec_respool,&sec_res);
	sec_resource_getvalue(sec_res,"dev_name",dev);
	sec_resource_getvalue(sec_res,"mount_path",mountpoint);

	sprintf(cmd,"mkdir %s",mountpoint);
	system(cmd);  

	mount_image(namebuf,dev,mountpoint);
	
	ret=build_image_boot_pcrs(dev,mountpoint,uuid,&image_boot_pcrs);
	ret=build_image_running_pcrs(dev,mountpoint,uuid,&image_running_pcrs);

	ret=build_entity_policy(uuid,NULL,image_boot_pcrs,image_running_pcrs,uuid,&image_policy);

	if(image_policy!=NULL)
	AddPolicy(image_policy,"IMGP");
	umount_image(dev,mountpoint);
	sprintf(cmd,"rmdir %s",mountpoint);
	system(cmd);  
	ExportPolicy("IMGP");
	*boot_pcrs=image_boot_pcrs;
	*running_pcrs=image_running_pcrs;
	*policy=image_policy;
	return 0;
}
//int build_glance_image_pcrlib(char * uuid,int devno,char * image_desc,int trust_level)
int build_glance_image_pcrlib(char * uuid,char * image_desc,int trust_level)
{

	char cmd[512];
	char desc[512];
	char namebuf[512];
	char digest[DIGEST_SIZE];
	struct policy_file * pfile;
	void * struct_template;
	int ret;
	void * sec_respool;
	void * sec_res;


        sprintf(namebuf,"/var/lib/glance/images/%s",uuid);

	char dev[DIGEST_SIZE*2];
	char part_dev[DIGEST_SIZE*2];
	char mountpoint[DIGEST_SIZE*2];

	/*

	sprintf(dev,"/dev/nbd%d",devno);
	sprintf(mountpoint,"./mnt%d",devno);
	*/
	sec_respool=find_sec_respool("image_mntpoint");
	ret=sec_respool_getres(sec_respool,&sec_res);
	sec_resource_getvalue(sec_res,"dev_name",dev);
	sec_resource_getvalue(sec_res,"mount_path",mountpoint);

	sprintf(cmd,"mkdir %s",mountpoint);
	system(cmd);  

	mount_image(namebuf,dev,mountpoint);
	
	ret=build_image_pcrlib(dev,mountpoint,image_desc,trust_level);
	umount_image(dev,mountpoint);
	sprintf(cmd,"rmdir %s",mountpoint);
	system(cmd);  
	return 0;
}