summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/xsh.c24
1 files changed, 24 insertions, 0 deletions
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 <security/_pam_aconf.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
+
/* ------ 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