From 6950b99458c49ba1711cba7bc01042a3403b8189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Thu, 11 Jul 2013 16:33:34 +0000 Subject: [PATCH] Add a command-line option that controls openpam_ttyconv_timeout. git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@685 185d5e19-27fe-0310-9dcf-9bff6b9f3609 --- bin/pamtest/pamtest.1 | 6 +++++- bin/pamtest/pamtest.c | 31 ++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/bin/pamtest/pamtest.1 b/bin/pamtest/pamtest.1 index 77fb0db..9d60dca 100644 --- a/bin/pamtest/pamtest.1 +++ b/bin/pamtest/pamtest.1 @@ -28,7 +28,7 @@ .\" .\" $Id$ .\" -.Dd April 14, 2012 +.Dd July 11, 2013 .Dt PAMTEST 1 .Os .Sh NAME @@ -39,6 +39,7 @@ .Op Fl dkMPsv .Op Fl H Ar rhost .Op Fl h Ar host +.Op Fl T Ar timeout .Op Fl t Ar tty .Op Fl U Ar ruser .Op Fl u Ar user @@ -136,6 +137,9 @@ flag when calling the and .Xr pam_close_session 3 primitives. +.It Fl T Ar timeout +Set the conversation timeout (in seconds) for +.Xr openpam_ttyconv 3 . .It Fl t Ar tty Specify the name of the tty. The default is to use the result of calling diff --git a/bin/pamtest/pamtest.c b/bin/pamtest/pamtest.c index 09769ce..6bb2d5c 100644 --- a/bin/pamtest/pamtest.c +++ b/bin/pamtest/pamtest.c @@ -34,6 +34,7 @@ #endif #include +#include #include #include #include @@ -274,6 +275,24 @@ usage(void) exit(1); } +/* + * Handle an option that takes an int argument and can be used only once + */ +static void +opt_num_once(int opt, long *num, const char *arg) +{ + char *end; + long l; + + l = strtol(arg, &end, 0); + if (end == optarg || *end != '\0') { + fprintf(stderr, + "The -%c option expects a numeric argument\n", opt); + usage(); + } + *num = l; +} + /* * Handle an option that takes a string argument and can be used only once */ @@ -301,11 +320,12 @@ main(int argc, char *argv[]) const char *user = NULL; const char *service = NULL; const char *tty = NULL; + long timeout = 0; int keepatit = 0; int pame; int opt; - while ((opt = getopt(argc, argv, "dH:h:kMPst:U:u:v")) != -1) + while ((opt = getopt(argc, argv, "dH:h:kMPsT:t:U:u:v")) != -1) switch (opt) { case 'd': openpam_debug++; @@ -330,6 +350,15 @@ main(int argc, char *argv[]) case 's': silent = PAM_SILENT; break; + case 'T': + opt_num_once(opt, &timeout, optarg); + if (timeout < 0 || timeout > INT_MAX) { + fprintf(stderr, + "Invalid conversation timeout\n"); + usage(); + } + openpam_ttyconv_timeout = (int)timeout; + break; case 't': opt_str_once(opt, &tty, optarg); break;