Mercurial > hg > Applications > virsh-wrapper
changeset 27:b731ce75cd35
add change_delimiter function that change '_' to '/'
author | taiki <taiki@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 14 Aug 2014 11:23:34 -1000 |
parents | 76bd473f3b78 |
children | 554085aec682 |
files | ie-virsh.c |
diffstat | 1 files changed, 28 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/ie-virsh.c Wed Aug 13 15:01:32 2014 -1000 +++ b/ie-virsh.c Thu Aug 14 11:23:34 2014 -1000 @@ -91,6 +91,21 @@ return 0; } +void +change_delimiter(char *name) +{ + long size = sizeof(name); + int i = 0; + for (; i < size; i++) { + if (name[i] == '_') { + name [i] = '/'; + } + } + +} + + + int check_name(const char *p) { @@ -207,14 +222,14 @@ setegid(getgid()); seteuid(getuid()); - regex_t *pattern = NEW(regex_t); - if (regcomp(pattern, name, 0) != 0) { - exit(0); + + int account_type = check_user_name(name); + if (account_type < 0) { + fprintf(stderr, "Parmission denied. :%s", name); } - int account_type = check_user_name(name); + char *vm_name = (char *)malloc(sizeof(char) * VM_NAME_LENGTH); - char *vm_name = (char *)malloc(sizeof(char) * VM_NAME_LENGTH); make_vm_name(vm_name, account_type, name, argv[1]); /* Confirm user is in GROUP(999) group */ @@ -235,24 +250,27 @@ if (argc>=3) { if ( strncmp(argv[1], "define", 6) == 0 ) { - if (regexec(pattern, argv[2], (size_t) 0, NULL, 0)) { - fprintf(stderr, bad_name); - exit(0); - } if (check_name(argv[2])) { fprintf(stderr, bad_name); exit(0); } + + change_delimiter(vm_name); char exec[1024]; // strncpy(exec, "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/fedora16.xml -n ",900); strncpy(exec, "/usr/local/bin/newvm.py -c /etc/libvirt/qemu/fedora19.xml -n ",900); - strncat(exec, argv[2],1000); + strncat(exec, vm_name,1000); fprintf(stdout, "excuting %s\n",exec ); system(exec); } } + regex_t *pattern = NEW(regex_t); + if (regcomp(pattern, name, 0) != 0) { + exit(0); + } + VMLISTPTR vmlist = get_vmlist(pattern); char name_xml[1024];