@@ -163,6 +163,18 @@ static int _pam_parse(int argc, CONST char **argv, radius_conf_t *conf)
163163 ctrl |= PAM_DEBUG_ARG ;
164164 conf -> debug = TRUE;
165165
166+ } else if (!strncmp (arg , "hostname=" , 9 )) {
167+ if (conf -> hostname [0 ] != '\0' ) {
168+ _pam_log (LOG_WARNING , "ignoring duplicate '%s'" , arg );
169+ } else {
170+ /* truncate excessive hostnames to MAXHOSTNAMELEN length */
171+ if (strlen (arg + 9 ) > MAXHOSTNAMELEN ) {
172+ * (arg + 9 + MAXHOSTNAMELEN ) = '\0' ;
173+ }
174+ /* set the new hostname */
175+ strcpy (conf -> hostname , arg + 9 );
176+ }
177+
166178 } else if (!strncmp (arg , "prompt=" , 7 )) {
167179 if (!strncmp (conf -> prompt , (arg + 7 ), MAXPROMPT )) {
168180 _pam_log (LOG_WARNING , "ignoring duplicate '%s'" , arg );
@@ -957,10 +969,14 @@ static int initialize(radius_conf_t *conf, int accounting)
957969 */
958970static void build_radius_packet (AUTH_HDR * request , CONST char * user , CONST char * password , radius_conf_t * conf )
959971{
960- char hostname [256 ];
972+ char hostname [MAXHOSTNAMELEN + 1 ];
961973
962974 hostname [0 ] = '\0' ;
963- gethostname (hostname , sizeof (hostname ) - 1 );
975+ if (conf -> hostname [0 ] != '\0' ) {
976+ strcpy (hostname , conf -> hostname );
977+ } else {
978+ gethostname (hostname , sizeof (hostname ) - 1 );
979+ }
964980
965981 /*
966982 * For Access-Request, create a random authentication
0 commit comments