From da67a7d6126846939fd43b1ddb5aa8c06ee09301 Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Sun, 9 Dec 2001 22:15:11 +0000 Subject: Relevant BUGIDs: 490938 Purpose of commit: new feature Commit summary: --------------- Added libpammodutil and link it with every module as its built. The issue here is that there is a lot of code that the various modules use in common, and this staic library can be used to help make this code more maintainable. I do not intend to make this library dynamic. Especially right now, as I want to be free to chop and change the API and don't want to deal with revision control and third party modules. This checkin makes the pam_rhost_auth module make some use of this new library. I don't intend to add support for any other module prior to releasing 0.76. --- examples/xsh.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'examples') diff --git a/examples/xsh.c b/examples/xsh.c index 7babce42..dbb2416c 100644 --- a/examples/xsh.c +++ b/examples/xsh.c @@ -13,6 +13,10 @@ #include +#include +#include +#include + /* ------ some local (static) functions ------- */ static void bail_out(pam_handle_t *pamh,int really, int code, const char *fn) @@ -56,6 +60,26 @@ int main(int argc, char **argv) retcode = pam_start(service, username, &conv, &pamh); bail_out(pamh,1,retcode,"pam_start"); + /* fill in the RUSER and RHOST fields */ + { + char buffer[100]; + struct passwd *pw; + + pw = getpwuid(getuid()); + if (pw != NULL) { + retcode = pam_set_item(pamh, PAM_RUSER, pw->pw_name); + bail_out(pamh,1,retcode,"pam_set_item(PAM_RUSER)"); + } + retcode = gethostname(buffer, sizeof(buffer)-1); + if (retcode) { + perror("failed to look up hostname"); + retcode = pam_end(pamh, PAM_ABORT); + bail_out(pamh,1,retcode,"pam_end"); + } + retcode = pam_set_item(pamh, PAM_RHOST, buffer); + bail_out(pamh,1,retcode,"pam_set_item(PAM_RHOST)"); + } + /* to avoid using goto we abuse a loop here */ for (;;) { /* authenticate the user --- `0' here, could have been PAM_SILENT -- cgit v1.2.3