diff options
author | brian <brian@FreeBSD.org> | 1997-08-27 20:06:20 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-08-27 20:06:20 +0000 |
commit | 6c9afb5a313b719d4498d929ecf771ca26e79435 (patch) | |
tree | 5afe6f30a412635c518772d64620112ad847e9f2 /lib/libutil/login_progok.c | |
parent | 1fa2fafd210a0a94505d20066e2c109207101d32 (diff) | |
download | FreeBSD-src-6c9afb5a313b719d4498d929ecf771ca26e79435.zip FreeBSD-src-6c9afb5a313b719d4498d929ecf771ca26e79435.tar.gz |
Add full support for determining if a user
is restricted from running a given program.
Diffstat (limited to 'lib/libutil/login_progok.c')
-rw-r--r-- | lib/libutil/login_progok.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/libutil/login_progok.c b/lib/libutil/login_progok.c new file mode 100644 index 0000000..6ef2cf4 --- /dev/null +++ b/lib/libutil/login_progok.c @@ -0,0 +1,39 @@ +#include <sys/types.h> +#include <login_cap.h> +#include <pwd.h> +#include <string.h> + +int +login_progok(uid_t uid, const char *prog) +{ + login_cap_t *lc; + const struct passwd *pwd; + char **data; + + pwd = getpwuid(uid); + if (!pwd) + return 0; /* How did that happen ? - we can't run */ + + lc = login_getpwclass(pwd); + if (!lc) + return 1; /* We're missing login.conf ? - we can run */ + + data = login_getcaplist(lc, "prog.allow", NULL); + if (data) + for (; *data; data++) + if (!strcmp(*data, prog)) { + login_close(lc); + return 1; /* We're in prog.allow - we can run */ + } + + data = login_getcaplist(lc, "prog.deny", NULL); + if (data) + for (; *data; data++) + if (!strcmp(*data, prog)) { + login_close(lc); + return 0; /* We're in prog.deny - we can't run */ + } + + login_close(lc); + return 1; /* We're not mentioned anywhere - we can run */ +} |