Skip to content

Commit

Permalink
hostname: add conf hostname=
Browse files Browse the repository at this point in the history
If the configuration provides a hostname, let's use it instead of the
local hostname.
  • Loading branch information
vjardin committed Dec 1, 2024
1 parent c898ed1 commit bc3b684
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/pam_radius_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ static int _pam_parse(int argc, CONST char **argv, radius_conf_t *conf)
ctrl |= PAM_DEBUG_ARG;
conf->debug = TRUE;

} else if (!strncmp(*argv, "hostname=", 9)) {
if (!strncmp(conf->hostname, (char*)*argv+9, MAXHOSTNAME)) {
_pam_log(LOG_WARNING, "ignoring duplicate '%s'", *argv);
} else {
/* truncate excessive hostnames to (MAXHOSTNAME -1) length */
if (strlen((char*)*argv+9) >= (MAXHOSTNAME - 1)) {
*((char*)*argv+9 + (MAXHOSTNAME - 1)) = 0;
}
/* set the new hostname */
memset(conf->hostname, 0, sizeof(conf->hostname));
snprintf(conf->hostname, MAXHOSTNAME, "%s", (char*)*argv+9);
}

} else if (!strncmp(arg, "prompt=", 7)) {
if (!strncmp(conf->prompt, (arg+7), MAXPROMPT)) {
_pam_log(LOG_WARNING, "ignoring duplicate '%s'", arg);
Expand Down Expand Up @@ -957,10 +970,14 @@ static int initialize(radius_conf_t *conf, int accounting)
*/
static void build_radius_packet(AUTH_HDR *request, CONST char *user, CONST char *password, radius_conf_t *conf)
{
char hostname[256];
char hostname[MAXHOSTNAME];

hostname[0] = '\0';
gethostname(hostname, sizeof(hostname) - 1);
if (conf->hostname[0] != '\0') {
strcpy(hostname, conf->hostname);
} else {
gethostname(hostname, sizeof(hostname) - 1);
}

/*
* For Access-Request, create a random authentication
Expand Down
2 changes: 2 additions & 0 deletions src/pam_radius_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#define MAXPROMPT 33 /* max prompt length, including '\0' */
#define DEFAULT_PROMPT "Password" /* default prompt, without the ': ' */

#define MAXHOSTNAME 65

/*************************************************************************
* Platform specific defines
Expand Down Expand Up @@ -190,6 +191,7 @@ typedef struct radius_conf_t {
int privilege_level;
int require_message_authenticator;
uint8_t *message_authenticator;
char hostname[MAXHOSTNAME];
} radius_conf_t;

#endif /* PAM_RADIUS_H */

0 comments on commit bc3b684

Please sign in to comment.