From 73461538c2a564f3992725609929618b698e9701 Mon Sep 17 00:00:00 2001 From: Philippe Charnier Date: Sun, 18 Jan 2004 21:46:39 +0000 Subject: Remove unused includes. Make it WARNS=6 friendly. Concerning bin/2442, make a new function dup_shell() to replace ok_shell() and make it unconditionnally strdup() its result to make the caller's code simplier. Change ok_shell() to just return an integer value suitable for tests (it was used mainly for that purpose). Do not use strdup() in the caller's code but rely on dup_shell() that will do the job for us. PR: bin/2442 --- chpass/util.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'chpass/util.c') diff --git a/chpass/util.c b/chpass/util.c index ac105aa..07d96e2 100644 --- a/chpass/util.c +++ b/chpass/util.c @@ -49,7 +49,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include @@ -139,18 +138,45 @@ bad: return (1); return (0); } -char * +int ok_shell(char *name) { char *p, *sh; setusershell(); while ((sh = getusershell())) { - if (!strcmp(name, sh)) - return (name); + if (!strcmp(name, sh)) { + endusershell(); + return (1); + } + /* allow just shell name, but use "real" path */ + if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) { + endusershell(); + return (1); + } + } + endusershell(); + return (0); +} + +char * +dup_shell(char *name) +{ + char *p, *sh, *ret; + + setusershell(); + while ((sh = getusershell())) { + if (!strcmp(name, sh)) { + endusershell(); + return (strdup(name)); + } /* allow just shell name, but use "real" path */ - if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) - return (sh); + if ((p = strrchr(sh, '/')) && strcmp(name, p + 1) == 0) { + ret = strdup(sh); + endusershell(); + return (ret); + } } + endusershell(); return (NULL); } -- cgit v1.2.3-56-ge451