Print this page
NEX-17589 Get "too high" smbd error when copy big file to cifs share
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
NEX-17795 SMB logon should tolerate idmap problems
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Joyce McIntosh <joyce.mcintosh@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-4083 Upstream changes from illumos 5917 and 5995
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Kevin Crowe <kevin.crowe@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-2461 smb_split_sid uses wrong allocation size

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/smbsrv/libsmb/common/smb_idmap.c
          +++ new/usr/src/lib/smbsrv/libsmb/common/smb_idmap.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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
       23 + * Copyright 2018 Nexenta Systems, Inc.  All rights reserved.
  24   24   */
  25   25  
  26   26  /*
  27   27   * SMB server interface to idmap
  28   28   * (smb_idmap_get..., smb_idmap_batch_...)
  29   29   *
  30      - * There are three implementations of this interface:
  31      - *      uts/common/fs/smbsrv/smb_idmap.c (smbsrv kmod)
  32      - *      lib/smbsrv/libfksmbsrv/common/fksmb_idmap.c (libfksmbsrv)
  33      - *      lib/smbsrv/libsmb/common/smb_idmap.c (libsmb)
       30 + * There are three implementations of this interface.
       31 + * This is the libsmb version of these routines.  See also:
       32 + * $SRC/uts/common/fs/smbsrv/smb_idmap.c
       33 + * $SRC/lib/smbsrv/libfksmbsrv/common/fksmb_idmap.c
  34   34   *
  35   35   * There are enough differences (relative to the code size)
  36   36   * that it's more trouble than it's worth to merge them.
  37   37   *
  38   38   * This one differs from the others in that it:
  39   39   *      calls idmap interfaces (libidmap)
  40   40   *      domain SIDs returned are allocated
  41   41   */
  42   42  
  43   43  #include <syslog.h>
