diff options
Diffstat (limited to 'examples/xsh.c')
-rw-r--r-- | examples/xsh.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/examples/xsh.c b/examples/xsh.c index 5b34fc17..29f4dc00 100644 --- a/examples/xsh.c +++ b/examples/xsh.c @@ -32,6 +32,22 @@ static struct pam_conv conv = { /* ------- the application itself -------- */ +static char *xgethostname() { + long max_host_name; + char *buffer; + + max_host_name = sysconf(_SC_HOST_NAME_MAX); + buffer = malloc(max_host_name + 1); + + if (gethostname(buffer, max_host_name + 1)) { + free(buffer); + return NULL; + } + + buffer[max_host_name] = '\0'; + return buffer; +} + int main(int argc, char **argv) { pam_handle_t *pamh=NULL; @@ -58,7 +74,7 @@ int main(int argc, char **argv) /* fill in the RUSER and RHOST etc. fields */ { - char buffer[100]; + char *myhostname; struct passwd *pw; const char *tty; @@ -68,13 +84,14 @@ int main(int argc, char **argv) bail_out(pamh,1,retcode,"pam_set_item(PAM_RUSER)"); } - retcode = gethostname(buffer, sizeof(buffer)-1); - if (retcode) { + myhostname = xgethostname(); + if (!myhostname) { 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); + retcode = pam_set_item(pamh, PAM_RHOST, myhostname); + free(myhostname); bail_out(pamh,1,retcode,"pam_set_item(PAM_RHOST)"); tty = ttyname(fileno(stdin)); |