fixed
This commit is contained in:
parent
04ff3cf8e7
commit
0306c4319b
@ -2,6 +2,7 @@
|
|||||||
cat > mutils.c << EOF
|
cat > mutils.c << EOF
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
|
||||||
$(for i in $(ls src); do
|
$(for i in $(ls src); do
|
||||||
f=$(basename $i .c)
|
f=$(basename $i .c)
|
||||||
@ -24,21 +25,29 @@ struct cmd {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc > 1) {
|
char *prog = basename(argv[0]);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (argc == 1 && !strcmp(prog, "mutils")) {
|
||||||
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
|
for (size_t i = 0; i < sizeof(cmds) / sizeof(struct cmd); i++)
|
||||||
printf("%s ", cmds[i].str);
|
printf("%s ", cmds[i].str);
|
||||||
|
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
return 0;
|
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
|
EOF
|
||||||
|
|
||||||
echo $CFLAGS | xargs $CC -Iconfigs -Ilibmu mutils.c obj/*.o bin/*.c -o mutils
|
echo $CFLAGS | xargs $CC -Iconfigs -Ilibmu mutils.c obj/*.o bin/*.c -o mutils
|
||||||
|
@ -3,23 +3,30 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <libgen.h>
|
||||||
#define _MUSUID_C
|
#define _MUSUID_C
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
const char *progs[] = {"su", "ping"};
|
const char *progs[] = {"su", "ping"};
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
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);
|
fputs("musuid: missing operand\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
argc--;
|
else if (!strcmp(prog, "musuid")) {
|
||||||
argv++;
|
argv++;
|
||||||
|
argc--;
|
||||||
|
|
||||||
|
prog = argv[0];
|
||||||
|
}
|
||||||
|
|
||||||
/* RUN */
|
/* RUN */
|
||||||
for (size_t i = 0; i < sizeof(progs) / sizeof(char *); i++)
|
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);
|
execv(MUTILS_PATH, argv);
|
||||||
|
|
||||||
fprintf(stderr, "musuid: unknown command: %s\n", argv[0]);
|
fprintf(stderr, "musuid: unknown command: %s\n", argv[0]);
|
||||||
|
7
src/su.c
7
src/su.c
@ -60,23 +60,24 @@ static int password(const struct passwd *pw) {
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (hide_input(STDIN_FILENO, 1)) {
|
if (hide_input(STDIN_FILENO, 1)) {
|
||||||
fprintf(stderr, "su: %s\n", strerror(errno));
|
fprintf(stderr, "\nsu: %s\n", strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t ret = 0;
|
off_t ret = 0;
|
||||||
if ((ret = read(STDIN_FILENO, psswd, sizeof(psswd))) <= 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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
psswd[ret - 1] = '\0';
|
psswd[ret - 1] = '\0';
|
||||||
if (pw_check("su", pw, psswd)) {
|
if (pw_check("su", pw, psswd)) {
|
||||||
memset(psswd, '\0', sizeof(psswd));
|
memset(psswd, '\0', sizeof(psswd));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("\n");
|
|
||||||
memset(psswd, '\0', sizeof(psswd));
|
memset(psswd, '\0', sizeof(psswd));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user