diff options
author | Lukas Slebodnik <lslebodn@redhat.com> | 2014-05-31 19:06:56 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-06-03 14:46:17 +0200 |
commit | 8269d3c385ac1686f2dcf778827f04435f1ec4bf (patch) | |
tree | cf875dac5ad676d2cb5ecb16daa948d33a0b01f8 /src/providers/ldap | |
parent | 973f2f3d0056f0150715db8b6c40a2eb5d964ea9 (diff) | |
download | sssd-8269d3c385ac1686f2dcf778827f04435f1ec4bf.tar.gz sssd-8269d3c385ac1686f2dcf778827f04435f1ec4bf.tar.xz sssd-8269d3c385ac1686f2dcf778827f04435f1ec4bf.zip |
Unify usage of function gethostname
man gethostanme says:
NOTES
SUSv2 guarantees that "Host names are limited to 255 bytes".
POSIX.1-2001 guarantees that "Host names (not including the terminating
null byte) are limited to HOST_NAME_MAX bytes". On Linux,
HOST_NAME_MAX is defined with the value 64, which has been the limit
since Linux 1.0 (earlier kernels imposed a limit of 8 bytes).
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
(cherry picked from commit bf6f1b3d49e17b1adf0448c0b06e94b1e52ddffd)
Diffstat (limited to 'src/providers/ldap')
-rw-r--r-- | src/providers/ldap/ldap_child.c | 6 | ||||
-rw-r--r-- | src/providers/ldap/sdap_access.c | 5 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/providers/ldap/ldap_child.c b/src/providers/ldap/ldap_child.c index 34f23ec80..96404c4c8 100644 --- a/src/providers/ldap/ldap_child.c +++ b/src/providers/ldap/ldap_child.c @@ -229,14 +229,14 @@ static krb5_error_code ldap_child_get_tgt_sync(TALLOC_CTX *memctx, full_princ = talloc_strdup(memctx, princ_str); } } else { - char hostname[512]; + char hostname[HOST_NAME_MAX + 1]; - ret = gethostname(hostname, 511); + ret = gethostname(hostname, HOST_NAME_MAX); if (ret == -1) { krberr = KRB5KRB_ERR_GENERIC; goto done; } - hostname[511] = '\0'; + hostname[HOST_NAME_MAX] = '\0'; DEBUG(SSSDBG_TRACE_LIBS, "got hostname: [%s]\n", hostname); diff --git a/src/providers/ldap/sdap_access.c b/src/providers/ldap/sdap_access.c index 4e1709028..486a08c85 100644 --- a/src/providers/ldap/sdap_access.c +++ b/src/providers/ldap/sdap_access.c @@ -1067,7 +1067,7 @@ static errno_t sdap_access_host(struct ldb_message *user_entry) struct ldb_message_element *el; unsigned int i; char *host; - char hostname[HOST_NAME_MAX+1]; + char hostname[HOST_NAME_MAX + 1]; el = ldb_msg_find_element(user_entry, SYSDB_AUTHORIZED_HOST); if (!el || el->num_values == 0) { @@ -1075,11 +1075,12 @@ static errno_t sdap_access_host(struct ldb_message *user_entry) return ERR_ACCESS_DENIED; } - if (gethostname(hostname, sizeof(hostname)) == -1) { + if (gethostname(hostname, HOST_NAME_MAX) == -1) { DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get system hostname. Access denied\n"); return ERR_ACCESS_DENIED; } + hostname[HOST_NAME_MAX] = '\0'; /* FIXME: PADL's pam_ldap also calls gethostbyname() on the hostname * in some attempt to get aliases and/or FQDN for the machine. |