changeset 0:7785dd06c62f

Virsh Wrapper initial version
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 11 Nov 2012 16:26:00 +0900
parents
children 1a8257a34493
files Makefile ie-virsh.c
diffstat 2 files changed, 90 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile	Sun Nov 11 16:26:00 2012 +0900
@@ -0,0 +1,9 @@
+TARGET = ie-virsh
+
+$(TARGET): $(TARGET).c
+	$(CC) $(CFLAGS) $(TARGET).c -o $(TARGET)
+	chmod 2711 $(TARGET)
+	sudo chown root $(TARGET)
+
+clean:
+	rm $(TARGET)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ie-virsh.c	Sun Nov 11 16:26:00 2012 +0900
@@ -0,0 +1,81 @@
+
+#define command "/bin/ls"
+#define arg1 "/Users/kana/Desktop"
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+#include <strings.h>
+
+/********************************************
+ * Wrapper - Secure Yourself                *
+ *                                          *
+ * 2007 - Mike Golvach - eggi@comcast.net   *
+ *                                          *
+ * Usage: COMMAND [start|stop]              *
+ *                                          *
+ ********************************************/
+ 
+ /* Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License */
+
+/* Define global variables */
+
+int gid;
+
+/* main(int argc, char **argv) - main process loop */
+
+int main(int argc, char **argv)
+{
+
+/* Set euid and egid to actual user */
+
+ gid = getgid();
+ setegid(getgid());
+ seteuid(getuid());
+
+/* Confirm user is in GROUP(999) group */
+
+/*
+ if ( gid != 999 ) {
+  printf("User Not Authorized!  Exiting...\n");
+  exit(1);
+ }
+ */
+
+/* Check argc count only at this point */
+
+ if ( argc != 2 ) {
+  printf("Usage: COMMAND [start|stop]\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], "start", 5) == 0 ) {
+  if (execl(command, command, arg1, NULL) < 0) {
+   perror("Execl:");
+  }
+ } else if ( strncmp(argv[1], "stop", 4) == 0 ) {
+  if (execl(command, command, arg1, NULL) < 0) {
+   perror("Execl:");
+  }
+ } else {
+  printf("Usage: COMMAND [start|stop]\n");
+  exit(1);
+ }
+ exit(0);
+}
+