--- vzctl-3.0.22/src/lib/create.c 2008-10-28 12:41:06.000000000 +0100 +++ nvzctl-3.0.22/src/lib/create.c 2008-11-06 13:59:42.000000000 +0100 @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include "list.h" #include "logger.h" @@ -253,7 +255,9 @@ logger(-1, 0, "Creation of container private area failed"); return ret; } - vps_postcreate(veid, &vps_p->res.fs, &vps_p->res.tmpl); + + vps_postcreate(veid, &vps_p->res.fs, &vps_p->res.tmpl, + cmd_p->res.misc.rootpw); move_config(veid, DESTR); /* store root, private, ostemplate in case default used */ if (cmd_p->res.fs.root_orig == NULL && @@ -278,13 +282,42 @@ return 0; } -int vps_postcreate(envid_t veid, fs_param *fs, tmpl_param *tmpl) +static char *long2str(unsigned long value, char *buf) +{ + int i; + + for (i = 0; i < 7; i++) { + int j = value % 64; + + if (j < 1) + buf[i] = '.'; + else if (j == 1) + buf[i] = '/'; + else if (j < 12) + buf[i] = '0' - 2 + j; + else if (j < 38) + buf[i] = 'A' - 12 + j; + else if (j < 63) + buf[i] = 'a' - 38 + j; + else + buf[i] = 'z'; + + buf[i+1] = '\0'; + + if (!(value /= 64)) + break; + } + + return buf + i + 1; +} + +int vps_postcreate(envid_t veid, fs_param *fs, tmpl_param *tmpl, char *rootpw) { char buf[STR_SIZE]; dist_actions actions; char *dist_name; char *arg[2]; - char *env[3]; + char *env[5]; int ret; if (check_var(fs->root, "VE_ROOT is not set")) @@ -307,7 +340,30 @@ snprintf(buf, sizeof(buf), "VE_ROOT=%s", fs->root); env[0] = buf; env[1] = ENV_PATH; - env[2] = NULL; + + if (rootpw == NULL) { + env[2] = NULL; + } else { + char ebuf1[STR_SIZE]; + char ebuf2[STR_SIZE]; + char salt[20]; + char *tmpsalt; + char *cpassword = NULL; + struct timeval tv; + + salt[0] = salt[2] = '$'; salt[1] = '1'; + gettimeofday(&tv, (struct timezone *)0); + tmpsalt = long2str(tv.tv_usec, &salt[3]); + long2str(tv.tv_sec + getpid(), tmpsalt); + cpassword = strdup(crypt(rootpw, salt)); + + snprintf(ebuf1, sizeof(ebuf1), "VE_ROOTPASSWD=%s", rootpw); + env[2] = ebuf1; + snprintf(ebuf2, sizeof(ebuf2), "VE_CROOTPASSWD=%s", cpassword); + env[3] = ebuf2; + env[4] = NULL; + } + logger(0, 0, "Performing postcreate actions"); ret = run_script(actions.post_create, arg, env, 0); fsumount(veid, fs->root); --- vzctl-3.0.22/src/lib/config.c 2008-11-06 14:14:45.000000000 +0100 +++ nvzctl-3.0.22/src/lib/config.c 2008-11-06 12:13:44.000000000 +0100 @@ -195,6 +195,7 @@ {"cpus", required_argument, NULL, PARAM_VCPUS}, /* misc param */ {"initlog", required_argument, NULL, PARAM_INITLOG}, +{"rootpasswd", required_argument, NULL, PARAM_ROOTPW}, /* create param */ {"onboot", required_argument, NULL, PARAM_ONBOOT}, {"setmode", required_argument, NULL, PARAM_SETMODE}, @@ -1891,6 +1892,9 @@ case PARAM_USERPW: ret = conf_parse_strlist(&vps_p->res.misc.userpw, val, 1); break; + case PARAM_ROOTPW: + ret = conf_parse_str(&vps_p->res.misc.rootpw, val, 1); + break; case PARAM_APPLYCONFIG_MAP: if (!strcmp(val, "name")) vps_p->opt.apply_cfg_map = APPCONF_MAP_NAME; --- vzctl-3.0.22/src/Makefile.am 2008-10-28 12:41:06.000000000 +0100 +++ nvzctl-3.0.22/src/Makefile.am 2008-11-06 13:37:46.000000000 +0100 @@ -34,7 +34,7 @@ vzmemcheck \ vzsplit -VZCTL_LIBS = $(top_builddir)/src/lib/libvzctl.la +VZCTL_LIBS = $(top_builddir)/src/lib/libvzctl.la -lcrypt arpsend_SOURCES = arpsend.c --- vzctl-3.0.22/src/vzctl-actions.c 2008-10-28 12:41:06.000000000 +0100 +++ nvzctl-3.0.22/src/vzctl-actions.c 2008-11-06 11:59:03.000000000 +0100 @@ -200,6 +200,7 @@ {"config", required_argument, NULL, PARAM_CONFIG}, {"private", required_argument, NULL, PARAM_PRIVATE}, {"root", required_argument, NULL, PARAM_ROOT}, + {"rootpasswd", required_argument, NULL, PARAM_ROOTPW}, {"ipadd", required_argument, NULL, PARAM_IP_ADD}, {"hostname", required_argument, NULL, PARAM_HOSTNAME}, {"name", required_argument, NULL, PARAM_NAME}, --- vzctl-3.0.22/include/create.h 2008-10-28 12:41:06.000000000 +0100 +++ nvzctl-3.0.22/include/create.h 2008-11-06 12:42:27.000000000 +0100 @@ -23,7 +23,7 @@ struct mod_action; -int vps_postcreate(envid_t veid, fs_param *fs, tmpl_param *tmpl); +int vps_postcreate(envid_t veid, fs_param *fs, tmpl_param *tmpl, char *rootpw); int vps_create(vps_handler *h, envid_t veid, vps_param *vps_p, vps_param *cmd_p, struct mod_action *action); int vps_destroy(vps_handler *h, envid_t veid, fs_param *fs); --- vzctl-3.0.22/include/vzctl_param.h 2008-11-06 14:14:45.000000000 +0100 +++ nvzctl-3.0.22/include/vzctl_param.h 2008-11-06 11:41:08.000000000 +0100 @@ -134,7 +134,8 @@ #define PARAM_NETIF_MAC_FILTER 360 #define PARAM_NETIF_BRIDGE 361 #define PARAM_DESCRIPTION 362 -#define PARAM_INITLOG 363 +#define PARAM_ROOTPW 363 +#define PARAM_INITLOG 364 #define PARAM_LINE "e:p:f:t:i:l:k:a:b:n:x:h" #endif --- vzctl-3.0.22/include/res.h 2008-11-06 14:14:45.000000000 +0100 +++ nvzctl-3.0.22/include/res.h 2008-11-06 11:57:44.000000000 +0100 @@ -50,6 +50,7 @@ list_head_t userpw; list_head_t nameserver; list_head_t searchdomain; + char *rootpw; char *hostname; char *description; int wait;