Mercurial > hg > Applications > virsh-wrapper
changeset 39:6e385ccc40bf
Support teacher account
author | atton |
---|---|
date | Sun, 15 Nov 2015 12:18:35 +0900 |
parents | 16840a2375ae |
children | 984f31ae74d5 |
files | ie-virsh.c newvm.py |
diffstat | 2 files changed, 22 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/ie-virsh.c Fri Nov 06 21:51:43 2015 +0900 +++ b/ie-virsh.c Sun Nov 15 12:18:35 2015 +0900 @@ -7,9 +7,8 @@ #include <unistd.h> #include <signal.h> #include <string.h> - -#include <sys/types.h> #include <regex.h> +#include <pwd.h> /* Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License */ @@ -28,10 +27,13 @@ const char *guests[] = {}; const char *managers[] = {"atton"}; -const char students_sym[] = "students"; -const char managers_sym[] = "managers"; -const char guests_sym[] = "guests"; -const char delimiter[] = "_"; +const char *students_identifier = "students"; +const char *teachers_identifier = "teacher"; +const char *students_sym = "students"; +const char *teachers_sym = "teachers"; +const char *managers_sym = "managers"; +const char *guests_sym = "guests"; +const char *delimiter = "_"; static char bad_name[] = "Bad vmname. Try 01 or 02 ... 04\n"; @@ -45,7 +47,8 @@ enum { STUDENTS, GUESTS, - MANAGERS + MANAGERS, + TEACHERS }; #define VMNAME_MAX (512) @@ -142,20 +145,12 @@ int check_user_name(const char *account_name) { - const char *regex = "[ek]([0-9]{6})"; - - regex_t *pattern = NEW(regex_t); - int ret = 1; + const char *home = getpwuid(getuid())->pw_dir; - if (regcomp(pattern, regex, REG_EXTENDED|REG_NEWLINE) != 0) { - exit(0); - } - - ret = regexec(pattern, account_name, (size_t) 0, NULL, 0); - regfree(pattern); - - if (!ret){ - return STUDENTS; + if (strstr(home, students_identifier) != NULL) { + return STUDENTS; + } else if (strstr(home, teachers_identifier) != NULL) { + return TEACHERS; } const int managers_num = sizeof(managers) / sizeof(managers[0]); @@ -214,6 +209,12 @@ strncat(vm_name, account_name, VM_NAME_LENGTH); strncat(vm_name, delimiter, VM_NAME_LENGTH); break; + case TEACHERS: + strncat(vm_name, teachers_sym, VM_NAME_LENGTH); + strncat(vm_name, delimiter, VM_NAME_LENGTH); + strncat(vm_name, account_name, VM_NAME_LENGTH); + strncat(vm_name, delimiter, VM_NAME_LENGTH); + break; case GUESTS: bind_name(vm_name, guests_sym, account_name); break;
--- a/newvm.py Fri Nov 06 21:51:43 2015 +0900 +++ b/newvm.py Sun Nov 15 12:18:35 2015 +0900 @@ -121,5 +121,5 @@ print("VM_NAME:" + vm_name) config.write('/etc/libvirt/qemu/' + vm_name + '.xml') print "Created vm config file %s.xml" % vm_name -print "Use disk image %s, you must create it from the template disk: %s" % (disk_image, disk_old) +print "Use disk image %s" % disk_image print "Done!"