From 38bf64b415376f1419cd798fd753736960355bf5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 22 Nov 2013 10:03:07 +0100 Subject: first version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 66 ++++++-------------------------------------------------- src/passphrase.c | 16 +++----------- src/passphrase.h | 8 +++---- 3 files changed, 14 insertions(+), 76 deletions(-) diff --git a/Makefile b/Makefile index 8e112d5..87ce435 100644 --- a/Makefile +++ b/Makefile @@ -1,76 +1,24 @@ -USR_PREFIX = /usr -LOCAL_PREFIX = $(USR_PREFIX)/local -BIN = /bin -SBIN = /sbin -DEV = /dev - -EXTRA_CPP_FLAGS = -# see configurable-definitions - -_LB = $(LOCAL_PREFIX)$(BIN) -_UB = $(USR_PREFIX)$(BIN) -_SB = $(BIN) -_LS = $(LOCAL_PREFIX)$(SBIN) -_US = $(USR_PREFIX)$(SBIN) -_SS = $(SBIN) - -AUTH = pam -TTY_GROUP = tty -DEFAULT_HOME = / -DEFAULT_SH = sh -DEFAULT_SHELL = $(BIN)/$(DEFAULT_SH) -DEFAULT_TERM = dumb -VCS = $(DEV)/vcs -VCSA = $(DEV)/vcsa -PATH = $(_LB):$(_UB):$(_SB) -PATH_ROOT = $(_LS):$(_LB):$(_US):$(_UB):$(_SS):$(_SB) - -auth_none = 0 -auth_crypt = 1 -auth_pam = 2 - -H = \# -VCS_LEN = $(shell vcs="$(VCS)" ; echo "$${$(H)vcs}") -VCSA_LEN = $(shell vcsa="$(VCSA)" ; echo "$${$(H)vcsa}") - -STR_DEFS = TTY_GROUP DEFAULT_HOME DEFAULT_SH DEFAULT_SHELL DEFAULT_TERM PATH PATH_ROOT VCS VCSA -VRB_DEFS = VCS_LEN VCSA_LEN - -STR_CPPFLAGS = $(foreach D, $(STR_DEFS), -D'$(D)="$($(D))"') -VRB_CPPFLAGS = $(foreach D, $(VRB_DEFS), -D'$(D)=$($(D))') -DAUTH=$(auth_$(AUTH)) - OPTIMISE = -Os -CPPFLAGS = $(EXTRA_CPP_FLAGS) $(STR_CPPFLAGS) $(VRB_CPPFLAGS) -CFLAGS = -std=gnu99 -Wall -Wextra -LDFLAGS = -ifeq ($(AUTH),crypt) -LDFLAGS += -lcrypt -endif -ifeq ($(AUTH),pam) -LDFLAGS += -lpam -endif +CPPFLAGS = +CFLAGS = -std=c90 -Wall -Wextra -fPIC +LDFLAGS = -shared CC_FLAGS = $(CPPFLAGS) $(CFLAGS) $(OPTIMISE) LD_FLAGS = $(LDFLAGS) $(CFLAGS) $(OPTIMISE) -SRC = cerberus passphrase quit security login -ifneq ($(AUTH),none) -SRC += auth/$(AUTH) -endif +SRC = passphrase OBJ = $(foreach S, $(SRC), obj/$(S).o) .PHONY: all -all: bin/cerberus +all: bin/libpassphrase.so -bin/cerberus: $(OBJ) +bin/libpassphrase.so: $(OBJ) @mkdir -p bin $(CC) $(LD_FLAGS) -o "$@" $^ - -obj/cerberus.o: $(foreach H, $(SRC), src/$(H).h) src/auth.h -obj/%.o: src/%.c src/%.h src/config.h +obj/%.o: src/%.c src/%.h @mkdir -p "$(shell dirname "$@")" $(CC) $(CC_FLAGS) -o "$@" -c "$<" diff --git a/src/passphrase.c b/src/passphrase.c index 93cfd9f..a3ca289 100644 --- a/src/passphrase.c +++ b/src/passphrase.c @@ -21,8 +21,6 @@ #include #include -#include "config.h" - #include "passphrase.h" @@ -38,7 +36,7 @@ static struct termios saved_stty; /** * Reads the passphrase from stdin * - * @return The passphrase, should be `free`:ed + * @return The passphrase, should be wiped `free`:ed, `NULL` on error */ char* get_passphrase(void) { @@ -52,11 +50,7 @@ char* get_passphrase(void) int c; if (rc == NULL) - { - perror("malloc"); - sleep(ERROR_SLEEP); - _exit(1); - } + return NULL; /* Read password until EOF or Enter, skip all \0 as that is probably not a part of the passphrase (good luck typing @@ -71,11 +65,7 @@ char* get_passphrase(void) *(rc + len++) = c; if (len == size) if ((rc = realloc(rc, (size <<= 1L) * sizeof(char))) == NULL) - { - perror("realloc"); - sleep(ERROR_SLEEP); - _exit(1); - } + return NULL; } } diff --git a/src/passphrase.h b/src/passphrase.h index 8dbc39d..9a1baa5 100644 --- a/src/passphrase.h +++ b/src/passphrase.h @@ -23,19 +23,19 @@ /** * Reads the passphrase from stdin * - * @return The passphrase, should be `free`:ed + * @return The passphrase, should be wiped `free`:ed, `NULL` on error */ -char* get_passphrase(void); +extern char* get_passphrase(void); /** * Disable echoing and do anything else to the terminal settnings `get_passphrase` requires */ -void disable_echo(void); +extern void disable_echo(void); /** * Undo the actions of `disable_echo` */ -void reenable_echo(void); +extern void reenable_echo(void); #endif -- cgit v1.2.3-70-g09d2