int main(int argc, char **argv) { int errline = 0, i; CMD_FILE cf; // check if cmd file was given if (argc < 2) { printf("USAGE: su_exec cmdfile\n"); return 0; } if ((errline = open_and_parse_cmd_file(argv[1], &cf)) != 0) { if (errline == ERR_NOFILE) { printf("could not find command file %s \n", argv[1]); return ERR_NOFILE; } if (errline == ERR_NOKEY) { printf("authentication keys do not match! will not process file \n"); return ERR_NOKEY; } printf("error on line %i of command file: %s\n", errline, g_err_line); free(g_err_line); free_cmds(&cf); return 0; } if (!check_keys(&cf)) { printf("keys do not match!\n"); free_cmds(&cf); return 0; } // set the uid to root, so that shell commands think they are really run from the root account setuid(geteuid()); for (i = 0; i < cf.num_cmds; i++) { printf("exec command %s <br>\n", cf.cmds[i].real_cmd); system(cf.cmds[i].real_cmd); } free_cmds(&cf); return 0; }
int main(int argc, char **argv) { char *line; struct commands cmds; int quit = 0; while (!quit) { line = readline("myshell> "); if (!line) return (0); add_history(line); (void) parse_line(line, &cmds); if (exec_cmds(&cmds)) { fprintf(stderr, "Line execution failed.\n"); } free_cmds(&cmds); free(line); } return (0); }