示例#1
0
/**
 * gnutls_ocsp_req_print:
 * @req: The data to be printed
 * @format: Indicate the format to use
 * @out: Newly allocated datum with (0) terminated string.
 *
 * This function will pretty print a OCSP request, suitable for
 * display to a human.
 *
 * If the format is %GNUTLS_OCSP_PRINT_FULL then all fields of the
 * request will be output, on multiple lines.
 *
 * The output @out->data needs to be deallocate using gnutls_free().
 *
 * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
 *   negative error value.
 **/
int
gnutls_ocsp_req_print(gnutls_ocsp_req_t req,
		      gnutls_ocsp_print_formats_t format,
		      gnutls_datum_t * out)
{
	gnutls_buffer_st str;
	int rc;

	if (format != GNUTLS_OCSP_PRINT_FULL) {
		gnutls_assert();
		return GNUTLS_E_INVALID_REQUEST;
	}

	_gnutls_buffer_init(&str);

	_gnutls_buffer_append_str(&str, _("OCSP Request Information:\n"));

	print_req(&str, req);

	rc = _gnutls_buffer_to_datum(&str, out, 1);
	if (rc != GNUTLS_E_SUCCESS) {
		gnutls_assert();
		return rc;
	}

	return GNUTLS_E_SUCCESS;
}
示例#2
0
int main(int argc, char **argv)
{
  if (argc < 2) {
    printf("Provide at least on parameter (err, req, handle)\n");
    exit(0);
  }

  if (!strcmp(argv[1], "err")) {
    print_err();
  } else if (!strcmp(argv[1], "req")) {
    print_req();
  } else if (!strcmp(argv[1], "handle")) {
    print_handle();
  }
  return 0;
}
示例#3
0
//Our entry-point.
int ioctl(int fd, int request, unsigned long* data){
  //The hook.
  if(request == MD_XACT){
	Request request;
	Response response;
	memcpy(&request,*(unsigned int *)data,277);
	response.return_code = 0;
	memset(response.dog_data,0x00,256);
	response.dog_serial = curr_dog.dog_serial;
	
    if(request.magic != MD_MAGIC){
     printf("ERR-BAD MAGIC\n"); 
    }
	
	crypt_request(&request);
	if(DEBUG){
		print_req(&request);
	}
	//Determine transaction - Much Functionality WOW
	switch(request.opcode){
		case MD_DOGCHECK:
			printf("MD_DOGCHECK\n");
			break;
		case MD_READDOG:
			printf("MD_READDOG\n");
			if(request.dog_password == curr_dog.dog_password){
				memcpy(&response.dog_data, curr_dog.dog_flashmem+request.dog_addr,request.dog_bytes);
			}else{
				response.return_code = MD_ERR_PW;
			}
			break;
		case MD_WRITEDOG:
			printf("MD_WRITEDOG\n");
			if(request.dog_password == curr_dog.dog_password){
				memcpy(curr_dog.dog_flashmem+request.dog_addr,&request.dog_data,request.dog_bytes);
				fseek(dogfile,0,SEEK_SET);
				fwrite(&curr_dog,224,1,dogfile);
			}else{
				response.return_code = MD_ERR_PW;
			}	
			break;
		case MD_CONVERT:
			printf("MD_CONVERT\n");
			unsigned long dog_response = convert(request.dog_bytes,request.dog_data);
			memcpy(&response.dog_data,&dog_response,4);
			break;
		case MD_SETPASSWORD:
			printf("MD_SETPASSWORD\n");
			if(request.dog_password == curr_dog.dog_password){
				curr_dog.dog_password = *(unsigned long *)request.dog_data;
				fseek(dogfile,0,SEEK_SET);
				fwrite(&curr_dog,224,1,dogfile);
				
			}else{
				response.return_code = MD_ERR_PW;
			}	
			break;
		case MD_SETSHARE:
			printf("MD_SETSHARE\n");
			b_share = request.dog_data[0];
			response.dog_data[0] = b_share;
			break;
		case MD_GETLOCKNO:
			printf("MD_GETLOCKNO\n");
			memcpy(&response.dog_data,curr_dog.mfg_serial,4);
			break;
		case MD_LOGIN:
			printf("MD_LOGIN\n");
			int j;
			for(j=0;j<8;j++){
			 response.dog_data[j] = curr_dog.vendor_id[j];
			}
			break;
		case MD_SETDOGCASCADE:
			printf("MD_SETDOGCASCADE\n");
			response.dog_data[0] = request.dog_data[0];
			break;
		case MD_RTADD:
			printf("MD_RTADD\n");
			add_rtkey(request.dog_data,request.dog_bytes,request.dog_password);
			break;
		case MD_SETDOGSERIAL:
			printf("MD_SETDOGSERIAL\n");
			set_dog_serial(request.dog_data);
			break;
		case MD_SETMFGSERIAL:
			printf("MD_SETMFGSERIAL\n");
			set_mfg_serial(request.dog_data);
			break;
		case MD_SETVID:
			printf("MD_SETVID\n");
			set_vendor_id(request.dog_data);
			break;
		case MD_RLRT:
			printf("MD_RLRT\n");
			load_dogfile();
			break;
		default:
			printf("Unsupported Opcode: %04X\n",request.opcode);
			break;	
	}
	if(DEBUG){
	print_resp(&response);
	}
	crypt_response(&request,&response);
	
	//Copy the response packet to the program.
    memcpy(*(unsigned int *)data-272,&response,208);
	return 0;
  }
  //Any other ioctl, we don't care about.
  realIOCTL(fd,request,data);  
}
示例#4
0
//!
//!
//!
//! @param[in] req
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure
//!
int prepare_validate(imager_request * req)
{
    int i = 0;
    int num_sda_parts = 0;
    imager_param *p = NULL;
    prepare_params *state = NULL;

    print_req(req);

    if ((state = EUCA_ZALLOC(1, sizeof(prepare_params))) == NULL)
        err("out of memory");

    // set defaults
    state->bootable = FALSE;
    state->cache = TRUE;
    state->work = FALSE;
    state->action = ACTION_DOWNLOAD | ACTION_CONVERT;

    // record in 'state' all specified parameters
    for (p = req->params; p != NULL && p->key != NULL; p++) {
        if (strcmp(p->key, _CACHE) == 0) {
            state->cache = parse_boolean(p->val);
        } else if (strcmp(p->key, _BOOT) == 0) {
            state->bootable = parse_boolean(p->val);
        } else if (strcmp(p->key, _ID) == 0) {
            state->id = p->val;
        } else if (strcmp(p->key, _KEY) == 0) {
            state->sshkey = parse_loginpassword(p->val);
        } else if (strcmp(p->key, _OUT) == 0) {
            state->out = p->val;
        } else if (strcmp(p->key, _WORK) == 0) {
            state->work = parse_boolean(p->val);
        } else if (strcmp(p->key, _VBR) == 0) {
            if (state->total_vbrs == (EUCA_MAX_VBRS - 1))
                err("too many vbr= parameters");
            state->vbrs[state->total_vbrs++] = p->val;
            if (strstr(p->val, ":sda1:") != NULL || strstr(p->val, ":sda2:") != NULL || strstr(p->val, ":sda3:") != NULL) {
                num_sda_parts++;
            }
        } else if (strcmp(p->key, _ACTION) == 0) {
            if (strcmp(p->val, "download") == 0) {
                state->action = ACTION_DOWNLOAD;
            } else if (strcmp(p->val, "convert") == 0) {
                state->action = ACTION_CONVERT;
            } else {
                err("unknown action parameter '%s' for command 'prepare'", p->val);
            }
        } else {
            err("invalid parameter '%s' for command 'prepare'", p->key);
        }
    }

    // ensure mandatory params are present
    if (state->total_vbrs < 1)
        err("not a single VBR was specified");

    LOGINFO("actions: download=%s convert=%s\n",
            (state->action & ACTION_DOWNLOAD) ? ("yes") : ("no"),
            (state->action & ACTION_CONVERT) ? ("yes") : ("no"))

    // if a bootable disk is requested and the expected number of partitions is present,
    // then add the boot VBR entry so an extra, 4th, boot partition will get created
    if (state->bootable && num_sda_parts > 0) {
        char buf[1024];
        snprintf(buf, sizeof(buf), BOOT_VBR_FORMAT, num_sda_parts+1);
        state->vbrs[state->total_vbrs++] = strdup(buf);
    }

    for (i = 0; i < state->total_vbrs; i++) {
        if (vbr_add_ascii(state->vbrs[i], &(state->vm)))
            err("failed to add VBR record '%s'", state->vbrs[i]);
    }

    if (vbr_parse(&(state->vm), NULL) != EUCA_OK)
        err("failed to validate VBR records");

    // if given an empty key file, just set the pointer to NULL
    if (state->sshkey && strlen(state->sshkey) == 0) {
        EUCA_FREE(state->sshkey);
    }
    // save pointer to find it later
    req->internal = ((void *)state);
    return (EUCA_OK);
}
示例#5
0
//!
//!
//!
//! @param[in] req
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure
//!
int convert_validate(imager_request * req)
{
    img_loc *loc = NULL;
    img_spec *spec = NULL;
    imager_param *p = NULL;
    convert_params *state = NULL;

    print_req(req);

    if (vddk_available == FALSE) {
        LOGERROR("failed to initialize VMware's VDDK (is LD_LIBRARY_PATH set?)\n");
        return EUCA_ERROR;
    }

    if ((state = calloc(1, sizeof(convert_params))) == NULL)
        err("out of memory");

    // default values
    state->cache = TRUE;

    // record in 'state' all specified parameters
    for (p = req->params; p != NULL && p->key != NULL; p++) {
        if (strcmp(p->key, _IN) == 0) {
            state->in = p->val;
        } else if (strcmp(p->key, _ITYPE) == 0) {
            state->in_type = parse_content_type_enum(p->val);
        } else if (strcmp(p->key, _IRANGE) == 0) {
            char * start = strtok(p->val, "-");
            char * end = strtok(NULL, "-");
            if (start == NULL || end == NULL)
                err("failed to parse range parameter " _IRANGE);
            char * endptr;
            errno = 0;
            state->start_sector = strtoll(start, &endptr, 10);
            if (errno != 0 && *endptr != '\0')
                err("failed to parse range parameter " _IRANGE);
            state->end_sector = strtoll(end, &endptr, 10);
            if (errno != 0 && *endptr != '\0')
                err("failed to parse range parameter " _IRANGE);
            if (state->start_sector > state->end_sector)
                err("start sector is greater than end sector in " _IRANGE);
        } else if (strcmp(p->key, _CACHE) == 0) {
            state->cache = parse_boolean(p->val);
        } else if (strcmp(p->key, _LOGIN) == 0) {
            state->login = parse_loginpassword(p->val);
        } else if (strcmp(p->key, _OUT) == 0) {
            state->out = p->val;
        } else if (strcmp(p->key, _OTYPE) == 0) {
            state->out_type = parse_content_type_enum(p->val);
        } else if (strcmp(p->key, _PASS) == 0) {
            state->password = parse_loginpassword(p->val);
        } else if (strcmp(p->key, _VDC) == 0) {
            state->vdc = p->val;
        } else if (strcmp(p->key, _VMDK) == 0) {
            state->vmdk = p->val;
        } else if (strcmp(p->key, _VMX) == 0) {
            state->vmx = p->val;
        } else if (strcmp(p->key, _BUFSIZE) == 0) {
            char * endptr;
            errno = 0;
            state->buf_size_bytes = strtoll(p->val, &endptr, 10);
            if (errno != 0 && *endptr != '\0')
                err("failed to parse buffer size parameter " _BUFSIZE);
        } else {
            err("invalid parameter '%s' for command 'convert'", p->key);
        }
    }

    if (state->in == NULL) {
        if (req->index < 1)
            err("parameter '" _IN "' must be specified for first command in a sequence");
        else
            state->in = "";            // so it is set to something
    }
    // ensure paired parameters are both present
    if ((state->login != NULL && state->password == NULL) || (state->login == NULL && state->password != NULL))
        err("both login and password must be specified");

    // figure out what kind of conversion this is
    char * url = NULL;
    if (strncmp("http", state->in, 4) == 0) {   // looks like a URL, so a remote conversion
        if (state->out == NULL)
            err("with a remote conversion '" _OUT "' must be specified");
        state->in_type = VMDK;
        url = state->in;
    }
    if (state->out!=NULL && strncmp("http", state->out, 4) == 0) { // output looks like a URL, so a remote conversion
        if (url != NULL)
            err("conversion from remote to remote VMDK not supported");
        state->out_type = VMDK;
        url = state->out;
    }
    if (url != NULL) { // local conversion
        if (state->in_type == GUESS) {
            if (strstr(".vmdk", state->in) != NULL) {
                state->in_type = VMDK;
            } else {
                state->in_type = DISK;
            }
        }
    }

    if (state->out_type == GUESS) {
        if (state->in_type == VMDK)
            state->out_type = DISK;
        else if (state->in_type == DISK)
            state->out_type = VMDK;
    }
    if (state->in_type == GUESS) {
        if (state->out_type == VMDK)
            state->in_type = DISK;
        else if (state->out_type == DISK)
            state->in_type = VMDK;
    }
    if (state->in_type==state->out_type)
        err("identical input and output types requested");

    if (url != NULL) { // remote conversion
        if (strstr(url, "?dcPath=") != NULL) {    // looks like a vSphere URL
            if (state->vdc) {
                err("with " _VDC " option the URL must not contain a path");
            }
            if (state->vmdk) {
                err("with " _VMDK " option the URL must not contain a path");
            }
        }
        // parse vSphere URL and maybe path
        if ((spec = calloc(1, sizeof(img_spec))) == NULL)
            err("out of memory for img_spec in convert_validate");

        loc = &(spec->location);
        if (parse_img_spec(loc, url) != EUCA_OK)
            err("failed to parse input string '%s'", state->in);

        if (state->vdc) {
            euca_strncpy(loc->vsphere_dc, state->vdc, sizeof(loc->vsphere_dc));
        }

        if (state->vmdk) {
            if (parse_vsphere_path(state->vmdk, loc->vsphere_ds, sizeof(loc->vsphere_ds), loc->path, sizeof(loc->path)) != EUCA_OK)
                err("failed to parse VMDK path");
        }

        if (state->vmx) {
            if (parse_vsphere_path(state->vmx, loc->vsphere_vmx_ds, sizeof(loc->vsphere_vmx_ds), loc->vsphere_vmx_path, sizeof(loc->vsphere_vmx_ds))
                != EUCA_OK)
                err("failed to parse VMX path");
        }
        // add login/password to the spec if we have them
        if (state->login) {
            euca_strncpy(spec->location.creds.login, state->login, sizeof(spec->location.creds.login));
            euca_strncpy(spec->location.creds.password, state->password, sizeof(spec->location.creds.password));
        }

        state->remote = spec;
    }

    if (state->buf_size_bytes == 0) {
        state->buf_size_bytes = DEFAULT_BUFFER_SIZE_BYTES;
    }

    req->internal = ((void *)state);   // save pointer to find it later
    return (EUCA_OK);
}