directive, the LDAP queries include a sub-filter that limits retrieval to
entries that satisfy the time constraints, if any.
- If the N\bNE\bET\bTG\bGR\bRO\bOU\bUP\bP_\b_B\bBA\bAS\bSE\bE configuration directive is present, queries are
- performed to determine the list of netgroups the user belongs to before
- the sudoers query. This makes it possible to include netgroups in the
- sudoers query string in the same manner as Unix groups. The third query
- mentioned above is not performed unless a group provider plugin is also
- configured. The actual LDAP queries performed by s\bsu\bud\bdo\bo are as follows:
+ If the N\bNE\bET\bTG\bGR\bRO\bOU\bUP\bP_\b_B\bBA\bAS\bSE\bE configuration directive is present (see _\bC_\bo_\bn_\bf_\bi_\bg_\bu_\br_\bi_\bn_\bg
+ _\bl_\bd_\ba_\bp_\b._\bc_\bo_\bn_\bf below), queries are performed to determine the list of
+ netgroups the user belongs to before the sudoers query. This makes it
+ possible to include netgroups in the sudoers query string in the same
+ manner as Unix groups. The third query mentioned above is not performed
+ unless a group provider plugin is also configured. The actual LDAP
+ queries performed by s\bsu\bud\bdo\bo are as follows:
1. Match all nisNetgroup records with a nisNetgroupTriple containing
- the user and host. The query will match nisNetgroupTriple entries
- with either the short or long form of the host name or no host name
- specified in the tuple. A wildcard is used to match any domain name
- but be aware that the NIS schema used by some LDAP servers may not
- support wild cards for nisNetgroupTriple.
+ the user, host and NIS domain. The query will match
+ nisNetgroupTriple entries with either the short or long form of the
+ host name or no host name specified in the tuple. If the NIS domain
+ is set, the query will match only match entries that include the
+ domain or for which there is no domain present. If the NIS domain
+ is _\bn_\bo_\bt set, a wildcard is used to match any domain name but be aware
+ that the NIS schema used by some LDAP servers may not support wild
+ cards for nisNetgroupTriple.
2. Repeated queries are performed to find any nested nisNetgroup
records with a memberNisNetgroup entry that refers to an already-
file distributed with s\bsu\bud\bdo\bo or http://www.sudo.ws/license.html for
complete details.
-Sudo 1.8.12 January 26, 2015 Sudo 1.8.12
+Sudo 1.8.12 January 30, 2015 Sudo 1.8.12
struct ldap_netgroup *ng, *old_tail;
struct timeval tv, *tvp = NULL;
LDAPMessage *entry, *result;
+ const char *domain;
size_t filt_len;
char *filt;
int rc;
tvp = &tv;
}
+ /* Use NIS domain if set, else wildcard match. */
+ domain = sudo_getdomainname();
+
STAILQ_FOREACH(base, &ldap_conf.netgroup_base, entries) {
- /* Build query. */
- filt_len = 2 + strlen(ldap_conf.netgroup_search_filter) +
- 24 + (2 * sudo_ldap_value_len(pw->pw_name)) + 26 +
- sudo_ldap_value_len(user_shost) + 1 + 7 + 1;
- if (user_host != user_shost) {
- filt_len += 26 + sudo_ldap_value_len(user_host) + 1 +
- sudo_ldap_value_len(pw->pw_name);
- }
- filt = sudo_emalloc(filt_len);
DPRINTF1("searching from netgroup_base '%s'", base->val);
- CHECK_STRLCPY(filt, "(&", filt_len);
- CHECK_STRLCAT(filt, ldap_conf.netgroup_search_filter, filt_len);
- CHECK_STRLCAT(filt, "(|(nisNetgroupTriple=\\(,", filt_len);
- CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
- CHECK_STRLCAT(filt, ",*\\))(nisNetgroupTriple=\\(", filt_len);
- CHECK_LDAP_VCAT(filt, user_shost, filt_len);
- CHECK_STRLCAT(filt, ",", filt_len);
- CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
- if (user_host != user_shost) {
+
+ /* Build query, using NIS domain if it is set. */
+ if (domain != NULL) {
+ filt_len = sizeof("(nisNetgroupTriple=\\(,,\\))") - 1 +
+ sudo_ldap_value_len(pw->pw_name);
+ if (user_host == user_shost) {
+ filt_len *= 4;
+ filt_len += 2 * sudo_ldap_value_len(user_shost);
+ filt_len += 2 * sudo_ldap_value_len(domain);
+ } else {
+ filt_len *= 6;
+ filt_len += 2 * sudo_ldap_value_len(user_shost);
+ filt_len += 2 * sudo_ldap_value_len(user_host);
+ filt_len += 3 * sudo_ldap_value_len(domain);
+ }
+ filt_len += 7 + strlen(ldap_conf.netgroup_search_filter);
+ filt = sudo_emalloc(filt_len);
+ CHECK_STRLCPY(filt, "(&", filt_len);
+ CHECK_STRLCAT(filt, ldap_conf.netgroup_search_filter, filt_len);
+ CHECK_STRLCAT(filt, "(|(nisNetgroupTriple=\\(,", filt_len);
+ CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
+ CHECK_STRLCAT(filt, ",", filt_len);
+ CHECK_LDAP_VCAT(filt, domain, filt_len);
+ CHECK_STRLCAT(filt, "\\))(nisNetgroupTriple=\\(", filt_len);
+ CHECK_LDAP_VCAT(filt, user_shost, filt_len);
+ CHECK_STRLCAT(filt, ",", filt_len);
+ CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
+ if (user_host != user_shost) {
+ CHECK_STRLCAT(filt, ",", filt_len);
+ CHECK_LDAP_VCAT(filt, domain, filt_len);
+ CHECK_STRLCAT(filt, "\\))(nisNetgroupTriple=\\(", filt_len);
+ CHECK_LDAP_VCAT(filt, user_host, filt_len);
+ CHECK_STRLCAT(filt, ",", filt_len);
+ CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
+ }
+ CHECK_STRLCAT(filt, ",", filt_len);
+ CHECK_LDAP_VCAT(filt, domain, filt_len);
+ CHECK_STRLCAT(filt, "\\))(nisNetgroupTriple=\\(,", filt_len);
+ CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
+ CHECK_STRLCAT(filt, ",\\))(nisNetgroupTriple=\\(", filt_len);
+ CHECK_LDAP_VCAT(filt, user_shost, filt_len);
+ CHECK_STRLCAT(filt, ",", filt_len);
+ CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
+ if (user_host != user_shost) {
+ CHECK_STRLCAT(filt, ",\\))(nisNetgroupTriple=\\(", filt_len);
+ CHECK_LDAP_VCAT(filt, user_host, filt_len);
+ CHECK_STRLCAT(filt, ",", filt_len);
+ CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
+ }
+ CHECK_STRLCAT(filt, ",\\))))", filt_len);
+ } else {
+ filt_len = sizeof("(nisNetgroupTriple=\\(,,*\\))") - 1 +
+ sudo_ldap_value_len(pw->pw_name);
+ if (user_host == user_shost) {
+ filt_len *= 2;
+ filt_len += sudo_ldap_value_len(user_shost);
+ } else {
+ filt_len *= 3;
+ filt_len += sudo_ldap_value_len(user_shost);
+ filt_len += sudo_ldap_value_len(user_host);
+ }
+ filt_len += 7 + strlen(ldap_conf.netgroup_search_filter);
+ filt = sudo_emalloc(filt_len);
+ CHECK_STRLCPY(filt, "(&", filt_len);
+ CHECK_STRLCAT(filt, ldap_conf.netgroup_search_filter, filt_len);
+ CHECK_STRLCAT(filt, "(|(nisNetgroupTriple=\\(,", filt_len);
+ CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
CHECK_STRLCAT(filt, ",*\\))(nisNetgroupTriple=\\(", filt_len);
- CHECK_LDAP_VCAT(filt, user_host, filt_len);
+ CHECK_LDAP_VCAT(filt, user_shost, filt_len);
CHECK_STRLCAT(filt, ",", filt_len);
CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
+ if (user_host != user_shost) {
+ CHECK_STRLCAT(filt, ",*\\))(nisNetgroupTriple=\\(", filt_len);
+ CHECK_LDAP_VCAT(filt, user_host, filt_len);
+ CHECK_STRLCAT(filt, ",", filt_len);
+ CHECK_LDAP_VCAT(filt, pw->pw_name, filt_len);
+ }
+ CHECK_STRLCAT(filt, ",*\\))))", filt_len);
}
- CHECK_STRLCAT(filt, ",*\\))))", filt_len);
-
DPRINTF1("ldap netgroup search filter: '%s'", filt);
result = NULL;
rc = ldap_search_ext_s(ld, base->val, LDAP_SCOPE_SUBTREE, filt,