예제 #1
0
파일: luks.c 프로젝트: yumingfei/libguestfs
int
do_luks_kill_slot (const char *device, const char *key, int keyslot)
{
  char *tempfile = write_key_to_temp (key);
  if (!tempfile)
    return -1;

  const char *argv[MAX_ARGS];
  char keyslot_s[16];
  size_t i = 0;

  ADD_ARG (argv, i, str_cryptsetup);
  ADD_ARG (argv, i, "-q");
  ADD_ARG (argv, i, "-d");
  ADD_ARG (argv, i, tempfile);
  ADD_ARG (argv, i, "luksKillSlot");
  ADD_ARG (argv, i, device);
  snprintf (keyslot_s, sizeof keyslot_s, "%d", keyslot);
  ADD_ARG (argv, i, keyslot_s);
  ADD_ARG (argv, i, NULL);

  char *err;
  int r = commandv (NULL, &err, (const char * const *) argv);
  remove_temp (tempfile);

  if (r == -1) {
    reply_with_error ("%s", err);
    free (err);
    return -1;
  }

  free (err);

  return 0;
}
예제 #2
0
파일: luks.c 프로젝트: yumingfei/libguestfs
static int
luks_open (const char *device, const char *key, const char *mapname,
           int readonly)
{
  /* Sanity check: /dev/mapper/mapname must not exist already.  Note
   * that the device-mapper control device (/dev/mapper/control) is
   * always there, so you can't ever have mapname == "control".
   */
  size_t len = strlen (mapname);
  char devmapper[len+32];
  snprintf (devmapper, len+32, "/dev/mapper/%s", mapname);
  if (access (devmapper, F_OK) == 0) {
    reply_with_error ("%s: device already exists", devmapper);
    return -1;
  }

  char *tempfile = write_key_to_temp (key);
  if (!tempfile)
    return -1;

  const char *argv[MAX_ARGS];
  size_t i = 0;

  ADD_ARG (argv, i, str_cryptsetup);
  ADD_ARG (argv, i, "-d");
  ADD_ARG (argv, i, tempfile);
  if (readonly) ADD_ARG (argv, i, "--readonly");
  ADD_ARG (argv, i, "luksOpen");
  ADD_ARG (argv, i, device);
  ADD_ARG (argv, i, mapname);
  ADD_ARG (argv, i, NULL);

  char *err;
  int r = commandv (NULL, &err, (const char * const *) argv);
  remove_temp (tempfile);

  if (r == -1) {
    reply_with_error ("%s", err);
    free (err);
    return -1;
  }

  free (err);

  udev_settle ();

  return 0;
}
예제 #3
0
파일: luks.c 프로젝트: yumingfei/libguestfs
static int
luks_format (const char *device, const char *key, int keyslot,
             const char *cipher)
{
  char *tempfile = write_key_to_temp (key);
  if (!tempfile)
    return -1;

  const char *argv[MAX_ARGS];
  char keyslot_s[16];
  size_t i = 0;

  ADD_ARG (argv, i, str_cryptsetup);
  ADD_ARG (argv, i, "-q");
  if (cipher) {
    ADD_ARG (argv, i, "--cipher");
    ADD_ARG (argv, i, cipher);
  }
  ADD_ARG (argv, i, "--key-slot");
  snprintf (keyslot_s, sizeof keyslot_s, "%d", keyslot);
  ADD_ARG (argv, i, keyslot_s);
  ADD_ARG (argv, i, "luksFormat");
  ADD_ARG (argv, i, device);
  ADD_ARG (argv, i, tempfile);
  ADD_ARG (argv, i, NULL);

  char *err;
  int r = commandv (NULL, &err, (const char * const *) argv);
  remove_temp (tempfile);

  if (r == -1) {
    reply_with_error ("%s", err);
    free (err);
    return -1;
  }

  free (err);

  udev_settle ();

  return 0;
}
예제 #4
0
파일: evilloop.c 프로젝트: pscha/tines
Node *evilloop (Node *pos)
{
	cli_outfun = set_status;

	while (!quit_tines) {
		Tbinding *binding;

		ui_draw (pos, inputbuf, 0);
		binding = parsekey (ui_input (), ui_current_scope);
		do {

			switch (binding->action) {
				case ui_action_quit:
					remove_temp (&pos);
					quit_tines = 1;
					break;
				case ui_action_command:
					if(!string_isoneof(binding->action_param, no_remove_temp_commands))
						remove_temp (&pos);
					pos = docmd (pos, binding->action_param);
					if(!string_isoneof(binding->action_param,keep_inputbuf))
						inputbuf[0] = 0;
					break;
				case ui_action_top:
					remove_temp (&pos);
					inputbuf[0] = 0;
					pos = node_top (pos);
					break;
				case ui_action_bottom:
					remove_temp (&pos);
					inputbuf[0] = 0;
					pos = node_bottom (pos);
					break;
				case ui_action_up:
					if (!remove_temp (&pos)) {
						if(forced_up){
							if (node_forced_up (pos)){
								pos = node_forced_up (pos);
							}
						} else {
							if (node_up (pos)){
								pos = node_up (pos);
							}
						}
					}
					inputbuf[0] = 0;
					break;
				case ui_action_down:
					if (!remove_temp (&pos)) {
						if(forced_down){
							if(node_forced_down(pos))
								pos = node_forced_down (pos);
						} else {
							if(node_down(pos))
								pos = node_down (pos);
						}							
						inputbuf[0] = 0;
						break;
					}
				case ui_action_pagedown:
					remove_temp (&pos);
					inputbuf[0] = 0;
					{
						int n;

						for (n = 0; n < tines_nodes_down; n++)
							if (node_down (pos)) {
								pos = node_down (pos);
							}
					}
					break;
				case ui_action_pageup:
					remove_temp (&pos);
					inputbuf[0] = 0;
					{
						int n;

						for (n = 0; n < tines_nodes_up; n++)
							if (node_up (pos))
								pos = node_up (pos);
					}
					break;
				case ui_action_left:
					if (!remove_temp (&pos)) {
						if (node_left (pos))
							pos = node_left (pos);
					}
					inputbuf[0] = 0;
					break;
				case ui_action_right:
					if (node_right (pos)) {
						pos = node_right (pos);
					} else {
						if (fixnullstring (node_get (pos, TEXT))[0]) {
							node_insert_right (pos);
							if (node_getflag (pos, F_temp))
								node_setflag (pos, F_temp, 0);
							if (!strcmp(fixnullstring(node_get(pos,"type")),"todo")){
								node_set (node_right (pos), "type","todo");
								node_set (node_right (pos), "done","no");
							}
							node_setflag (node_right (pos), F_temp, 1);
							pos = node_right (pos);
						}
					}
					inputbuf[0] = 0;
					break;
				case ui_action_complete:
					if (strcmp
						(inputbuf,
						 fixnullstring (node_get (pos, TEXT))) == 0) {
						if (node_right (pos)) {
							pos = node_right (pos);
						} else {
							if (fixnullstring (node_get (pos, TEXT))[0]) {
								node_insert_right (pos);
								if (node_getflag (pos, F_temp))
									node_setflag (pos, F_temp, 0);
								if (!strcmp(fixnullstring(node_get(pos,"type")),"todo")){
									node_set (node_right (pos), "type","todo");
									node_set (node_right (pos), "done","no");
								}
								node_setflag (node_right (pos), F_temp, 1);

								pos = node_right (pos);
							}
						}
						inputbuf[0] = 0;
					} else {
						strcpy (inputbuf,
								fixnullstring (node_get (pos, TEXT)));
					}
					break;
				case ui_action_cancel:
					if (node_getflag (pos, F_temp)) {
						pos = node_remove (pos);
					} else {
						/*stop = ui_quit (pos); */
					}
					inputbuf[0] = 0;
					break;
				case ui_action_backspace:
					if (!strlen (inputbuf)) {
						/*pos = ui_remove (pos); */
					} else {
						inputbuf[strlen (inputbuf) - 1] = 0;
						if (node_getflag (pos, F_temp))
							if (node_up (pos))
								pos = node_remove (pos);
					}
					break;
				case ui_action_unbound:
					undefined_key (ui_scope_names[ui_current_scope],
								   binding->key !=
								   1000 ? binding->key : *((int *) &binding->
														   action_param[0]));
				case ui_action_ignore:
					break;
				default:
					if (binding->action > 31 && binding->action < 255) {	/*  input for buffer */
						inputbuf[strlen (inputbuf) + 1] = 0;
						inputbuf[strlen (inputbuf)] = binding->action;
					} else
						undefined_key (ui_scope_names[ui_current_scope],
									   binding->key !=
									   1000 ? binding->
									   key : *((int *) &binding->
											   action_param[0]));
					break;
			}
		} while ((++binding)->key == 999);


		if (strlen (inputbuf)) {
			if (node_getflag (pos, F_temp)) {
				node_set (pos, TEXT, inputbuf);
			} else {
				if (node_match (inputbuf, pos)) {
					pos = node_match (inputbuf, pos);
				} else {
				  if (add_at_top) {
					pos = node_insert_up (node_top (pos));
				  } else {
					pos = node_insert_down (node_bottom (pos));
				  }
					node_setflag (pos, F_temp, 1);
					node_set (pos, TEXT, inputbuf);
					if (node_left (pos))
							if (!strcmp(fixnullstring(node_get(node_left(pos),"type")),"todo")){
								node_set (pos, "type","todo");
								node_set (pos, "done","no");
							}
				}
			}
		} else {
			docmd(pos, "autosave_check_timeout"); 
		}
	}
	return pos;
}