Print this page
NEX-14547 Get UNIX group info. from AD/LDAP with partial RFC2307 schema
NEX-13132 smbd dumping core in nss_ldap.so.1`getbymember
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libsldap/common/ns_reads.c
          +++ new/usr/src/lib/libsldap/common/ns_reads.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
       23 + * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
  23   24   */
  24   25  
  25   26  #include <stdio.h>
  26   27  #include <sys/types.h>
  27   28  #include <stdlib.h>
  28   29  #include <libintl.h>
  29   30  #include <ctype.h>
  30   31  #include <syslog.h>
  31   32  #include <sys/stat.h>
  32   33  #include <fcntl.h>
↓ open down ↓ 187 lines elided ↑ open up ↑
 220  221          char    **mapped_rdns;
 221  222          char    **rdns, *new_rdn, *new_dn = NULL;
 222  223          int     nRdn = 0, i, len = 0, rdn_mapped;
 223  224  
 224  225          if (service == NULL || dn == NULL)
 225  226                  return (NULL);
 226  227  
 227  228          if ((rdns = ldap_explode_dn(dn, 0)) == NULL)
 228  229                  return (NULL);
 229  230  
 230      -        for (nRdn = 0; rdns[nRdn] != NULL; nRdn++);
      231 +        for (nRdn = 0; rdns[nRdn] != NULL; nRdn++)
      232 +                ;
 231  233  
 232  234          if ((mapped_rdns = (char **)calloc(nRdn, sizeof (char *))) == NULL) {
 233  235                  ldap_value_free(rdns);
 234  236                  return (NULL);
 235  237          }
 236  238  
 237  239          rdn_mapped = 0;
 238  240          /* Break down RDNs in a DN */
 239  241          for (i = 0; i < nRdn; i++) {
 240  242                  if ((new_rdn = _cvtRDN(service, rdns[i])) != NULL) {
↓ open down ↓ 3982 lines elided ↑ open up ↑
4223 4225                  return (NS_LDAP_INTERNAL);
4224 4226          }
4225 4227  
4226 4228          value = __ns_ldap_getAttr(result->entry, "dn");
4227 4229          *userDN = strdup(value[0]);
4228 4230          (void) __ns_ldap_freeResult(&result);
4229 4231          result = NULL;
4230 4232          return (NS_LDAP_SUCCESS);
4231 4233  }
4232 4234  
     4235 +#define _P_UID  "uid"
     4236 +static const char *dn2uid_attrs[] = {
     4237 +        _P_CN,
     4238 +        _P_UID,
     4239 +        (char *)NULL
     4240 +};
4233 4241  
4234 4242  /*ARGSUSED*/
     4243 +int
     4244 +__ns_ldap_dn2uid(const char *dn,
     4245 +                char **userID,
     4246 +                const ns_cred_t *cred,  /* cred is ignored */
     4247 +                ns_ldap_error_t **errorp)
     4248 +{
     4249 +        ns_ldap_result_t        *result = NULL;
     4250 +        char            *filter, *userdata;
     4251 +        char            errstr[MAXERROR];
     4252 +        char            **value;
     4253 +        int             rc = 0;
     4254 +        size_t          len;
     4255 +
     4256 +        *errorp = NULL;
     4257 +        *userID = NULL;
     4258 +        if ((dn == NULL) || (dn[0] == '\0'))
     4259 +                return (NS_LDAP_INVALID_PARAM);
     4260 +
     4261 +        len = strlen(UIDDNFILTER) + strlen(dn) + 1;
     4262 +        filter = (char *)malloc(len);
     4263 +        if (filter == NULL) {
     4264 +                return (NS_LDAP_MEMORY);
     4265 +        }
     4266 +        (void) snprintf(filter, len, UIDDNFILTER, dn);
     4267 +
     4268 +        len = strlen(UIDDNFILTER_SSD) + strlen(dn) + 1;
     4269 +        userdata = (char *)malloc(len);
     4270 +        if (userdata == NULL) {
     4271 +                return (NS_LDAP_MEMORY);
     4272 +        }
     4273 +        (void) snprintf(userdata, len, UIDDNFILTER_SSD, dn);
     4274 +
     4275 +        /*
     4276 +         * Unlike uid2dn, we DO want attribute mapping, so that
     4277 +         * "uid" is mapped to/from samAccountName, for example.
     4278 +         */
     4279 +        rc = __ns_ldap_list("passwd", filter,
     4280 +            __s_api_merge_SSD_filter,
     4281 +            dn2uid_attrs, cred, 0,
     4282 +            &result, errorp, NULL,
     4283 +            userdata);
     4284 +        free(filter);
     4285 +        filter = NULL;
     4286 +        free(userdata);
     4287 +        userdata = NULL;
     4288 +        if (rc != NS_LDAP_SUCCESS)
     4289 +                goto out;
     4290 +
     4291 +        if (result->entries_count > 1) {
     4292 +                (void) sprintf(errstr,
     4293 +                    gettext("Too many entries are returned for %s"), dn);
     4294 +                MKERROR(LOG_WARNING, *errorp, NS_LDAP_INTERNAL, strdup(errstr),
     4295 +                    NULL);
     4296 +                rc = NS_LDAP_INTERNAL;
     4297 +                goto out;
     4298 +        }
     4299 +
     4300 +        value = __ns_ldap_getAttr(result->entry, _P_UID);
     4301 +        if (value == NULL || value[0] == NULL) {
     4302 +                rc = NS_LDAP_NOTFOUND;
     4303 +                goto out;
     4304 +        }
     4305 +
     4306 +        *userID = strdup(value[0]);
     4307 +        rc = NS_LDAP_SUCCESS;
     4308 +
     4309 +out:
     4310 +        (void) __ns_ldap_freeResult(&result);
     4311 +        result = NULL;
     4312 +        return (rc);
     4313 +}
     4314 +
     4315 +/*ARGSUSED*/
4235 4316  int
4236 4317  __ns_ldap_host2dn(const char *host,
4237 4318                  const char *domain,
4238 4319                  char **hostDN,
4239 4320                  const ns_cred_t *cred,  /* cred is ignored */
4240 4321                  ns_ldap_error_t **errorp)
4241 4322  {
4242 4323          ns_ldap_result_t        *result = NULL;
4243 4324          char            *filter, *userdata;
4244 4325          char            errstr[MAXERROR];
↓ open down ↓ 1560 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX