static bool os_parse_runas_uid_gid(const char *optarg) { unsigned long lv; const char *ep; uid_t got_uid; gid_t got_gid; int rc; rc = qemu_strtoul(optarg, &ep, 0, &lv); got_uid = lv; /* overflow here is ID in C99 */ if (rc || *ep != ':' || got_uid != lv || got_uid == (uid_t)-1) { return false; } rc = qemu_strtoul(ep + 1, 0, 0, &lv); got_gid = lv; /* overflow here is ID in C99 */ if (rc || got_gid != lv || got_gid == (gid_t)-1) { return false; } user_pwd = NULL; user_uid = got_uid; user_gid = got_gid; return true; }
/* Scan for remote-port links to be setup. */ void rp_device_add(QemuOpts *opts, DeviceState *dev, Error **errp) { Error *err = NULL; Object *adaptor; bool ambiguous; const char *path; char *name; int i; /* * Find the adaptor this remote-port device is connected to. * At the moment, we only support one adaptor per device. */ name = g_strdup_printf("rp-adaptor%d", 0); path = qemu_opt_get(opts, name); g_free(name); if (!path) { /* This is not a remote-port device. */ return; } adaptor = object_resolve_path(path, &ambiguous); if (!adaptor) { error_setg(errp, "Did not find rp adaptor %s!\n", path); return; } /* * Loop through the channels this device provides and attach * them to the adaptor. */ for (i = 0; i < INT_MAX; i++) { unsigned long dev_nr; const char *dev_nr_str; name = g_strdup_printf("rp-chan%d", i); dev_nr_str = qemu_opt_get(opts, name); g_free(name); if (!dev_nr_str) { if (i == 0) { /* At least one channel must be provided. */ error_setg(errp, "Did not find rp-chan%d!\n", i); } return; } if (qemu_strtoul(dev_nr_str, NULL, 0, &dev_nr)) { error_setg(errp, "Invalid rp-chan%d!\n", i); return; } /* Now, attach the device to the adaptor. */ rp_device_attach(adaptor, OBJECT(dev), 0, dev_nr, &err); if (err != NULL) { error_propagate(errp, err); return; } } }
static void s390_ipl_set_boot_menu(S390IPLState *ipl) { QemuOptsList *plist = qemu_find_opts("boot-opts"); QemuOpts *opts = QTAILQ_FIRST(&plist->head); uint8_t *flags = &ipl->qipl.qipl_flags; uint32_t *timeout = &ipl->qipl.boot_menu_timeout; const char *tmp; unsigned long splash_time = 0; if (!get_boot_device(0)) { if (boot_menu) { error_report("boot menu requires a bootindex to be specified for " "the IPL device"); } return; } switch (ipl->iplb.pbt) { case S390_IPL_TYPE_CCW: /* In the absence of -boot menu, use zipl parameters */ if (!qemu_opt_get(opts, "menu")) { *flags |= QIPL_FLAG_BM_OPTS_ZIPL; return; } break; case S390_IPL_TYPE_QEMU_SCSI: break; default: if (boot_menu) { error_report("boot menu is not supported for this device type"); } return; } if (!boot_menu) { return; } *flags |= QIPL_FLAG_BM_OPTS_CMD; tmp = qemu_opt_get(opts, "splash-time"); if (tmp && qemu_strtoul(tmp, NULL, 10, &splash_time)) { error_report("splash-time is invalid, forcing it to 0"); *timeout = 0; return; } if (splash_time > 0xffffffff) { error_report("splash-time is too large, forcing it to max value"); *timeout = 0xffffffff; return; } *timeout = cpu_to_be32(splash_time); }
/* * Convert @key to a list index. * Convert all leading decimal digits to a (non-negative) number, * capped at INT_MAX. * If @end is non-null, assign a pointer to the first character after * the number to *@end. * Else, fail if any characters follow. * On success, return the converted number. * On failure, return a negative value. * Note: since only digits are converted, no two keys can map to the * same number, except by overflow to INT_MAX. */ static int key_to_index(const char *key, const char **end) { int ret; unsigned long index; if (*key < '0' || *key > '9') { return -EINVAL; } ret = qemu_strtoul(key, end, 10, &index); if (ret) { return ret == -ERANGE ? INT_MAX : ret; } return index <= INT_MAX ? index : INT_MAX; }