Skip to content

Commit 5e04385

Browse files
committed
add and document hostname=... Fixes #104
1 parent c898ed1 commit 5e04385

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

USAGE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ client_id=bar - send a NAS-Identifier RADIUS attribute with string
6262
This feature may be disabled by using 'client_id='.
6363
i.e. A blank client ID.
6464

65+
hostname=foo - use the given value for the host name instead of the
66+
value returned by gethostname().
67+
This value is used to do a DNS lookup to set
68+
NAS-IP-Address and/or the NAS-IPv6-Address.
69+
6570
retry=# - How many times to re-send a packet if there is no
6671
response. Once the retry count has been reached,
6772
the module fails, and PAM continues to the next module.

src/pam_radius_auth.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
958970
static 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

src/pam_radius_auth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ typedef struct radius_conf_t {
190190
int privilege_level;
191191
int require_message_authenticator;
192192
uint8_t *message_authenticator;
193+
char hostname[MAXHOSTNAMELEN + 1];
193194
} radius_conf_t;
194195

195196
#endif /* PAM_RADIUS_H */

0 commit comments

Comments
 (0)