Mercurial > hg > Applications > docker-wrapper
changeset 18:8efb8b39ae0c
Fix SEGV without arguments
author | atton |
---|---|
date | Tue, 24 Nov 2015 16:59:54 +0900 |
parents | cefc6c47d109 |
children | fe7095c365cf |
files | Makefile ie-docker.c |
diffstat | 2 files changed, 21 insertions(+), 76 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Tue Nov 24 16:48:43 2015 +0900 +++ b/Makefile Tue Nov 24 16:59:54 2015 +0900 @@ -2,7 +2,7 @@ IEDOCKERDIR = /etc/iecloud/ PORTRANGE1 = "10000" PORTRANGE2 = "12000" -CFLAGS = -Wall -O2 -g +CFLAGS = -Wall -O0 -g INSTALL_DIR = /usr/local/bin @@ -13,7 +13,7 @@ sudo chown root $(TARGET) sudo chmod 4711 $(TARGET) -install: $(TARGET) +install: $(TARGET) install $(TARGET) $(INSTALL_DIR) install create.py $(INSTALL_DIR) install portops.py $(INSTALL_DIR) @@ -25,7 +25,7 @@ -mkdir $(IEDOCKERDIR) python numberfile.py $(PORTRANGE1) $(PORTRANGE2) -cp iecloudport.list $(IEDOCKERDIR) - + clean: rm -f $(TARGET) $(TARGET2) *.o
--- a/ie-docker.c Tue Nov 24 16:48:43 2015 +0900 +++ b/ie-docker.c Tue Nov 24 16:59:54 2015 +0900 @@ -15,7 +15,7 @@ void get_port_number(const char *user_name, char const *project_name, char *port_number) -{ +{ FILE *fp = NULL; if ((fp = fopen(portlist_file, "r")) == NULL) { printf("[!] file open error\n"); @@ -33,11 +33,11 @@ char *ret = strtok(NULL, ","); if (ret == NULL) continue; - user_name_flag = strncmp(user_name, ret, BUFF_SIZE); + user_name_flag = strncmp(user_name, ret, BUFF_SIZE); ret = strtok(NULL, ","); if (ret == NULL) continue; - project_name_flag = strncmp(project_name, ret, BUFF_SIZE); + project_name_flag = strncmp(project_name, ret, BUFF_SIZE); printf("project :%s\n", project_name); if (user_name_flag == 0 && project_name_flag == 0) { @@ -113,7 +113,7 @@ opt->outerport, opt->tty, opt->dettach, - opt->interactive, + opt->interactive, opt->ps_name, opt->exec_ps_command, opt->volume, @@ -140,8 +140,8 @@ return list; } -void -print_pslist(PSLISTPTR list) +void +print_pslist(PSLISTPTR list) { for(;list && list->name[0]; list = list->next) { fprintf(stdout, " %s\n",list->name); @@ -175,49 +175,6 @@ return 0; } -int -check_user_name(const char *account_name) -{ - const char *regex = "[ek]([0-9]{6})"; - - regex_t *pattern = NEW(regex_t); - int ret = 1; - - 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; - } - - ret = regexec(pattern, account_name, (size_t) 0, NULL, 0); - regfree(pattern); - - const int managers_num = sizeof(managers) / sizeof(managers[0]); - int i = 0; - - for (; i< managers_num; i++) { - if (strncmp(account_name, managers[i], NAME_LENGTH) == 0) { - return MANAGERS; - } - } - - const int guests_num = sizeof(guests) / sizeof(guests[0]); - int j = 0; - - for (; j< guests_num; j++) { - if (strncmp(account_name, guests[j], NAME_LENGTH) == 0) { - return GUESTS; - } - } - - return -1; -} - void bind_name(char *name, const char *first, const char *second) { @@ -254,7 +211,7 @@ strncat(ps_name, vm_num, PS_NAME_LENGTH); } -void +void usage() { printf("Usage: ie-docker\n"); @@ -290,17 +247,6 @@ setegid(getgid()); seteuid(getuid()); - FILE *fp = NULL; - if ((fp = fopen("output", "w")) == NULL) { - fputs("test\n", fp); - } - fclose(fp); - - int account_type = check_user_name(name); - if (account_type < 0) { - fprintf(stderr, "[!] Permission denied. :%s\n", name); - } - /* Confirm user is in GROUP(999) group */ /* @@ -322,12 +268,6 @@ setgid(0); setuid(0); - if (strncmp(argv[1], create_command, 6) == 0) { - char exec[512]; - sprintf(exec, "/usr/local/bin/create.py %s", argv[2]); - system(exec); - exit(1); - } char *ps_name = (char *)malloc(sizeof(char) * PS_NAME_LENGTH); if (ps_name == NULL) { @@ -349,6 +289,11 @@ exec_opt->dettach = FALSE; exec_opt->interactive = FALSE; + if (argc < 2) { + usage(); + exit(0); + } + if (strncmp(argv[1], "ps", 4) != 0) { if (strncmp(argv[1], run_command, 3) == 0) { parse_run_command(argc, argv, run_opt); @@ -359,21 +304,21 @@ get_port_number(name, run_opt->ps_name, run_opt->outerport); strncpy(ps_name, run_opt->ps_name, 64); run_opt->ps_name[0] = '\0'; - make_ps_name(run_opt->ps_name, account_type, name, ps_name); + //make_ps_name(run_opt->ps_name, account_type, name, ps_name); } else if (strncmp(argv[1], exec_command, 4) == 0){ parse_exec_command(argc, argv, exec_opt); strncpy(ps_name, exec_opt->ps_name, 64); - make_ps_name(exec_opt->ps_name, account_type, name, ps_name); + //make_ps_name(exec_opt->ps_name, account_type, name, ps_name); } else if (strncmp(argv[1], rm_command, 4) == 0) { char exec[512]; sprintf(exec, "/usr/local/bin/remove.py %s", argv[2]); system(exec); - make_ps_name(ps_name, account_type, name, argv[2]); + //make_ps_name(ps_name, account_type, name, argv[2]); free(run_opt); free(exec_opt); } else { - make_ps_name(ps_name, account_type, name, argv[2]); + //make_ps_name(ps_name, account_type, name, argv[2]); free(run_opt); free(exec_opt); } @@ -382,7 +327,7 @@ PSLISTPTR pslist = get_pslist(pattern); /* - * Check argv for proper arguments and run + * Check argv for proper arguments and run * the corresponding script, if invoked. */ @@ -419,7 +364,7 @@ opt->outerport, opt->tty, opt->dettach, - opt->interactive, + opt->interactive, opt->ps_name, opt->exec_ps_command, opt->volume,