This commit is contained in:
Your Name 2024-09-30 16:11:43 +03:00
parent 04ff3cf8e7
commit 0306c4319b
3 changed files with 32 additions and 15 deletions

View File

@ -2,6 +2,7 @@
cat > mutils.c << EOF
#include <stdio.h>
#include <string.h>
#include <libgen.h>
$(for i in $(ls src); do
f=$(basename $i .c)
@ -24,21 +25,29 @@ struct cmd {
};
int main(int argc, char **argv) {
if (argc > 1) {
argc--;
argv++;
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
if (!strcmp(argv[0], cmds[i].str))
return cmds[i].func(argc, argv);
}
char *prog = basename(argv[0]);
if (argc == 1 && !strcmp(prog, "mutils")) {
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
printf("%s ", cmds[i].str);
putchar('\n');
return 0;
}
else if (!strcmp(prog, "mutils")) {
argv++;
argc--;
prog = argv[0];
}
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
if (!strcmp(prog, cmds[i].str))
return cmds[i].func(argc, argv);
fprintf(stderr, "mutils: unknown applet %s\n", prog);
}
EOF
echo $CFLAGS | xargs $CC -Iconfigs -Ilibmu mutils.c obj/*.o bin/*.c -o mutils

View File

@ -3,23 +3,30 @@
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <libgen.h>
#define _MUSUID_C
#include "config.h"
const char *progs[] = {"su", "ping"};
int main(int argc, char **argv) {
if (argc == 1) {
char *prog = basename(argv[0]);
if (argc == 1 && !strcmp(prog, "musuid")) {
fputs("musuid: missing operand\n", stderr);
return 1;
}
argc--;
else if (!strcmp(prog, "musuid")) {
argv++;
argc--;
prog = argv[0];
}
/* RUN */
for (size_t i = 0; i < sizeof(progs) / sizeof(char *); i++)
if (!strcmp(argv[0], progs[i]))
if (!strcmp(prog, progs[i]))
execv(MUTILS_PATH, argv);
fprintf(stderr, "musuid: unknown command: %s\n", argv[0]);

View File

@ -60,23 +60,24 @@ static int password(const struct passwd *pw) {
fflush(stdout);
if (hide_input(STDIN_FILENO, 1)) {
fprintf(stderr, "su: %s\n", strerror(errno));
fprintf(stderr, "\nsu: %s\n", strerror(errno));
return 1;
}
off_t ret = 0;
if ((ret = read(STDIN_FILENO, psswd, sizeof(psswd))) <= 0) {
fprintf(stderr, "su: %s\n", strerror(errno));
fprintf(stderr, "\nsu: %s\n", strerror(errno));
return 1;
}
putchar('\n');
psswd[ret - 1] = '\0';
if (pw_check("su", pw, psswd)) {
memset(psswd, '\0', sizeof(psswd));
return 1;
}
printf("\n");
memset(psswd, '\0', sizeof(psswd));
return 0;
}