↓ open down ↓ 146 lines elided ↑ open up ↑
 190  190  
 191  191          if (sib->sib_flags & SMB_IDMAP_ID2SID) {
 192  192                  /*
 193  193                   * SIDs are allocated only when mapping
 194  194                   * UID/GID to SIDs
 195  195                   */
 196  196                  for (i = 0; i < sib->sib_nmap; i++) {
 197  197                          smb_sid_free(sib->sib_maps[i].sim_sid);
 198  198                          free(sib->sib_maps[i].sim_domsid);
 199  199                  }
      200 +        } else if (sib->sib_flags & SMB_IDMAP_SID2ID) {
      201 +                /*
      202 +                 * SID prefixes are allocated only when mapping
      203 +                 * SIDs to UID/GID
      204 +                 */
      205 +                for (i = 0; i < sib->sib_nmap; i++) {
      206 +                        free(sib->sib_maps[i].sim_domsid);
      207 +                }
 200  208          }
 201  209  
 202  210          if (sib->sib_size && sib->sib_maps) {
 203  211                  free(sib->sib_maps);
 204  212                  sib->sib_maps = NULL;
 205  213          }
 206  214  }
 207  215  
 208  216  /*
 209  217   * smb_idmap_batch_getid
↓ open down ↓ 13 lines elided ↑ open up ↑
 223  231          char sidstr[SMB_SID_STRSZ];
 224  232          idmap_stat stat;
 225  233          int flag = 0;
 226  234  
 227  235          if (idmaph == NULL || sim == NULL || sid == NULL)
 228  236                  return (IDMAP_ERR_ARG);
 229  237  
 230  238          smb_sid_tostr(sid, sidstr);
 231  239          if (smb_sid_splitstr(sidstr, &sim->sim_rid) != 0)
 232  240                  return (IDMAP_ERR_SID);
 233      -        sim->sim_domsid = sidstr;
      241 +        /* Note: Free sim_domsid in smb_idmap_batch_destroy */
      242 +        sim->sim_domsid = strdup(sidstr);
 234  243          sim->sim_idtype = idtype;
 235  244  
 236  245          switch (idtype) {
 237  246          case SMB_IDMAP_USER:
 238  247                  stat = idmap_get_uidbysid(idmaph, sim->sim_domsid,
 239  248                      sim->sim_rid, flag, sim->sim_id, &sim->sim_stat);
 240  249                  smb_idmap_check("idmap_get_uidbysid", stat);
 241  250                  break;
 242  251  
 243  252          case SMB_IDMAP_GROUP:
↓ open down ↓ 7 lines elided ↑ open up ↑
 251  260                      sim->sim_rid, flag, sim->sim_id, &sim->sim_idtype,
 252  261                      &sim->sim_stat);
 253  262                  smb_idmap_check("idmap_get_pidbysid", stat);
 254  263                  break;
 255  264  
 256  265          default:
 257  266                  stat = IDMAP_ERR_ARG;
 258  267                  break;
 259  268          }
 260  269  
 261      -        /* This was copied by idmap_get_Xbysid. */
 262      -        sim->sim_domsid = NULL;
 263      -
 264  270          return (stat);
 265  271  }
 266  272  
 267  273  /*
 268  274   * smb_idmap_batch_getsid
 269  275   *
 270  276   * Queue a request to map the given UID/GID to a SID.
 271  277   *
 272  278   * sim->sim_domsid and sim->sim_rid will contain the mapping
 273  279   * result upon successful process of the batched request.
      280 + * Stash the type for error reporting (caller saves the ID).
      281 + *
 274  282   * NB: sim_domsid allocated by strdup, here or in libidmap
 275  283   */
 276  284  idmap_stat
 277  285  smb_idmap_batch_getsid(idmap_get_handle_t *idmaph, smb_idmap_t *sim,
 278  286      uid_t id, int idtype)
 279  287  {
 280  288          idmap_stat stat;
 281  289          int flag = 0;
 282  290  
 283  291          if (!idmaph || !sim)
 284  292                  return (IDMAP_ERR_ARG);
 285  293  
      294 +        sim->sim_idtype = idtype;
 286  295          switch (idtype) {
 287  296          case SMB_IDMAP_USER:
 288  297                  stat = idmap_get_sidbyuid(idmaph, id, flag,
 289  298                      &sim->sim_domsid, &sim->sim_rid, &sim->sim_stat);
 290  299                  smb_idmap_check("idmap_get_sidbyuid", stat);
 291  300                  break;
 292  301  
 293  302          case SMB_IDMAP_GROUP:
 294  303                  stat = idmap_get_sidbygid(idmaph, id, flag,
 295  304                      &sim->sim_domsid, &sim->sim_rid, &sim->sim_stat);
↓ open down ↓ 24 lines elided ↑ open up ↑
 320  329                  stat = IDMAP_SUCCESS;
 321  330                  break;
 322  331  
 323  332          default:
 324  333                  return (IDMAP_ERR_ARG);
 325  334          }
 326  335  
 327  336          return (stat);
 328  337  }
 329  338  
      339 +static void
      340 +smb_idmap_bgm_report(smb_idmap_batch_t *sib, smb_idmap_t *sim)
      341 +{
      342 +
      343 +        if ((sib->sib_flags & SMB_IDMAP_ID2SID) != 0) {
      344 +                /*
      345 +                 * Note: The ID and type we asked idmap to map
      346 +                 * were saved in *sim_id and sim_idtype.
      347 +                 */
      348 +                uint_t id = (sim->sim_id == NULL) ?
      349 +                    0 : (uint_t)*sim->sim_id;
      350 +                syslog(LOG_ERR, "Can't get SID for "
      351 +                    "ID=%u type=%d, status=%d",
      352 +                    id, sim->sim_idtype, sim->sim_stat);
      353 +        }
      354 +
      355 +        if ((sib->sib_flags & SMB_IDMAP_SID2ID) != 0) {
      356 +                syslog(LOG_ERR, "Can't get ID for SID %s-%u, status=%d",
      357 +                    sim->sim_domsid, sim->sim_rid, sim->sim_stat);
      358 +        }
      359 +}
      360 +
 330  361  /*
 331  362   * smb_idmap_batch_getmappings
 332  363   *
 333  364   * trigger ID mapping service to get the mappings for queued
 334  365   * requests.
 335  366   *
 336  367   * Checks the result of all the queued requests.
 337  368   */
 338  369  idmap_stat
 339  370  smb_idmap_batch_getmappings(smb_idmap_batch_t *sib)
↓ open down ↓ 5 lines elided ↑ open up ↑
 345  376          if ((stat = idmap_get_mappings(sib->sib_idmaph)) != IDMAP_SUCCESS) {
 346  377                  smb_idmap_check("idmap_get_mappings", stat);
 347  378                  return (stat);
 348  379          }
 349  380  
 350  381          /*
 351  382           * Check the status for all the queued requests
 352  383           */
 353  384          for (i = 0, sim = sib->sib_maps; i < sib->sib_nmap; i++, sim++) {
 354  385                  if (sim->sim_stat != IDMAP_SUCCESS) {
 355      -                        if (sib->sib_flags == SMB_IDMAP_SID2ID) {
 356      -                                smb_tracef("[%d] %d (%d)", sim->sim_idtype,
 357      -                                    sim->sim_rid, sim->sim_stat);
      386 +                        smb_idmap_bgm_report(sib, sim);
      387 +                        if ((sib->sib_flags & SMB_IDMAP_SKIP_ERRS) == 0) {
      388 +                                return (sim->sim_stat);
 358  389                          }
 359      -                        return (sim->sim_stat);
 360  390                  }
 361  391          }
 362  392  
 363  393          if (smb_idmap_batch_binsid(sib) != 0)
 364  394                  stat = IDMAP_ERR_OTHER;
 365  395  
 366  396          return (stat);
 367  397  }
 368  398  
 369  399  /*
↓ open down ↓ 32 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX