11
|
1
|
|
2
|
|
3 #include <stdlib.h>
|
|
4 #include <unistd.h>
|
|
5
|
|
6 #include <stdio.h>
|
|
7 #include <sys/types.h>
|
|
8 #include <unistd.h>
|
|
9 #include <signal.h>
|
|
10 #include <string.h>
|
|
11
|
|
12 #include <sys/types.h>
|
|
13 #include <regex.h>
|
|
14
|
|
15 /********************************************
|
|
16 * Vagrant Wrapper - Secure Yourself *
|
|
17 * *
|
|
18 * 2007 - Mike Golvach - eggi@comcast.net *
|
|
19 * 2013 - Shinji KONO kono@ie.u-rykyu.ac.jp *
|
|
20 * *
|
|
21 * Usage: COMMAND [init|up|destroy|ssh] *
|
|
22 * *
|
|
23 ********************************************/
|
|
24
|
|
25 /* Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License */
|
|
26
|
|
27 #define command "/usr/bin/vagrant"
|
|
28 #define init_command "init"
|
|
29 #define up_command "up"
|
|
30 #define destroy_command "destroy"
|
|
31 #define ssh_command "ssh"
|
|
32
|
12
|
33 #define NEW(type) ((type*)malloc(sizeof(type)))
|
|
34
|
11
|
35 /* Define global variables */
|
|
36
|
|
37 void
|
|
38 usage()
|
|
39 {
|
|
40 printf("Usage: COMMAND [init|up|destroy|ssh]\n");
|
|
41 }
|
|
42
|
|
43 /* main(int argc, char **argv) - main process loop */
|
|
44
|
|
45 int main(int argc, char **argv)
|
|
46 {
|
|
47 int gid;
|
|
48 int uid;
|
|
49
|
|
50 /* Set euid and egid to actual user */
|
|
51
|
|
52 char *name = getlogin();
|
|
53 uid = getuid();
|
|
54 gid = getgid();
|
|
55 printf("uid %d gid %d name %s\n", uid,gid,name);
|
|
56 setegid(getgid());
|
|
57 seteuid(getuid());
|
|
58
|
|
59 regex_t *pattern = NEW(regex_t);
|
|
60 if (regcomp(pattern, name, 0) != 0) {
|
|
61 exit(0);
|
|
62 }
|
|
63
|
|
64 /* Confirm user is in GROUP(999) group */
|
|
65
|
|
66 /*
|
|
67 if ( gid != 999 ) {
|
|
68 printf("User Not Authorized! Exiting...\n");
|
|
69 exit(1);
|
|
70 }
|
|
71 */
|
|
72
|
|
73 /* Set uid, gid, euid and egid to root */
|
|
74
|
|
75 setegid(0);
|
|
76 seteuid(0);
|
|
77 setgid(0);
|
|
78 setuid(0);
|
|
79
|
|
80 /* Check argv for proper arguments and run
|
|
81 * the corresponding script, if invoked.
|
|
82 */
|
|
83
|
|
84 if ( strncmp(argv[1], "init", 4) == 0 ) {
|
|
85 if (execl(command, command, init_command, NULL) < 0) {
|
|
86 perror("Execl:");
|
|
87 }
|
|
88 } else if ( strncmp(argv[1], "destroy", 4) == 0 ) {
|
12
|
89 if (execl(command, command, destroy_command, NULL) < 0) {
|
11
|
90 perror("Execl:");
|
|
91 }
|
|
92 } else if ( strncmp(argv[1], "up", 2) == 0 ) {
|
|
93 if (execl(command, command, up_command, NULL) < 0) {
|
|
94 perror("Execl:");
|
|
95 }
|
|
96 } else if ( strncmp(argv[1], "ssh", 6) == 0 ) {
|
|
97 if (execl(command, command, ssh_command, NULL) < 0) {
|
|
98 perror("Execl:");
|
|
99 }
|
|
100 } else {
|
|
101 usage();
|
|
102 exit(1);
|
|
103 }
|
|
104 exit(0);
|
|
105 }
|
|
106
|
|
107 /* end */
|