Skip to content

Commit

Permalink
Merge pull request #6 from lmctv/pam_rhost
Browse files Browse the repository at this point in the history
New version of Enable PAM_RHOST patch
  • Loading branch information
quanah committed Mar 2, 2020
2 parents bda4c98 + c813bf1 commit f769dde
Show file tree
Hide file tree
Showing 29 changed files with 144 additions and 52 deletions.
25 changes: 22 additions & 3 deletions lib/checkpw.c
Expand Up @@ -657,6 +657,8 @@ static int saslauthd_verify_password(sasl_conn_t *conn,
char pwpath[sizeof(srvaddr.sun_path)];
const char *p = NULL;
char *freeme = NULL;
char *freemetoo = NULL;
const char *client_addr = NULL;
#ifdef USE_DOORS
door_arg_t arg;
#endif
Expand Down Expand Up @@ -692,28 +694,36 @@ static int saslauthd_verify_password(sasl_conn_t *conn,
user_realm = rtmp + 1;
}

if (sasl_getprop(conn, SASL_IPREMOTEPORT, (const void **) & client_addr) == SASL_OK) {
if(_sasl_strdup(client_addr, &freemetoo, NULL) != SASL_OK)
goto fail;
client_addr = freemetoo;
}

/*
* build request of the form:
*
* count authid count password count service count realm
* count authid count password count service count realm client
*/
{
unsigned short max_len, req_len, u_len, p_len, s_len, r_len;
unsigned short max_len, req_len, u_len, p_len, s_len, r_len, c_len;

max_len = (unsigned short) sizeof(query);

/* prevent buffer overflow */
if ((strlen(userid) > USHRT_MAX) ||
(strlen(passwd) > USHRT_MAX) ||
(strlen(service) > USHRT_MAX) ||
(user_realm && (strlen(user_realm) > USHRT_MAX))) {
(user_realm && (strlen(user_realm) > USHRT_MAX)) ||
(client_addr && (strlen(client_addr) > USHRT_MAX))) {
goto toobig;
}

u_len = (strlen(userid));
p_len = (strlen(passwd));
s_len = (strlen(service));
r_len = ((user_realm ? strlen(user_realm) : 0));
c_len = ((client_addr ? strlen(client_addr): 0));

/* prevent buffer overflow */
req_len = 30;
Expand All @@ -724,11 +734,14 @@ static int saslauthd_verify_password(sasl_conn_t *conn,
if (max_len - req_len < s_len) goto toobig;
req_len += s_len;
if (max_len - req_len < r_len) goto toobig;
req_len += r_len;
if (max_len - req_len < c_len) goto toobig;

u_len = htons(u_len);
p_len = htons(p_len);
s_len = htons(s_len);
r_len = htons(r_len);
c_len = htons(c_len);

memcpy(query_end, &u_len, sizeof(unsigned short));
query_end += sizeof(unsigned short);
Expand All @@ -745,6 +758,10 @@ static int saslauthd_verify_password(sasl_conn_t *conn,
memcpy(query_end, &r_len, sizeof(unsigned short));
query_end += sizeof(unsigned short);
if (user_realm) while (*user_realm) *query_end++ = *user_realm++;

memcpy(query_end, &c_len, sizeof(unsigned short));
query_end += sizeof(unsigned short);
if(client_addr) while (*client_addr) *query_end++ = *client_addr++;
}

#ifdef USE_DOORS
Expand Down Expand Up @@ -847,6 +864,7 @@ static int saslauthd_verify_password(sasl_conn_t *conn,
#endif /* USE_DOORS */

if(freeme) free(freeme);
if(freemetoo) free(freemetoo);

if (!strncmp(response, "OK", 2)) {
return SASL_OK;
Expand All @@ -861,6 +879,7 @@ static int saslauthd_verify_password(sasl_conn_t *conn,

fail:
if (freeme) free(freeme);
if (freemetoo) free(freemetoo);
return SASL_FAIL;
}

Expand Down
6 changes: 4 additions & 2 deletions saslauthd/auth_dce.c
Expand Up @@ -52,7 +52,8 @@ auth_dce(
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused))
/* END PARAMETERS */
)
{
Expand Down Expand Up @@ -100,7 +101,8 @@ auth_dce(
const char *login __attribute__((unused)),
const char *password __attribute__((unused)),
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused))
)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_dce.h
Expand Up @@ -26,4 +26,4 @@
* END COPYRIGHT
*/

char *auth_dce(const char *, const char *, const char *, const char *);
char *auth_dce(const char *, const char *, const char *, const char *, const char *);
3 changes: 2 additions & 1 deletion saslauthd/auth_getpwent.c
Expand Up @@ -68,7 +68,8 @@ auth_getpwent (
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused)) /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_getpwent.h
Expand Up @@ -25,4 +25,4 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_getpwent(const char *, const char *, const char *, const char *);
char *auth_getpwent(const char *, const char *, const char *, const char *, const char *);
3 changes: 2 additions & 1 deletion saslauthd/auth_httpform.c
Expand Up @@ -491,7 +491,8 @@ auth_httpform (
const char *user, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service __attribute__((unused)),
const char *realm /* I: user's realm */
const char *realm, /* I: user's realm */
const char *remote __attribute__((unused)) /* I: client address */
/* END PARAMETERS */
)
{
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_httpform.h
Expand Up @@ -25,5 +25,5 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_httpform(const char *, const char *, const char *, const char *);
char *auth_httpform(const char *, const char *, const char *, const char *, const char *);
int auth_httpform_init(void);
6 changes: 4 additions & 2 deletions saslauthd/auth_krb4.c
Expand Up @@ -167,7 +167,8 @@ auth_krb4 (
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service,
const char *realm_in
const char *realm_in,
const char *remote /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down Expand Up @@ -278,7 +279,8 @@ auth_krb4 (
const char *login __attribute__((unused)),
const char *password __attribute__((unused)),
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused))
)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_krb4.h
Expand Up @@ -25,5 +25,5 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_krb4(const char *, const char *, const char *, const char *);
char *auth_krb4(const char *, const char *, const char *, const char *, const char *);
int auth_krb4_init(void);
9 changes: 6 additions & 3 deletions saslauthd/auth_krb5.c
Expand Up @@ -175,7 +175,8 @@ auth_krb5 (
const char *user, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service, /* I: service authenticating to */
const char *realm /* I: user's realm */
const char *realm, /* I: user's realm */
const char *remote /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down Expand Up @@ -362,7 +363,8 @@ auth_krb5 (
const char *user, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service, /* I: service authenticating to */
const char *realm /* I: user's realm */
const char *realm, /* I: user's realm */
const char *remote /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down Expand Up @@ -470,7 +472,8 @@ auth_krb5 (
const char *login __attribute__((unused)),
const char *password __attribute__((unused)),
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused))
)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_krb5.h
Expand Up @@ -25,5 +25,5 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_krb5(const char *, const char *, const char *, const char *);
char *auth_krb5(const char *, const char *, const char *, const char *, const char *);
int auth_krb5_init(void);
6 changes: 4 additions & 2 deletions saslauthd/auth_ldap.c
Expand Up @@ -56,7 +56,8 @@ auth_ldap(
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service,
const char *realm
const char *realm,
const char *remote /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down Expand Up @@ -106,7 +107,8 @@ auth_ldap(
const char *login __attribute__((unused)),
const char *password __attribute__((unused)),
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused))
)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_ldap.h
Expand Up @@ -25,5 +25,5 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_ldap(const char *, const char *, const char *, const char *);
char *auth_ldap(const char *, const char *, const char *, const char *, const char *);
int auth_ldap_init(void);
14 changes: 12 additions & 2 deletions saslauthd/auth_pam.c
Expand Up @@ -181,7 +181,8 @@ auth_pam (
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service, /* I: service name */
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote /* I: remote host address */
/* END PARAMETERS */
)
{
Expand All @@ -208,6 +209,14 @@ auth_pam (

my_appdata.pamh = pamh;

char * remote_host = strdup(remote);
if (remote_host) {
char * semicol = strchr(remote_host, ';');
if (semicol) * semicol = NULL; /* truncate remote_host at the ';' port separator */
pam_set_item(pamh, PAM_RHOST, remote_host);
free (remote_host);
}

rc = pam_authenticate(pamh, PAM_SILENT);
if (rc != PAM_SUCCESS) {
syslog(LOG_DEBUG, "DEBUG: auth_pam: pam_authenticate failed: %s",
Expand Down Expand Up @@ -237,7 +246,8 @@ auth_pam(
const char *login __attribute__((unused)),
const char *password __attribute__((unused)),
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused))
)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_pam.h
Expand Up @@ -32,4 +32,4 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_pam(const char *, const char *, const char *, const char *);
char *auth_pam(const char *, const char *, const char *, const char *, const char *);
3 changes: 2 additions & 1 deletion saslauthd/auth_rimap.c
Expand Up @@ -451,7 +451,8 @@ auth_rimap (
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused)) /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_rimap.h
Expand Up @@ -25,5 +25,5 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_rimap(const char *, const char *, const char *, const char *);
char *auth_rimap(const char *, const char *, const char *, const char *, const char *);
int auth_rimap_init(void);
5 changes: 3 additions & 2 deletions saslauthd/auth_sasldb.c
Expand Up @@ -120,13 +120,14 @@ auth_sasldb (
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service __attribute__((unused)),
const char *realm
const char *realm,
#else
const char *login __attribute__((unused)),/* I: plaintext authenticator */
const char *password __attribute__((unused)), /* I: plaintext password */
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
#endif
const char *remote __attribute__((unused)) /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_sasldb.h
Expand Up @@ -25,4 +25,4 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_sasldb(const char *, const char *, const char *, const char *);
char *auth_sasldb(const char *, const char *, const char *, const char *, const char *);
6 changes: 4 additions & 2 deletions saslauthd/auth_shadow.c
Expand Up @@ -94,7 +94,8 @@ auth_shadow (
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused)) /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down Expand Up @@ -321,7 +322,8 @@ auth_shadow (
const char *login __attribute__((unused)),
const char *passwd __attribute__((unused)),
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused))
)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_shadow.h
Expand Up @@ -25,4 +25,4 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_shadow(const char *, const char *, const char *, const char *);
char *auth_shadow(const char *, const char *, const char *, const char *, const char *);
6 changes: 4 additions & 2 deletions saslauthd/auth_sia.c
Expand Up @@ -52,7 +52,8 @@ auth_sia (
const char *login, /* I: plaintext authenticator */
const char *password, /* I: plaintext password */
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused)) /* I: remote host address */
/* END PARAMETERS */
)
{
Expand Down Expand Up @@ -80,7 +81,8 @@ auth_sia(
const char *login __attribute__((unused)),
const char *password __attribute__((unused)),
const char *service __attribute__((unused)),
const char *realm __attribute__((unused))
const char *realm __attribute__((unused)),
const char *remote __attribute__((unused))
)
{
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion saslauthd/auth_sia.h
Expand Up @@ -25,4 +25,4 @@
* DAMAGE.
* END COPYRIGHT */

char *auth_sia(const char *, const char *, const char *, const char *);
char *auth_sia(const char *, const char *, const char *, const char *, const char *);

0 comments on commit f769dde

Please sign in to comment.