diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c96d17 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +us diff --git a/makefile b/makefile index ec6f2ab..84a0c0f 100644 --- a/makefile +++ b/makefile @@ -1,7 +1,7 @@ CC ?= gcc CFLAGS = -Wall -pedantic --std=c99 -O2 DBG_CFLAGS = -Wall -Werror -pedantic --std=c99 -O0 -g -LDFLAGS = -lcrypt +LDFLAGS != if [ "$(uname)" = 'Linux' ]; then printf '-lcrypt'; fi PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man @@ -13,7 +13,7 @@ dbg: install: us mkdir -p ${DESTDIR}${PREFIX}/bin cp -f us ${DESTDIR}${PREFIX}/bin/us - chown root:root ${DESTDIR}${PREFIX}/bin/us + chown 0:0 ${DESTDIR}${PREFIX}/bin/us chmod 4755 ${DESTDIR}${PREFIX}/bin/us # mkdir -p ${DESTDIR}${MANPREFIX}/man1 # cp -f us.1 ${DESTDIR}${MANPREFIX}/man1/us.1 diff --git a/us.c b/us.c index a888a87..4b486cc 100644 --- a/us.c +++ b/us.c @@ -17,7 +17,11 @@ */ #define _POSIX_C_SOURCE 200809L +#ifdef __linux__ #define _DEFAULT_SOURCE +#else +#define _BSD_SOURCE +#endif #include #include @@ -298,7 +302,6 @@ static int authenticate(uid_t uid, char ask) if (!op) die("getpwuid_shadow:"); hash_p = op->pw_passwd; - exit(EXIT_FAILURE); #endif } else { hash_p = pw->pw_passwd; @@ -374,7 +377,7 @@ static int authenticate(uid_t uid, char ask) char *enc = crypt(pass, hash); memset(pass, 0, 1024); - if (strcmp(enc, hash)) { + if (strncmp(hash, enc, 1024)) { printf("Authentication failure\n"); setuid(uid); return -1;