refactor cmd names
This commit is contained in:
parent
e735ad6710
commit
04150a407f
29 changed files with 84 additions and 81 deletions
|
@ -110,7 +110,7 @@ static int short_arg(char c, char* next) {
|
||||||
return ARG_UNUSED;
|
return ARG_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(cat) {
|
COMMAND(cat_main) {
|
||||||
|
|
||||||
int start;
|
int start;
|
||||||
int arg_len;
|
int arg_len;
|
||||||
|
|
|
@ -190,7 +190,7 @@ end:
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(chmod_cmd) {
|
COMMAND(chmod_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ group:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(chown_cmd) {
|
COMMAND(chown_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
|
|
||||||
|
|
|
@ -197,7 +197,7 @@ static void cp_file(char* path) {
|
||||||
pop_path_buffer_2(save2);
|
pop_path_buffer_2(save2);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(cp) {
|
COMMAND(cp_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
|
@ -12,7 +12,7 @@ static void help(void) {
|
||||||
printf("\tcount=N\t\tCopy only N input blocks\n");
|
printf("\tcount=N\t\tCopy only N input blocks\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(dd) {
|
COMMAND(dd_main) {
|
||||||
|
|
||||||
FILE* in_file = stdin;
|
FILE* in_file = stdin;
|
||||||
FILE* out_file = stdout;
|
FILE* out_file = stdout;
|
||||||
|
|
|
@ -74,7 +74,7 @@ static int short_arg(char c, char* next) {
|
||||||
return ARG_UNUSED;
|
return ARG_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(echo) {
|
COMMAND(echo_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
|
|
||||||
|
|
|
@ -903,7 +903,7 @@ static void help(void) {
|
||||||
printf("\t\t=\t\tprint current line number\n");
|
printf("\t\t=\t\tprint current line number\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(ed) {
|
COMMAND(ed_main) {
|
||||||
|
|
||||||
parse_help(argc, argv, help);
|
parse_help(argc, argv, help);
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ static bool run_match(char* path, void* pattern, bool many) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(grep) {
|
COMMAND(grep_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
char* pattern;
|
char* pattern;
|
||||||
|
|
|
@ -13,7 +13,7 @@ static void help (void) {
|
||||||
printf("Print the groups USER is in\n");
|
printf("Print the groups USER is in\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(groups) {
|
COMMAND(groups_main) {
|
||||||
|
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
int ngroups, i;
|
int ngroups, i;
|
||||||
|
|
|
@ -110,7 +110,7 @@ static int short_arg(char c, char* next) {
|
||||||
return ARG_UNUSED;
|
return ARG_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(head) {
|
COMMAND(head_main) {
|
||||||
|
|
||||||
int start, count, i;
|
int start, count, i;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ static void help (void) {
|
||||||
printf("Print information about the USER\n");
|
printf("Print information about the USER\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(user_id) {
|
COMMAND(id_main) {
|
||||||
|
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid, *groups;
|
gid_t gid, *groups;
|
||||||
|
|
|
@ -533,7 +533,7 @@ static int long_arg(char* cur, char* next) {
|
||||||
return ARG_UNUSED;
|
return ARG_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(ls) {
|
COMMAND(ls_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
bool titled;
|
bool titled;
|
||||||
|
|
|
@ -46,7 +46,7 @@ static bool mkdir_parents(char* path) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(makedir) {
|
COMMAND(mkdir_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ static void mv_dir(bool exists) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(mv) {
|
COMMAND(mv_main) {
|
||||||
|
|
||||||
int start, dest, i;
|
int start, dest, i;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
|
@ -97,7 +97,7 @@ static void help(void) {
|
||||||
printf("Format and print ARG(s) according to FORMAT (a-la C prinf)\n");
|
printf("Format and print ARG(s) according to FORMAT (a-la C prinf)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(print) {
|
COMMAND(printf_main) {
|
||||||
|
|
||||||
size_t index;
|
size_t index;
|
||||||
int arg_index;
|
int arg_index;
|
||||||
|
|
|
@ -110,7 +110,7 @@ static void rm_file(char* path) {
|
||||||
pop_path_buffer(save);
|
pop_path_buffer(save);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(rm) {
|
COMMAND(rm_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
|
|
||||||
|
|
12
command/su.c
12
command/su.c
|
@ -14,7 +14,7 @@ static struct {
|
||||||
|
|
||||||
static bool restricted_shell(const char *shell) {
|
static bool restricted_shell(const char *shell) {
|
||||||
char *line;
|
char *line;
|
||||||
int result = true;
|
bool result = true;
|
||||||
|
|
||||||
while ((line = getusershell()) != NULL) {
|
while ((line = getusershell()) != NULL) {
|
||||||
if (strcmp(line, shell) == 0) {
|
if (strcmp(line, shell) == 0) {
|
||||||
|
@ -54,7 +54,7 @@ static int short_arg (char c, char* next) {
|
||||||
return ARG_UNUSED;
|
return ARG_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND (su) {
|
COMMAND (su_main) {
|
||||||
|
|
||||||
int start, res;
|
int start, res;
|
||||||
uid_t cur_uid;
|
uid_t cur_uid;
|
||||||
|
@ -78,15 +78,13 @@ COMMAND (su) {
|
||||||
pw = xgetpwnam(flags.user);
|
pw = xgetpwnam(flags.user);
|
||||||
cur_uid = getuid();
|
cur_uid = getuid();
|
||||||
|
|
||||||
if (cur_uid != 0) {
|
if (cur_uid != 0)
|
||||||
res = prompt_password(pw, "Password: ");
|
res = prompt_password(pw, "Password: ");
|
||||||
} else {
|
else
|
||||||
res = PASSWORD_VALID;
|
res = PASSWORD_VALID;
|
||||||
}
|
|
||||||
|
|
||||||
if (res != PASSWORD_VALID) {
|
if (res != PASSWORD_VALID)
|
||||||
error("invalid password");
|
error("invalid password");
|
||||||
}
|
|
||||||
|
|
||||||
if (flags.shell && cur_uid != 0 && pw->pw_shell && restricted_shell(pw->pw_shell)) {
|
if (flags.shell && cur_uid != 0 && pw->pw_shell && restricted_shell(pw->pw_shell)) {
|
||||||
error_s("using restricted shell");
|
error_s("using restricted shell");
|
||||||
|
|
|
@ -63,7 +63,7 @@ static bool sync_file(char* path) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(sync_cmd) {
|
COMMAND(sync_main) {
|
||||||
|
|
||||||
int start, i, ret = EXIT_SUCCESS;
|
int start, i, ret = EXIT_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ cleanup:
|
||||||
stack_free(&stack);
|
stack_free(&stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(tac) {
|
COMMAND(tac_main) {
|
||||||
|
|
||||||
FILE* in;
|
FILE* in;
|
||||||
int i;
|
int i;
|
||||||
|
|
|
@ -210,7 +210,7 @@ static int short_arg(char c, char* next) {
|
||||||
return ARG_UNUSED;
|
return ARG_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(tail) {
|
COMMAND(tail_main) {
|
||||||
|
|
||||||
int start, count, i;
|
int start, count, i;
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ static int short_arg(char c, char* next) {
|
||||||
return ARG_UNUSED;
|
return ARG_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(tee_cmd) {
|
COMMAND(tee_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
FILE** files;
|
FILE** files;
|
||||||
|
|
|
@ -120,7 +120,7 @@ static int short_arg(char c, char* next) {
|
||||||
return ARG_UNUSED;
|
return ARG_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(wc) {
|
COMMAND(wc_main) {
|
||||||
|
|
||||||
int start, i;
|
int start, i;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ static void help(void) {
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(whoami) {
|
COMMAND(whoami_main) {
|
||||||
|
|
||||||
uid_t usr;
|
uid_t usr;
|
||||||
struct passwd* passwd;
|
struct passwd* passwd;
|
||||||
|
|
|
@ -111,7 +111,7 @@ void read_args(FILE* file, char*** args, int* size, int* capacity) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(xargs) {
|
COMMAND(xargs_main) {
|
||||||
|
|
||||||
int start, arg_start, arg_on_stack_count;
|
int start, arg_start, arg_on_stack_count;
|
||||||
int size, capacity, i;
|
int size, capacity, i;
|
||||||
|
|
|
@ -6,7 +6,7 @@ static void help(void) {
|
||||||
printf("Repeatedly output a line with all specified STRING(s), or 'y'.\n");
|
printf("Repeatedly output a line with all specified STRING(s), or 'y'.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
COMMAND(yes) {
|
COMMAND(yes_main) {
|
||||||
const char* repeat;
|
const char* repeat;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
-Isrc
|
-Isrc
|
||||||
-Icommand
|
-Icommand
|
||||||
-Ilib
|
-Ilib
|
||||||
|
-Ihash
|
||||||
-D_DEFAULT_SOURCE
|
-D_DEFAULT_SOURCE
|
||||||
-DMAJOR=0
|
-DMAJOR=0
|
||||||
-DMINOR=0
|
-DMINOR=0
|
||||||
|
|
|
@ -132,6 +132,10 @@ void xsetuid(uid_t uid);
|
||||||
void xsetgid(gid_t gid);
|
void xsetgid(gid_t gid);
|
||||||
struct passwd* xgetpwnam(char* name);
|
struct passwd* xgetpwnam(char* name);
|
||||||
|
|
||||||
|
|
||||||
|
char* crypt(const char* plaintext, const char* pw_pass);
|
||||||
|
|
||||||
|
|
||||||
#define PASSWORD_INVALID 0
|
#define PASSWORD_INVALID 0
|
||||||
#define PASSWORD_VALID 1
|
#define PASSWORD_VALID 1
|
||||||
#define PASSWORD_EMPTY 2
|
#define PASSWORD_EMPTY 2
|
||||||
|
|
|
@ -5,30 +5,30 @@
|
||||||
#define NEXT_ARGS argc - 1, &argv[1]
|
#define NEXT_ARGS argc - 1, &argv[1]
|
||||||
#define COMMAND(name) int name (ARGUMENTS)
|
#define COMMAND(name) int name (ARGUMENTS)
|
||||||
|
|
||||||
COMMAND(dd);
|
COMMAND(dd_main);
|
||||||
COMMAND(cat);
|
COMMAND(cat_main);
|
||||||
COMMAND(yes);
|
COMMAND(yes_main);
|
||||||
COMMAND(echo);
|
COMMAND(echo_main);
|
||||||
COMMAND(print);
|
COMMAND(printf_main);
|
||||||
COMMAND(groups);
|
COMMAND(groups_main);
|
||||||
COMMAND(user_id);
|
COMMAND(id_main);
|
||||||
COMMAND(ls);
|
COMMAND(ls_main);
|
||||||
COMMAND(tail);
|
COMMAND(tail_main);
|
||||||
COMMAND(head);
|
COMMAND(head_main);
|
||||||
COMMAND(ed);
|
COMMAND(ed_main);
|
||||||
COMMAND(tee_cmd);
|
COMMAND(tee_main);
|
||||||
COMMAND(whoami);
|
COMMAND(whoami_main);
|
||||||
COMMAND(wc);
|
COMMAND(wc_main);
|
||||||
COMMAND(xargs);
|
COMMAND(xargs_main);
|
||||||
COMMAND(tac);
|
COMMAND(tac_main);
|
||||||
COMMAND(rm);
|
COMMAND(rm_main);
|
||||||
COMMAND(cp);
|
COMMAND(cp_main);
|
||||||
COMMAND(makedir);
|
COMMAND(mkdir_main);
|
||||||
COMMAND(mv);
|
COMMAND(mv_main);
|
||||||
COMMAND(grep);
|
COMMAND(grep_main);
|
||||||
COMMAND(chown_cmd);
|
COMMAND(chown_main);
|
||||||
COMMAND(chmod_cmd);
|
COMMAND(chmod_main);
|
||||||
COMMAND(sync_cmd);
|
COMMAND(sync_main);
|
||||||
COMMAND(su);
|
COMMAND(su_main);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
50
src/main.c
50
src/main.c
|
@ -37,61 +37,61 @@ int main (ARGUMENTS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (streql(cmd, "dd")) {
|
if (streql(cmd, "dd")) {
|
||||||
return dd(NEXT_ARGS);
|
return dd_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "cat")) {
|
} else if (streql(cmd, "cat")) {
|
||||||
return cat(NEXT_ARGS);
|
return cat_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "yes")) {
|
} else if (streql(cmd, "yes")) {
|
||||||
return yes(NEXT_ARGS);
|
return yes_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "echo")) {
|
} else if (streql(cmd, "echo")) {
|
||||||
return echo(NEXT_ARGS);
|
return echo_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "printf")) {
|
} else if (streql(cmd, "printf")) {
|
||||||
return print(NEXT_ARGS);
|
return printf_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "groups")) {
|
} else if (streql(cmd, "groups")) {
|
||||||
return groups(NEXT_ARGS);
|
return groups_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "id")) {
|
} else if (streql(cmd, "id")) {
|
||||||
return user_id(NEXT_ARGS);
|
return id_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "ls") || streql(cmd, "dir")) {
|
} else if (streql(cmd, "ls") || streql(cmd, "dir")) {
|
||||||
return ls(NEXT_ARGS);
|
return ls_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "lsd")) {
|
} else if (streql(cmd, "lsd")) {
|
||||||
printf("look at all the funny colors\n");
|
printf("look at all the funny colors\n");
|
||||||
} else if (streql(cmd, "tail")) {
|
} else if (streql(cmd, "tail")) {
|
||||||
return tail(NEXT_ARGS);
|
return tail_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "head")) {
|
} else if (streql(cmd, "head")) {
|
||||||
return head(NEXT_ARGS);
|
return head_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "ed")) {
|
} else if (streql(cmd, "ed")) {
|
||||||
return ed(NEXT_ARGS);
|
return ed_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "tee")) {
|
} else if (streql(cmd, "tee")) {
|
||||||
return tee_cmd(NEXT_ARGS);
|
return tee_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "true")) {
|
} else if (streql(cmd, "true")) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} else if (streql(cmd, "false")) {
|
} else if (streql(cmd, "false")) {
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} else if (streql(cmd, "whoami")) {
|
} else if (streql(cmd, "whoami")) {
|
||||||
return whoami(NEXT_ARGS);
|
return whoami_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "wc")) {
|
} else if (streql(cmd, "wc")) {
|
||||||
return wc(NEXT_ARGS);
|
return wc_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "xargs")) {
|
} else if (streql(cmd, "xargs")) {
|
||||||
return xargs(NEXT_ARGS);
|
return xargs_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "tac")) {
|
} else if (streql(cmd, "tac")) {
|
||||||
return tac(NEXT_ARGS);
|
return tac_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "rm")) {
|
} else if (streql(cmd, "rm")) {
|
||||||
return rm(NEXT_ARGS);
|
return rm_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "cp")) {
|
} else if (streql(cmd, "cp")) {
|
||||||
return cp(NEXT_ARGS);
|
return cp_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "mkdir")) {
|
} else if (streql(cmd, "mkdir")) {
|
||||||
return makedir(NEXT_ARGS);
|
return mkdir_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "mv")) {
|
} else if (streql(cmd, "mv")) {
|
||||||
return mv(NEXT_ARGS);
|
return mv_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "grep")) {
|
} else if (streql(cmd, "grep")) {
|
||||||
return grep(NEXT_ARGS);
|
return grep_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "chown")) {
|
} else if (streql(cmd, "chown")) {
|
||||||
return chown_cmd(NEXT_ARGS);
|
return chown_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "chmod")) {
|
} else if (streql(cmd, "chmod")) {
|
||||||
return chmod_cmd(NEXT_ARGS);
|
return chmod_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "sync")) {
|
} else if (streql(cmd, "sync")) {
|
||||||
return sync_cmd(NEXT_ARGS);
|
return sync_main(NEXT_ARGS);
|
||||||
} else if (streql(cmd, "su")) {
|
} else if (streql(cmd, "su")) {
|
||||||
return su(NEXT_ARGS);
|
return su_main(NEXT_ARGS);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "lazysphere: invalid command %s\n", cmd);
|
fprintf(stderr, "lazysphere: invalid command %s\n", cmd);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
Loading…
Reference in a new issue