Print this page
NEX-13644 File access audit logging
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Reviewed by: Roman Strashkin <roman.strashkin@nexenta.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
SUP-795 IDMAP: idmap_getwinnamebyuid() and idmap_getwinnamebygid() fails for empty domains
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
SUP-642 Regression leading to AD usernames not being displayed by zfs userspace command.

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libidmap/common/idmap_api.c
          +++ new/usr/src/lib/libidmap/common/idmap_api.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright Milan Jurik 2012. All rights reserved.
  24      - * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
       24 + * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  25   25   * Copyright 2015 Joyent, Inc.
  26   26   */
  27   27  
  28   28  
  29   29  /*
  30   30   * libidmap API
  31   31   */
  32   32  
  33   33  #include <stdlib.h>
  34   34  #include <sys/varargs.h>
↓ open down ↓ 1 lines elided ↑ open up ↑
  36   36  #include <errno.h>
  37   37  #include <strings.h>
  38   38  #include <ctype.h>
  39   39  #include <sys/param.h>
  40   40  #include <sys/types.h>
  41   41  #include <sys/stat.h>
  42   42  #include <dlfcn.h>
  43   43  #include <libintl.h>
  44   44  #include <syslog.h>
  45   45  #include <assert.h>
       46 +#include <unistd.h>
       47 +#include <pwd.h>
       48 +#include <grp.h>
       49 +#include <netdb.h>
  46   50  #include "idmap_impl.h"
  47   51  #include "idmap_cache.h"
  48   52  
  49   53  static struct timeval TIMEOUT = { 25, 0 };
  50   54  
  51   55  static int idmap_stat2errno(idmap_stat);
  52   56  static idmap_stat       idmap_strdupnull(char **, const char *);
  53   57  
  54   58  #define __ITER_CREATE(itera, argu, ityp)\
  55   59          itera = calloc(1, sizeof (*itera));\
↓ open down ↓ 2201 lines elided ↑ open up ↑
2257 2261  
2258 2262  /*
2259 2263   * Get winname given gid
2260 2264   */
2261 2265  idmap_stat
2262 2266  idmap_getwinnamebygid(gid_t gid, int flag, char **name, char **domain)
2263 2267  {
2264 2268          return (idmap_getwinnamebypid(gid, 0, flag, name, domain));
2265 2269  }
2266 2270  
     2271 +/*
     2272 + * Get winname given SID
     2273 + */
     2274 +int
     2275 +idmap_getwinnamebysid(char *sid, int flag, char **name)
     2276 +{
     2277 +        uid_t pid;
     2278 +        idmap_get_handle_t *get_hdl = NULL;
     2279 +        idmap_rid_t rid;
     2280 +        idmap_stat stat;
     2281 +        char *ridp = NULL;
     2282 +        char *end;
     2283 +        int is_user = 0;
     2284 +        int rc;
     2285 +
     2286 +        if ((ridp = strrchr(sid, '-')) == NULL)
     2287 +                return (IDMAP_ERR_SID);
     2288 +
     2289 +        *ridp = '\0';
     2290 +
     2291 +        errno = 0;
     2292 +        rid = strtoul(ridp + 1, &end, 10);
     2293 +
     2294 +        if (errno != 0 || *end != '\0')
     2295 +                return (IDMAP_ERR_SID);
     2296 +
     2297 +        rc = idmap_get_create(&get_hdl);
     2298 +        if (rc != IDMAP_SUCCESS)
     2299 +                return (rc);
     2300 +
     2301 +        rc = idmap_get_pidbysid(get_hdl, sid, rid, flag, &pid, &is_user, &stat);
     2302 +        *ridp = '-';
     2303 +
     2304 +        if (rc == IDMAP_SUCCESS)
     2305 +                rc = idmap_get_mappings(get_hdl);
     2306 +
     2307 +        if (rc == IDMAP_SUCCESS && stat != IDMAP_SUCCESS)
     2308 +                rc = stat;
     2309 +
     2310 +        idmap_get_destroy(get_hdl);
     2311 +        get_hdl = NULL;
     2312 +
     2313 +        if (rc == IDMAP_SUCCESS) {
     2314 +                rc = idmap_getwinnamebypid(pid, is_user, flag, name, NULL);
     2315 +
     2316 +                if (rc == IDMAP_ERR_NORESULT && !IDMAP_ID_IS_EPHEMERAL(pid)) {
     2317 +                        /*
     2318 +                         * Unlike LSA, idmap doesn't map a winname for local
     2319 +                         * accounts. Recreate one.
     2320 +                         */
     2321 +                        char buf[1024];
     2322 +                        char hostname[MAXHOSTNAMELEN];
     2323 +                        struct group gr;
     2324 +                        struct passwd pwd;
     2325 +                        char *unixname = NULL;
     2326 +
     2327 +                        if (is_user) {
     2328 +                                if (getpwuid_r(pid, &pwd, buf,
     2329 +                                    sizeof (buf)) != NULL)
     2330 +                                        unixname = pwd.pw_name;
     2331 +                        } else {
     2332 +                                if (getgrgid_r(pid, &gr, buf,
     2333 +                                    sizeof (buf)) != NULL)
     2334 +                                        unixname = gr.gr_name;
     2335 +                        }
     2336 +
     2337 +                        if (unixname == NULL)
     2338 +                                return (rc);
     2339 +
     2340 +                        hostname[0] = '\0';
     2341 +                        if (gethostname(hostname, sizeof (hostname)) == 0)
     2342 +                                hostname[MAXHOSTNAMELEN - 1] = '\0';
     2343 +
     2344 +                        if (asprintf(name, "%s%s%s", unixname,
     2345 +                            (hostname[0] != '\0') ? "@" : "", hostname) >= 0)
     2346 +                                rc = IDMAP_SUCCESS;
     2347 +                }
     2348 +        }
     2349 +
     2350 +        return (rc);
     2351 +}
     2352 +
2267 2353  idmap_stat
2268 2354  idmap_flush(idmap_flush_op op)
2269 2355  {
2270 2356          idmap_retcode           rc1, rc2;
2271 2357  
2272 2358          rc1 = _idmap_clnt_call(IDMAP_FLUSH,
2273 2359              (xdrproc_t)xdr_idmap_flush_op, (caddr_t)&op,
2274 2360              (xdrproc_t)xdr_idmap_retcode, (caddr_t)&rc2, TIMEOUT);
2275 2361  
2276 2362          if (rc1 != IDMAP_SUCCESS)
↓ open down ↓ 135 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX