# HG changeset patch # User taiki # Date 1384198416 36000 # Node ID 422041acef4c3b7b13efc0fc33673aca9254654e # Parent 0740e88a783b90920a90cc42466c2fbd751bef89 add ie-vagrant diff -r 0740e88a783b -r 422041acef4c Makefile --- a/Makefile Tue Nov 13 22:12:08 2012 +0900 +++ b/Makefile Mon Nov 11 09:33:36 2013 -1000 @@ -1,16 +1,27 @@ TARGET = ie-virsh CFLAGS = -Wall -O2 -g +TARGET2 = ie-vagrant + + +all: $(TARGET) $(TARGET2) $(TARGET): $(TARGET).c $(CC) $(CFLAGS) $(TARGET).c -o $(TARGET) sudo chown root $(TARGET) sudo chmod 4711 $(TARGET) -install: $(TARGET) newvm.py +$(TARGET2): $(TARGET2).c + $(CC) $(CFLAGS) $(TARGET2).c -o $(TARGET2) + sudo chown root $(TARGET2) + sudo chmod 4711 $(TARGET2) + +install: $(TARGET) $(TARGET2) newvm.py install ie-virsh /usr/local/bin/ + install ie-vagrant /usr/local/bin/ install newvm.py /usr/local/bin/ chmod 4711 /usr/local/bin/ie-virsh + chmod 4711 /usr/local/bin/ie-vagrant chmod 755 /usr/local/bin/newvm.py clean: - rm $(TARGET) + rm -f $(TARGET) $(TARGET2) *.o diff -r 0740e88a783b -r 422041acef4c ie-vagrant.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ie-vagrant.c Mon Nov 11 09:33:36 2013 -1000 @@ -0,0 +1,105 @@ + + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +/******************************************** + * Vagrant Wrapper - Secure Yourself * + * * + * 2007 - Mike Golvach - eggi@comcast.net * + * 2013 - Shinji KONO kono@ie.u-rykyu.ac.jp * + * * + * Usage: COMMAND [init|up|destroy|ssh] * + * * + ********************************************/ + + /* Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License */ + +#define command "/usr/bin/vagrant" +#define init_command "init" +#define up_command "up" +#define destroy_command "destroy" +#define ssh_command "ssh" + +/* Define global variables */ + +void +usage() +{ + printf("Usage: COMMAND [init|up|destroy|ssh]\n"); +} + +/* main(int argc, char **argv) - main process loop */ + +int main(int argc, char **argv) +{ + int gid; + int uid; + +/* Set euid and egid to actual user */ + + char *name = getlogin(); + uid = getuid(); + gid = getgid(); + printf("uid %d gid %d name %s\n", uid,gid,name); + setegid(getgid()); + seteuid(getuid()); + + regex_t *pattern = NEW(regex_t); + if (regcomp(pattern, name, 0) != 0) { + exit(0); + } + +/* Confirm user is in GROUP(999) group */ + +/* + if ( gid != 999 ) { + printf("User Not Authorized! Exiting...\n"); + exit(1); + } + */ + +/* Set uid, gid, euid and egid to root */ + + setegid(0); + seteuid(0); + setgid(0); + setuid(0); + +/* Check argv for proper arguments and run + * the corresponding script, if invoked. + */ + + if ( strncmp(argv[1], "init", 4) == 0 ) { + if (execl(command, command, init_command, NULL) < 0) { + perror("Execl:"); + } + } else if ( strncmp(argv[1], "destroy", 4) == 0 ) { + if (execl(command, command, stop_command, NULL) < 0) { + perror("Execl:"); + } + } else if ( strncmp(argv[1], "up", 2) == 0 ) { + if (execl(command, command, up_command, NULL) < 0) { + perror("Execl:"); + } + } else if ( strncmp(argv[1], "ssh", 6) == 0 ) { + if (execl(command, command, ssh_command, NULL) < 0) { + perror("Execl:"); + } + } else { + usage(); + exit(1); + } + exit(0); +} + +/* end */ diff -r 0740e88a783b -r 422041acef4c ie-virsh.c --- a/ie-virsh.c Tue Nov 13 22:12:08 2012 +0900 +++ b/ie-virsh.c Mon Nov 11 09:33:36 2013 -1000 @@ -32,6 +32,8 @@ #define undefine_command "undefine" #define dumpxml_command "dumpxml" +#define vagrant_start_cmd "vagrant start" + static char bad_name[] = "Bad vmname. Try students/e11/e115711/01 or teachers/kono/02\n"; #define VMNAME_MAX (512)