Print this page
    
NEX-5560 smb2 should use 64-bit server-global uids
Reviewed by: Gordon Ross <gwr@nexenta.com>
NEX-2460 libfksmbd should not link with libsmb
NEX-1638 Updated DC Locator
 Includes work by: matt.barden@nexenta.com, kevin.crowe@nexenta.com
SMB-136 Snapshots not visible in Windows previous versions
re #6854 FindFirstFile,FindFirstFileEx,... are not working correctly on Nexenta CIFS-shares
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/common/smbsrv/smb_xdr.c
          +++ new/usr/src/common/smbsrv/smb_xdr.c
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License (the "License").
   6    6   * You may not use this file except in compliance with the License.
   7    7   *
   8    8   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9    9   * or http://www.opensolaris.org/os/licensing.
  10   10   * See the License for the specific language governing permissions
  11   11   * and limitations under the License.
  12   12   *
  
    | 
      ↓ 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) 2010, Oracle and/or its affiliates. All rights reserved.
  23      - * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
       23 + * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  24   24   */
  25   25  
  26   26  #include <sys/sunddi.h>
  27   27  #if !defined(_KERNEL) && !defined(_FAKE_KERNEL)
  28   28  #include <string.h>
  29   29  #include <strings.h>
  30   30  #include <stddef.h>
  31   31  #endif /* _KERNEL */
  32   32  #include <smbsrv/smb_door.h>
  33   33  #include <smbsrv/alloc.h>
  34   34  #include <sys/socket.h>
  35   35  #include <sys/sysmacros.h>
  36   36  
  37   37  #define SMB_XDRMAX32_SZ         0xFFFFFFFF
  38   38  
  39   39  bool_t smb_list_xdr(XDR *, list_t *,  const size_t, const size_t,
  40   40      const xdrproc_t);
  41   41  
  42   42  bool_t
  43   43  smb_buf32_xdr(XDR *xdrs, smb_buf32_t *objp)
  44   44  {
  45   45          uint_t  maxsize = SMB_XDRMAX32_SZ;
  46   46          uint_t  size;
  47   47  
  48   48          if (xdrs->x_op != XDR_DECODE)
  49   49                  maxsize = size = (uint_t)objp->len;
  50   50  
  51   51          if (xdr_bytes(xdrs, (char **)&objp->val, &size, maxsize)) {
  52   52                  if (xdrs->x_op == XDR_DECODE)
  53   53                          objp->len = (uint32_t)size;
  54   54                  return (TRUE);
  55   55          }
  56   56  
  57   57          return (FALSE);
  58   58  }
  59   59  
  60   60  /*
  61   61   * When decoding into a string, ensure that objp->buf is NULL or
  62   62   * is pointing at a buffer large enough to receive the string.
  63   63   * Don't leave it as an uninitialized pointer.
  64   64   *
  65   65   * If objp->buf is NULL, xdr_string will allocate memory for the
  66   66   * string.  Otherwise it will copy into the available buffer.
  67   67   */
  68   68  bool_t
  69   69  smb_string_xdr(XDR *xdrs, smb_string_t *objp)
  70   70  {
  71   71          if (!xdr_string(xdrs, &objp->buf, ~0))
  72   72                  return (FALSE);
  73   73          return (TRUE);
  74   74  }
  75   75  
  76   76  const char *
  77   77  smb_doorhdr_opname(uint32_t op)
  78   78  {
  79   79          struct {
  80   80                  uint32_t        op;
  81   81                  const char      *name;
  82   82          } ops[] = {
  83   83                  { SMB_DR_NULL,                  "null" },
  84   84                  { SMB_DR_ASYNC_RESPONSE,        "async_response" },
  85   85                  { SMB_DR_USER_AUTH_LOGON,       "user_auth_logon" },
  86   86                  { SMB_DR_USER_NONAUTH_LOGON,    "user_nonauth_logon" },
  87   87                  { SMB_DR_USER_AUTH_LOGOFF,      "user_auth_logoff" },
  88   88                  { SMB_DR_LOOKUP_SID,            "lookup_sid" },
  89   89                  { SMB_DR_LOOKUP_NAME,           "lookup_name" },
  90   90                  { SMB_DR_JOIN,                  "join" },
  91   91                  { SMB_DR_GET_DCINFO,            "get_dcinfo" },
  92   92                  { SMB_DR_VSS_GET_COUNT,         "vss_get_count" },
  93   93                  { SMB_DR_VSS_GET_SNAPSHOTS,     "vss_get_snapshots" },
  94   94                  { SMB_DR_VSS_MAP_GMTTOKEN,      "vss_map_gmttoken" },
  95   95                  { SMB_DR_ADS_FIND_HOST,         "ads_find_host" },
  96   96                  { SMB_DR_QUOTA_QUERY,           "quota_query" },
  97   97                  { SMB_DR_QUOTA_SET,             "quota_set" },
  98   98                  { SMB_DR_DFS_GET_REFERRALS,     "dfs_get_referrals" },
  99   99                  { SMB_DR_SHR_HOSTACCESS,        "share_hostaccess" },
 100  100                  { SMB_DR_SHR_EXEC,              "share_exec" },
 101  101                  { SMB_DR_NOTIFY_DC_CHANGED,     "notify_dc_changed" }
 102  102          };
 103  103          int     i;
 104  104  
 105  105          for (i = 0; i < (sizeof (ops) / sizeof (ops[0])); ++i) {
 106  106                  if (ops[i].op == op)
 107  107                          return (ops[i].name);
 108  108          }
 109  109  
 110  110          return ("unknown");
 111  111  }
 112  112  
 113  113  /*
 114  114   * Encode a door header structure into an XDR buffer.
 115  115   */
 116  116  int
 117  117  smb_doorhdr_encode(smb_doorhdr_t *hdr, uint8_t *buf, uint32_t buflen)
 118  118  {
 119  119          XDR xdrs;
 120  120          int rc = 0;
 121  121  
 122  122          xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_ENCODE);
 123  123  
 124  124          if (!smb_doorhdr_xdr(&xdrs, hdr))
 125  125                  rc = -1;
 126  126  
 127  127          xdr_destroy(&xdrs);
 128  128          return (rc);
 129  129  }
 130  130  
 131  131  /*
 132  132   * Decode an XDR buffer into a door header structure.
 133  133   */
 134  134  int
 135  135  smb_doorhdr_decode(smb_doorhdr_t *hdr, uint8_t *buf, uint32_t buflen)
 136  136  {
 137  137          XDR xdrs;
 138  138          int rc = 0;
 139  139  
 140  140          bzero(hdr, sizeof (smb_doorhdr_t));
 141  141          xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_DECODE);
 142  142  
 143  143          if (!smb_doorhdr_xdr(&xdrs, hdr))
 144  144                  rc = -1;
 145  145  
 146  146          xdr_destroy(&xdrs);
 147  147          return (rc);
 148  148  }
 149  149  
 150  150  bool_t
 151  151  smb_doorhdr_xdr(XDR *xdrs, smb_doorhdr_t *objp)
 152  152  {
 153  153          if (!xdr_uint32_t(xdrs, &objp->dh_magic))
 154  154                  return (FALSE);
 155  155          if (!xdr_uint32_t(xdrs, &objp->dh_flags))
 156  156                  return (FALSE);
 157  157          if (!xdr_uint32_t(xdrs, &objp->dh_fid))
 158  158                  return (FALSE);
 159  159          if (!xdr_uint32_t(xdrs, &objp->dh_op))
 160  160                  return (FALSE);
 161  161          if (!xdr_uint32_t(xdrs, &objp->dh_txid))
 162  162                  return (FALSE);
 163  163          if (!xdr_uint32_t(xdrs, &objp->dh_datalen))
 164  164                  return (FALSE);
 165  165          if (!xdr_uint32_t(xdrs, &objp->dh_resid))
 166  166                  return (FALSE);
 167  167          if (!xdr_uint32_t(xdrs, &objp->dh_door_rc))
 168  168                  return (FALSE);
 169  169          if (!xdr_uint32_t(xdrs, &objp->dh_status))
 170  170                  return (FALSE);
 171  171          return (TRUE);
 172  172  }
 173  173  
 174  174  /*
 175  175   * Encode an smb_netuserinfo_t into a buffer.
 176  176   */
 177  177  int
 178  178  smb_netuserinfo_encode(smb_netuserinfo_t *info, uint8_t *buf,
 179  179      uint32_t buflen, uint_t *nbytes)
 180  180  {
 181  181          XDR xdrs;
 182  182          int rc = 0;
 183  183  
 184  184          xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_ENCODE);
 185  185  
 186  186          if (!smb_netuserinfo_xdr(&xdrs, info))
 187  187                  rc = -1;
 188  188  
 189  189          if (nbytes != NULL)
 190  190                  *nbytes = xdr_getpos(&xdrs);
 191  191          xdr_destroy(&xdrs);
 192  192          return (rc);
 193  193  }
 194  194  
 195  195  /*
 196  196   * Decode an XDR buffer into an smb_netuserinfo_t.
 197  197   */
 198  198  int
 199  199  smb_netuserinfo_decode(smb_netuserinfo_t *info, uint8_t *buf,
 200  200      uint32_t buflen, uint_t *nbytes)
 201  201  {
 202  202          XDR xdrs;
 203  203          int rc = 0;
 204  204  
 205  205          xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_DECODE);
 206  206  
 207  207          bzero(info, sizeof (smb_netuserinfo_t));
 208  208          if (!smb_netuserinfo_xdr(&xdrs, info))
 209  209                  rc = -1;
 210  210  
 211  211          if (nbytes != NULL)
 212  212                  *nbytes = xdr_getpos(&xdrs);
 213  213          xdr_destroy(&xdrs);
 214  214          return (rc);
 215  215  }
 216  216  
 217  217  bool_t
 218  218  smb_inaddr_xdr(XDR *xdrs, smb_inaddr_t *objp)
 219  219  {
 220  220          if (!xdr_int32_t(xdrs, &objp->a_family))
 221  221                  return (FALSE);
 222  222          if (objp->a_family == AF_INET) {
 223  223                  if (!xdr_uint32_t(xdrs, (in_addr_t *)&objp->a_ipv4))
 224  224                          return (FALSE);
 225  225          } else {
 226  226                  if (!xdr_vector(xdrs, (char *)&objp->a_ipv6,
 227  227                      sizeof (objp->a_ipv6), sizeof (char), (xdrproc_t)xdr_char))
 228  228                          return (FALSE);
 229  229          }
 230  230          return (TRUE);
  
    | 
      ↓ open down ↓ | 
    197 lines elided | 
    
      ↑ open up ↑ | 
  
 231  231  }
 232  232  
 233  233  /*
 234  234   * XDR encode/decode for smb_netuserinfo_t.
 235  235   */
 236  236  bool_t
 237  237  smb_netuserinfo_xdr(XDR *xdrs, smb_netuserinfo_t *objp)
 238  238  {
 239  239          if (!xdr_uint64_t(xdrs, &objp->ui_session_id))
 240  240                  return (FALSE);
 241      -        if (!xdr_uint16_t(xdrs, &objp->ui_smb_uid))
 242      -                return (FALSE);
 243  241          if (!xdr_uint16_t(xdrs, &objp->ui_domain_len))
 244  242                  return (FALSE);
 245  243          if (!xdr_string(xdrs, &objp->ui_domain, ~0))
 246  244                  return (FALSE);
 247  245          if (!xdr_uint16_t(xdrs, &objp->ui_account_len))
 248  246                  return (FALSE);
 249  247          if (!xdr_string(xdrs, &objp->ui_account, ~0))
 250  248                  return (FALSE);
 251  249          if (!xdr_uint32_t(xdrs, &objp->ui_posix_uid))
 252  250                  return (FALSE);
 253  251          if (!xdr_uint16_t(xdrs, &objp->ui_workstation_len))
 254  252                  return (FALSE);
 255  253          if (!xdr_string(xdrs, &objp->ui_workstation, ~0))
 256  254                  return (FALSE);
 257  255          if (!smb_inaddr_xdr(xdrs, &objp->ui_ipaddr))
 258  256                  return (FALSE);
 259  257          if (!xdr_int32_t(xdrs, &objp->ui_native_os))
 260  258                  return (FALSE);
 261  259          if (!xdr_int64_t(xdrs, &objp->ui_logon_time))
 262  260                  return (FALSE);
 263  261          if (!xdr_uint32_t(xdrs, &objp->ui_numopens))
 264  262                  return (FALSE);
 265  263          if (!xdr_uint32_t(xdrs, &objp->ui_flags))
 266  264                  return (FALSE);
 267  265          return (TRUE);
 268  266  }
 269  267  
 270  268  /*
 271  269   * Encode an smb_netconnectinfo_t into a buffer.
 272  270   */
 273  271  int
 274  272  smb_netconnectinfo_encode(smb_netconnectinfo_t *info, uint8_t *buf,
 275  273      uint32_t buflen, uint_t *nbytes)
 276  274  {
 277  275          XDR xdrs;
 278  276          int rc = 0;
 279  277  
 280  278          xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_ENCODE);
 281  279  
 282  280          if (!smb_netconnectinfo_xdr(&xdrs, info))
 283  281                  rc = -1;
 284  282  
 285  283          if (nbytes != NULL)
 286  284                  *nbytes = xdr_getpos(&xdrs);
 287  285          xdr_destroy(&xdrs);
 288  286          return (rc);
 289  287  }
 290  288  
 291  289  /*
 292  290   * Decode an XDR buffer into an smb_netconnectinfo_t.
 293  291   */
 294  292  int
 295  293  smb_netconnectinfo_decode(smb_netconnectinfo_t *info, uint8_t *buf,
 296  294      uint32_t buflen, uint_t *nbytes)
 297  295  {
 298  296          XDR xdrs;
 299  297          int rc = 0;
 300  298  
 301  299          xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_DECODE);
 302  300  
 303  301          bzero(info, sizeof (smb_netconnectinfo_t));
 304  302          if (!smb_netconnectinfo_xdr(&xdrs, info))
 305  303                  rc = -1;
 306  304  
 307  305          if (nbytes != NULL)
 308  306                  *nbytes = xdr_getpos(&xdrs);
 309  307          xdr_destroy(&xdrs);
 310  308          return (rc);
 311  309  }
 312  310  
 313  311  /*
 314  312   * XDR encode/decode for smb_netconnectinfo_t.
 315  313   */
 316  314  bool_t
 317  315  smb_netconnectinfo_xdr(XDR *xdrs, smb_netconnectinfo_t *objp)
 318  316  {
 319  317          if (!xdr_uint32_t(xdrs, &objp->ci_id))
 320  318                  return (FALSE);
 321  319          if (!xdr_uint32_t(xdrs, &objp->ci_type))
 322  320                  return (FALSE);
 323  321          if (!xdr_uint32_t(xdrs, &objp->ci_numopens))
 324  322                  return (FALSE);
 325  323          if (!xdr_uint32_t(xdrs, &objp->ci_numusers))
 326  324                  return (FALSE);
 327  325          if (!xdr_uint32_t(xdrs, &objp->ci_time))
 328  326                  return (FALSE);
 329  327          if (!xdr_uint32_t(xdrs, &objp->ci_namelen))
 330  328                  return (FALSE);
 331  329          if (!xdr_uint32_t(xdrs, &objp->ci_sharelen))
 332  330                  return (FALSE);
 333  331          if (!xdr_string(xdrs, &objp->ci_username, MAXNAMELEN))
 334  332                  return (FALSE);
 335  333          if (!xdr_string(xdrs, &objp->ci_share, MAXNAMELEN))
 336  334                  return (FALSE);
 337  335          return (TRUE);
 338  336  }
 339  337  
 340  338  /*
 341  339   * Encode an smb_netfileinfo_t into a buffer.
 342  340   */
 343  341  int
 344  342  smb_netfileinfo_encode(smb_netfileinfo_t *info, uint8_t *buf,
 345  343      uint32_t buflen, uint_t *nbytes)
 346  344  {
 347  345          XDR xdrs;
 348  346          int rc = 0;
 349  347  
 350  348          xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_ENCODE);
 351  349  
 352  350          if (!smb_netfileinfo_xdr(&xdrs, info))
 353  351                  rc = -1;
 354  352  
 355  353          if (nbytes != NULL)
 356  354                  *nbytes = xdr_getpos(&xdrs);
 357  355          xdr_destroy(&xdrs);
 358  356          return (rc);
 359  357  }
 360  358  
 361  359  /*
 362  360   * Decode an XDR buffer into an smb_netfileinfo_t.
 363  361   */
 364  362  int
 365  363  smb_netfileinfo_decode(smb_netfileinfo_t *info, uint8_t *buf,
 366  364      uint32_t buflen, uint_t *nbytes)
 367  365  {
 368  366          XDR xdrs;
 369  367          int rc = 0;
 370  368  
 371  369          xdrmem_create(&xdrs, (const caddr_t)buf, buflen, XDR_DECODE);
 372  370  
 373  371          bzero(info, sizeof (smb_netfileinfo_t));
 374  372          if (!smb_netfileinfo_xdr(&xdrs, info))
 375  373                  rc = -1;
 376  374  
 377  375          if (nbytes != NULL)
 378  376                  *nbytes = xdr_getpos(&xdrs);
 379  377          xdr_destroy(&xdrs);
 380  378          return (rc);
 381  379  }
 382  380  
 383  381  /*
 384  382   * XDR encode/decode for smb_netfileinfo_t.
 385  383   */
 386  384  bool_t
 387  385  smb_netfileinfo_xdr(XDR *xdrs, smb_netfileinfo_t *objp)
 388  386  {
 389  387          if (!xdr_uint16_t(xdrs, &objp->fi_fid))
 390  388                  return (FALSE);
 391  389          if (!xdr_uint32_t(xdrs, &objp->fi_uniqid))
 392  390                  return (FALSE);
 393  391          if (!xdr_uint32_t(xdrs, &objp->fi_permissions))
 394  392                  return (FALSE);
 395  393          if (!xdr_uint32_t(xdrs, &objp->fi_numlocks))
 396  394                  return (FALSE);
 397  395          if (!xdr_uint32_t(xdrs, &objp->fi_pathlen))
 398  396                  return (FALSE);
 399  397          if (!xdr_uint32_t(xdrs, &objp->fi_namelen))
 400  398                  return (FALSE);
 401  399          if (!xdr_string(xdrs, &objp->fi_path, MAXPATHLEN))
 402  400                  return (FALSE);
 403  401          if (!xdr_string(xdrs, &objp->fi_username, MAXNAMELEN))
 404  402                  return (FALSE);
 405  403          return (TRUE);
 406  404  }
 407  405  
 408  406  bool_t
 409  407  smb_gmttoken_query_xdr(XDR *xdrs, smb_gmttoken_query_t *objp)
 410  408  {
 411  409          if (!xdr_uint32_t(xdrs, &objp->gtq_count)) {
 412  410                  return (FALSE);
 413  411          }
 414  412          if (!xdr_string(xdrs, &objp->gtq_path, ~0)) {
 415  413                  return (FALSE);
 416  414          }
 417  415          return (TRUE);
 418  416  }
 419  417  
 420  418  static bool_t
 421  419  smb_gmttoken_xdr(XDR *xdrs, smb_gmttoken_t *objp)
 422  420  {
 423  421          if (!xdr_string(xdrs, objp, SMB_VSS_GMT_SIZE)) {
 424  422                  return (FALSE);
 425  423          }
 426  424          return (TRUE);
 427  425  }
 428  426  
 429  427  bool_t
 430  428  smb_gmttoken_response_xdr(XDR *xdrs, smb_gmttoken_response_t *objp)
 431  429  {
 432  430          if (!xdr_uint32_t(xdrs, &objp->gtr_count)) {
 433  431                  return (FALSE);
 434  432          }
 435  433          if (!xdr_array(xdrs, (char **)&objp->gtr_gmttokens.gtr_gmttokens_val,
 436  434              (uint_t *)&objp->gtr_gmttokens.gtr_gmttokens_len, ~0,
 437  435              sizeof (smb_gmttoken_t), (xdrproc_t)smb_gmttoken_xdr)) {
 438  436                  return (FALSE);
 439  437          }
 440  438          return (TRUE);
 441  439  }
 442  440  
 443  441  bool_t
 444  442  smb_gmttoken_snapname_xdr(XDR *xdrs, smb_gmttoken_snapname_t *objp)
 445  443  {
 446  444          if (!xdr_string(xdrs, &objp->gts_path, MAXPATHLEN)) {
 447  445                  return (FALSE);
 448  446          }
 449  447          if (!xdr_string(xdrs, &objp->gts_gmttoken, SMB_VSS_GMT_SIZE)) {
 450  448                  return (FALSE);
 451  449          }
 452  450          if (!xdr_uint64_t(xdrs, &objp->gts_toktime)) {
 453  451                  return (FALSE);
 454  452          }
 455  453          return (TRUE);
 456  454  }
 457  455  
 458  456  bool_t
 459  457  smb_quota_xdr(XDR *xdrs, smb_quota_t *objp)
 460  458  {
 461  459          if (!xdr_vector(xdrs, (char *)objp->q_sidstr, SMB_SID_STRSZ,
 462  460              sizeof (char), (xdrproc_t)xdr_char))
 463  461                  return (FALSE);
 464  462          if (!xdr_uint32_t(xdrs, &objp->q_sidtype))
 465  463                  return (FALSE);
 466  464          if (!xdr_uint64_t(xdrs, &objp->q_used))
 467  465                  return (FALSE);
 468  466          if (!xdr_uint64_t(xdrs, &objp->q_thresh))
 469  467                  return (FALSE);
 470  468          if (!xdr_uint64_t(xdrs, &objp->q_limit))
 471  469                  return (FALSE);
 472  470  
 473  471          return (TRUE);
 474  472  }
 475  473  
 476  474  bool_t
 477  475  smb_quota_sid_xdr(XDR *xdrs, smb_quota_sid_t *objp)
 478  476  {
 479  477          if (!xdr_vector(xdrs, (char *)objp->qs_sidstr, SMB_SID_STRSZ,
 480  478              sizeof (char), (xdrproc_t)xdr_char))
 481  479                  return (FALSE);
 482  480          return (TRUE);
 483  481  }
 484  482  
 485  483  bool_t
 486  484  smb_quota_query_xdr(XDR *xdrs, smb_quota_query_t *objp)
 487  485  {
 488  486          if (!xdr_string(xdrs, &objp->qq_root_path, ~0))
 489  487                  return (FALSE);
 490  488          if (!xdr_uint32_t(xdrs, &objp->qq_query_op))
 491  489                  return (FALSE);
 492  490          if (!xdr_bool(xdrs, &objp->qq_single))
 493  491                  return (FALSE);
 494  492          if (!xdr_bool(xdrs, &objp->qq_restart))
 495  493                  return (FALSE);
 496  494          if (!xdr_uint32_t(xdrs, &objp->qq_max_quota))
 497  495                  return (FALSE);
 498  496          if (!smb_list_xdr(xdrs, &objp->qq_sid_list,
 499  497              offsetof(smb_quota_sid_t, qs_list_node),
 500  498              sizeof (smb_quota_sid_t), (xdrproc_t)smb_quota_sid_xdr))
 501  499                  return (FALSE);
 502  500  
 503  501          return (TRUE);
 504  502  }
 505  503  
 506  504  bool_t
 507  505  smb_quota_response_xdr(XDR *xdrs, smb_quota_response_t *objp)
 508  506  {
 509  507          if (!xdr_uint32_t(xdrs, &objp->qr_status))
 510  508                  return (FALSE);
 511  509          if (!smb_list_xdr(xdrs, &objp->qr_quota_list,
 512  510              offsetof(smb_quota_t, q_list_node),
 513  511              sizeof (smb_quota_t), (xdrproc_t)smb_quota_xdr))
 514  512                  return (FALSE);
 515  513          return (TRUE);
 516  514  }
 517  515  
 518  516  bool_t
 519  517  smb_quota_set_xdr(XDR *xdrs, smb_quota_set_t *objp)
 520  518  {
 521  519          if (!xdr_string(xdrs, &objp->qs_root_path, ~0))
 522  520                  return (FALSE);
 523  521          if (!smb_list_xdr(xdrs, &objp->qs_quota_list,
 524  522              offsetof(smb_quota_t, q_list_node),
 525  523              sizeof (smb_quota_t), (xdrproc_t)smb_quota_xdr))
 526  524                  return (FALSE);
 527  525          return (TRUE);
 528  526  }
 529  527  
 530  528  /*
 531  529   * XDR a list_t list of elements
 532  530   * offset - offset of list_node_t in list element
 533  531   * elsize - size of list element
 534  532   * elproc - XDR function for the list element
 535  533   */
 536  534  bool_t
 537  535  smb_list_xdr(XDR *xdrs, list_t *list,  const size_t offset,
 538  536      const size_t elsize, const xdrproc_t elproc)
 539  537  {
 540  538          void *node;
 541  539          uint32_t count = 0;
 542  540  
 543  541          switch (xdrs->x_op) {
 544  542          case XDR_ENCODE:
 545  543                  node = list_head(list);
 546  544                  while (node) {
 547  545                          ++count;
 548  546                          node = list_next(list, node);
 549  547                  }
 550  548                  if (!xdr_uint32_t(xdrs, &count))
 551  549                          return (FALSE);
 552  550  
 553  551                  node = list_head(list);
 554  552                  while (node) {
 555  553                          if (!elproc(xdrs, node))
 556  554                                  return (FALSE);
 557  555                          node = list_next(list, node);
 558  556                  }
 559  557                  return (TRUE);
 560  558  
 561  559          case XDR_DECODE:
 562  560                  if (!xdr_uint32_t(xdrs, &count))
 563  561                          return (FALSE);
 564  562                  list_create(list, elsize, offset);
 565  563                  while (count) {
 566  564                          node = MEM_MALLOC("xdr", elsize);
 567  565                          if (node == NULL)
 568  566                                  return (FALSE);
 569  567                          if (!elproc(xdrs, node))
 570  568                                  return (FALSE);
 571  569                          list_insert_tail(list, node);
 572  570                          --count;
 573  571                  }
 574  572                  return (TRUE);
 575  573  
 576  574          case XDR_FREE:
 577  575                  while ((node = list_head(list)) != NULL) {
 578  576                          list_remove(list, node);
 579  577                          (void) elproc(xdrs, node);
 580  578                          MEM_FREE("xdr", node);
 581  579                  }
 582  580                  list_destroy(list);
 583  581                  return (TRUE);
 584  582          }
 585  583  
 586  584          return (FALSE);
 587  585  }
 588  586  
 589  587  bool_t
 590  588  dfs_target_pclass_xdr(XDR *xdrs, dfs_target_pclass_t *objp)
 591  589  {
 592  590          return (xdr_enum(xdrs, (enum_t *)objp));
 593  591  }
 594  592  
 595  593  bool_t
 596  594  dfs_target_priority_xdr(XDR *xdrs, dfs_target_priority_t *objp)
 597  595  {
 598  596          if (!dfs_target_pclass_xdr(xdrs, &objp->p_class))
 599  597                  return (FALSE);
 600  598  
 601  599          if (!xdr_uint16_t(xdrs, &objp->p_rank))
 602  600                  return (FALSE);
 603  601  
 604  602          return (TRUE);
 605  603  }
 606  604  
 607  605  bool_t
 608  606  dfs_target_xdr(XDR *xdrs, dfs_target_t *objp)
 609  607  {
 610  608          if (!xdr_vector(xdrs, (char *)objp->t_server, DFS_SRVNAME_MAX,
 611  609              sizeof (char), (xdrproc_t)xdr_char))
 612  610                  return (FALSE);
 613  611  
 614  612          if (!xdr_vector(xdrs, (char *)objp->t_share, DFS_NAME_MAX,
 615  613              sizeof (char), (xdrproc_t)xdr_char))
 616  614                  return (FALSE);
 617  615  
 618  616          if (!xdr_uint32_t(xdrs, &objp->t_state))
 619  617                  return (FALSE);
 620  618  
 621  619          if (!dfs_target_priority_xdr(xdrs, &objp->t_priority))
 622  620                  return (FALSE);
 623  621  
 624  622          return (TRUE);
 625  623  }
 626  624  
 627  625  bool_t
 628  626  dfs_reftype_xdr(XDR *xdrs, dfs_reftype_t *objp)
 629  627  {
 630  628          return (xdr_enum(xdrs, (enum_t *)objp));
 631  629  }
 632  630  
 633  631  bool_t
 634  632  dfs_info_xdr(XDR *xdrs, dfs_info_t *objp)
 635  633  {
 636  634          if (!xdr_vector(xdrs, (char *)objp->i_uncpath, DFS_PATH_MAX,
 637  635              sizeof (char), (xdrproc_t)xdr_char))
 638  636                  return (FALSE);
 639  637  
 640  638          if (!xdr_vector(xdrs, (char *)objp->i_comment, DFS_COMMENT_MAX,
 641  639              sizeof (char), (xdrproc_t)xdr_char))
 642  640                  return (FALSE);
 643  641  
 644  642          if (!xdr_vector(xdrs, (char *)objp->i_guid,
 645  643              UUID_PRINTABLE_STRING_LENGTH, sizeof (char), (xdrproc_t)xdr_char))
 646  644                  return (FALSE);
 647  645  
 648  646          if (!xdr_uint32_t(xdrs, &objp->i_state))
 649  647                  return (FALSE);
 650  648  
 651  649          if (!xdr_uint32_t(xdrs, &objp->i_timeout))
 652  650                  return (FALSE);
 653  651  
 654  652          if (!xdr_uint32_t(xdrs, &objp->i_propflags))
 655  653                  return (FALSE);
 656  654  
 657  655          if (!xdr_uint32_t(xdrs, &objp->i_type))
 658  656                  return (FALSE);
 659  657  
 660  658          if (!xdr_array(xdrs, (char **)&objp->i_targets,
 661  659              (uint32_t *)&objp->i_ntargets, ~0, sizeof (dfs_target_t),
 662  660              (xdrproc_t)dfs_target_xdr))
 663  661                  return (FALSE);
 664  662  
 665  663          return (TRUE);
 666  664  }
 667  665  
 668  666  bool_t
 669  667  dfs_referral_query_xdr(XDR *xdrs, dfs_referral_query_t *objp)
 670  668  {
 671  669          if (!dfs_reftype_xdr(xdrs, &objp->rq_type))
 672  670                  return (FALSE);
 673  671  
 674  672          if (!xdr_string(xdrs, &objp->rq_path, ~0))
 675  673                  return (FALSE);
 676  674  
 677  675          return (TRUE);
 678  676  }
 679  677  
 680  678  bool_t
 681  679  dfs_referral_response_xdr(XDR *xdrs, dfs_referral_response_t *objp)
 682  680  {
 683  681          if (!dfs_info_xdr(xdrs, &objp->rp_referrals))
 684  682                  return (FALSE);
 685  683  
 686  684          if (!xdr_uint32_t(xdrs, &objp->rp_status))
 687  685                  return (FALSE);
 688  686  
 689  687          return (TRUE);
 690  688  }
 691  689  
 692  690  bool_t
 693  691  smb_shr_hostaccess_query_xdr(XDR *xdrs, smb_shr_hostaccess_query_t *objp)
 694  692  {
 695  693          if (!xdr_string(xdrs, &objp->shq_none, ~0))
 696  694                  return (FALSE);
 697  695  
 698  696          if (!xdr_string(xdrs, &objp->shq_ro, ~0))
 699  697                  return (FALSE);
 700  698  
 701  699          if (!xdr_string(xdrs, &objp->shq_rw, ~0))
 702  700                  return (FALSE);
 703  701  
 704  702          if (!xdr_uint32_t(xdrs, &objp->shq_flag))
 705  703                  return (FALSE);
 706  704  
 707  705          if (!smb_inaddr_xdr(xdrs, &objp->shq_ipaddr))
 708  706                  return (FALSE);
 709  707  
 710  708          return (TRUE);
 711  709  }
 712  710  
 713  711  bool_t
 714  712  smb_shr_execinfo_xdr(XDR *xdrs, smb_shr_execinfo_t *objp)
 715  713  {
 716  714          if (!xdr_string(xdrs, &objp->e_sharename, ~0))
 717  715                  return (FALSE);
 718  716  
 719  717          if (!xdr_string(xdrs, &objp->e_winname, ~0))
 720  718                  return (FALSE);
 721  719  
 722  720          if (!xdr_string(xdrs, &objp->e_userdom, ~0))
 723  721                  return (FALSE);
 724  722  
 725  723          if (!smb_inaddr_xdr(xdrs, &objp->e_srv_ipaddr))
 726  724                  return (FALSE);
 727  725  
 728  726          if (!smb_inaddr_xdr(xdrs, &objp->e_cli_ipaddr))
 729  727                  return (FALSE);
 730  728  
 731  729          if (!xdr_string(xdrs, &objp->e_cli_netbiosname, ~0))
 732  730                  return (FALSE);
 733  731  
 734  732          if (!xdr_u_int(xdrs, &objp->e_uid))
 735  733                  return (FALSE);
 736  734  
 737  735          if (!xdr_int(xdrs, &objp->e_type))
 738  736                  return (FALSE);
 739  737  
 740  738          return (TRUE);
 741  739  }
 742  740  
 743  741  /*
 744  742   * The smbsrv ioctl callers include a CRC of the XDR encoded data,
 745  743   * and kmod ioctl handler checks it.  Both use this function.  This
 746  744   * is not really XDR related, but this is as good a place as any.
 747  745   */
 748  746  #define SMB_CRC_POLYNOMIAL      0xD8B5D8B5
 749  747  uint32_t
 750  748  smb_crc_gen(uint8_t *buf, size_t len)
 751  749  {
 752  750          uint32_t crc = SMB_CRC_POLYNOMIAL;
 753  751          uint8_t *p;
 754  752          int i;
 755  753  
 756  754          for (p = buf, i = 0; i < len; ++i, ++p) {
 757  755                  crc = (crc ^ (uint32_t)*p) + (crc << 12);
 758  756  
 759  757                  if (crc == 0 || crc == 0xFFFFFFFF)
 760  758                          crc = SMB_CRC_POLYNOMIAL;
 761  759          }
 762  760  
 763  761          return (crc);
 764  762  }
  
    | 
      ↓ open down ↓ | 
    512 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX