Print this page
    
3910 t_look(3NSL) should never return T_ERROR
    
      
        | Split | Close | 
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/rpc/sec/authdesubr.c
          +++ new/usr/src/uts/common/rpc/sec/authdesubr.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, Version 1.0 only
   6    6   * (the "License").  You may not use this file except in compliance
   7    7   * with the License.
   8    8   *
   9    9   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10   10   * or http://www.opensolaris.org/os/licensing.
  11   11   * See the License for the specific language governing permissions
  12   12   * and limitations under the License.
  
    | ↓ open down ↓ | 12 lines elided | ↑ open up ↑ | 
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
       23 + * Copyright 2014 Gary Mills
  23   24   * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
  24   25   * Use is subject to license terms.
  25   26   */
  26   27  
  27   28  /*      Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T     */
  28   29  /*        All Rights Reserved   */
  29   30  
  30   31  /*
  31   32   * Portions of this source code were derived from Berkeley 4.3 BSD
  32   33   * under license from the Regents of the University of California.
  33   34   */
  34   35  
  35      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  36      -
  37   36  /*
  38   37   * Miscellaneous support routines for kernel implentation of AUTH_DES
  39   38   */
  40   39  
  41   40  /*
  42   41   *  rtime - get time from remote machine
  43   42   *
  44   43   *  sets time, obtaining value from host
  45   44   *  on the udp/time socket.  Since timeserver returns
  46   45   *  with time of day in seconds since Jan 1, 1900,  must
  47   46   *  subtract 86400(365*70 + 17) to get time
  48   47   *  since Jan 1, 1970, which is what get/settimeofday
  49   48   *  uses.
  50   49   */
  51   50  #include <sys/param.h>
  52   51  #include <sys/types.h>
  53   52  #include <sys/time.h>
  54   53  #include <sys/systm.h>
  55   54  #include <sys/errno.h>
  56   55  #include <sys/proc.h>
  57   56  #include <sys/user.h>
  58   57  #include <sys/socket.h>
  59   58  #include <sys/sysmacros.h>
  60   59  #include <netinet/in.h>
  61   60  #include <rpc/rpc.h>
  62   61  #include <sys/stream.h>
  63   62  #include <sys/strsubr.h>
  64   63  #include <sys/cred.h>
  65   64  #include <sys/utsname.h>
  66   65  #include <sys/vnode.h>
  67   66  #include <sys/file.h>
  68   67  #include <sys/uio.h>
  69   68  #include <sys/systeminfo.h>
  70   69  #include <rpc/rpcb_prot.h>
  71   70  #include <sys/cmn_err.h>
  72   71  
  73   72  #define TOFFSET ((uint32_t)86400 * (365 * 70 + (70 / 4)))
  74   73  #define WRITTEN ((uint32_t)86400 * (365 * 86 + (86 / 4)))
  75   74  
  76   75  #define NC_INET "inet"          /* XXX */
  77   76  
  78   77  int
  79   78  rtime(struct knetconfig *synconfig, struct netbuf *addrp, int calltype,
  80   79          struct timeval *timep, struct timeval *wait)
  81   80  {
  82   81          int                     error;
  83   82          int                     timo;
  84   83          time_t                  thetime;
  85   84          int32_t                 srvtime;
  86   85          uint32_t                dummy;
  87   86          struct t_kunitdata      *unitdata;
  88   87          struct t_call           *server;
  89   88          TIUSER                  *tiptr;
  90   89          int                     type;
  91   90          int                     uderr;
  92   91          int                     i;
  93   92          int                     retries;
  94   93          mblk_t                  *mp;
  95   94          mblk_t                  *mp2;
  96   95  
  97   96          retries = 5;
  98   97          if (calltype == 0) {
  99   98  again:
 100   99                  RPCLOG0(8, "rtime: using old method\n");
 101  100                  if ((error = t_kopen(NULL, synconfig->knc_rdev,
 102  101                      FREAD|FWRITE, &tiptr, CRED())) != 0) {
 103  102                          RPCLOG(1, "rtime: t_kopen %d\n", error);
  
    | ↓ open down ↓ | 57 lines elided | ↑ open up ↑ | 
 104  103                          return (-1);
 105  104                  }
 106  105  
 107  106                  if ((error = t_kbind(tiptr, NULL, NULL)) != 0) {
 108  107                          (void) t_kclose(tiptr, 1);
 109  108                          RPCLOG(1, "rtime: t_kbind %d\n", error);
 110  109                          return (-1);
 111  110                  }
 112  111  
 113  112                  if (synconfig->knc_semantics == NC_TPI_CLTS) {
 114      -                    if ((error = t_kalloc(tiptr, T_UNITDATA, T_UDATA|T_ADDR,
 115      -                        (char **)&unitdata)) != 0) {
 116      -                            RPCLOG(1, "rtime: t_kalloc %d\n", error);
 117      -                            (void) t_kclose(tiptr, 1);
 118      -                            return (-1);
 119      -                    }
      113 +                        if ((error = t_kalloc(tiptr, T_UNITDATA,
      114 +                            T_UDATA|T_ADDR, (char **)&unitdata)) != 0) {
      115 +                                RPCLOG(1, "rtime: t_kalloc %d\n", error);
      116 +                                (void) t_kclose(tiptr, 1);
      117 +                                return (-1);
      118 +                        }
 120  119  
 121      -                    unitdata->addr.len = addrp->len;
 122      -                    bcopy(addrp->buf, unitdata->addr.buf, unitdata->addr.len);
      120 +                        unitdata->addr.len = addrp->len;
      121 +                        bcopy(addrp->buf, unitdata->addr.buf,
      122 +                            unitdata->addr.len);
 123  123  
 124      -                    dummy = 0;
 125      -                    unitdata->udata.buf = (caddr_t)&dummy;
 126      -                    unitdata->udata.len = sizeof (dummy);
      124 +                        dummy = 0;
      125 +                        unitdata->udata.buf = (caddr_t)&dummy;
      126 +                        unitdata->udata.len = sizeof (dummy);
 127  127  
 128      -                    if ((error = t_ksndudata(tiptr, unitdata, NULL)) != 0) {
 129      -                            RPCLOG(1, "rtime: t_ksndudata %d\n", error);
 130      -                            (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
 131      -                            (void) t_kclose(tiptr, 1);
 132      -                            return (-1);
 133      -                    }
      128 +                        if ((error = t_ksndudata(tiptr, unitdata, NULL)) !=
      129 +                            0) {
      130 +                                RPCLOG(1, "rtime: t_ksndudata %d\n", error);
      131 +                                (void) t_kfree(tiptr, (char *)unitdata,
      132 +                                    T_UNITDATA);
      133 +                                (void) t_kclose(tiptr, 1);
      134 +                                return (-1);
      135 +                        }
 134  136  
 135      -                    timo = TIMEVAL_TO_TICK(wait);
      137 +                        timo = TIMEVAL_TO_TICK(wait);
 136  138  
 137      -                    RPCLOG(8, "rtime: timo %x\n", timo);
 138      -                    if ((error = t_kspoll(tiptr, timo, READWAIT, &type)) != 0) {
 139      -                            RPCLOG(1, "rtime: t_kspoll %d\n", error);
 140      -                            (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
 141      -                            (void) t_kclose(tiptr, 1);
 142      -                            return (-1);
 143      -                    }
      139 +                        RPCLOG(8, "rtime: timo %x\n", timo);
      140 +                        if ((error = t_kspoll(tiptr, timo, READWAIT,
      141 +                            &type)) != 0) {
      142 +                                RPCLOG(1, "rtime: t_kspoll %d\n", error);
      143 +                                (void) t_kfree(tiptr, (char *)unitdata,
      144 +                                    T_UNITDATA);
      145 +                                (void) t_kclose(tiptr, 1);
      146 +                                return (-1);
      147 +                        }
 144  148  
 145      -                    if (type == 0) {
 146      -                            RPCLOG0(1, "rtime: t_kspoll timed out\n");
 147      -                            (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
 148      -                            (void) t_kclose(tiptr, 1);
 149      -                            return (-1);
 150      -                    }
      149 +                        if (type == 0) {
      150 +                                RPCLOG0(1, "rtime: t_kspoll timed out\n");
      151 +                                (void) t_kfree(tiptr, (char *)unitdata,
      152 +                                    T_UNITDATA);
      153 +                                (void) t_kclose(tiptr, 1);
      154 +                                return (-1);
      155 +                        }
 151  156  
 152      -                    error = t_krcvudata(tiptr, unitdata, &type, &uderr);
 153      -                    if (error != 0) {
 154      -                            RPCLOG(1, "rtime: t_krcvudata %d\n", error);
 155      -                            (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
 156      -                            (void) t_kclose(tiptr, 1);
 157      -                            return (-1);
 158      -                    }
      157 +                        error = t_krcvudata(tiptr, unitdata, &type, &uderr);
      158 +                        if (error != 0) {
      159 +                                RPCLOG(1, "rtime: t_krcvudata %d\n", error);
      160 +                                (void) t_kfree(tiptr, (char *)unitdata,
      161 +                                    T_UNITDATA);
      162 +                                (void) t_kclose(tiptr, 1);
      163 +                                if (error == EBADMSG && retries-- > 0)
      164 +                                        goto again;
      165 +                                return (-1);
      166 +                        }
 159  167  
 160      -                    if (type == T_UDERR) {
 161      -                            if (bcmp(addrp->buf, unitdata->addr.buf,
 162      -                                unitdata->addr.len) != 0) {
      168 +                        if (type == T_UDERR) {
      169 +                                if (bcmp(addrp->buf, unitdata->addr.buf,
      170 +                                    unitdata->addr.len) != 0) {
 163  171                                  /*
 164  172                                   * Response comes from some other
 165  173                                   * destination:
 166  174                                   * ignore it since it's not related to the
 167  175                                   * request we just sent out.
 168  176                                   */
 169      -                                    (void) t_kfree(tiptr, (char *)unitdata,
 170      -                                        T_UNITDATA);
 171      -                                    (void) t_kclose(tiptr, 1);
 172      -                                    goto again;
 173      -                            }
 174      -                    }
      177 +                                        (void) t_kfree(tiptr, (char *)unitdata,
      178 +                                            T_UNITDATA);
      179 +                                        (void) t_kclose(tiptr, 1);
      180 +                                        goto again;
      181 +                                }
      182 +                        }
 175  183  
 176      -                    if (type != T_DATA) {
 177      -                            RPCLOG(1, "rtime: t_krcvudata returned type %d\n",
 178      -                                type);
 179      -                            (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
 180      -                            (void) t_kclose(tiptr, 1);
 181      -                            if (retries-- == 0)
 182      -                                    return (-1);
 183      -                            goto again;
 184      -                    }
      184 +                        if (type != T_DATA) {
      185 +                                RPCLOG(1,
      186 +                                    "rtime: t_krcvudata returned type %d\n",
      187 +                                    type);
      188 +                                (void) t_kfree(tiptr, (char *)unitdata,
      189 +                                    T_UNITDATA);
      190 +                                (void) t_kclose(tiptr, 1);
      191 +                                if (retries-- == 0)
      192 +                                        return (-1);
      193 +                                goto again;
      194 +                        }
 185  195  
 186      -                    if (unitdata->udata.len < sizeof (uint32_t)) {
 187      -                            RPCLOG(1, "rtime: bad rcvd length %d\n",
 188      -                                unitdata->udata.len);
 189      -                            (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
 190      -                            (void) t_kclose(tiptr, 1);
 191      -                            if (retries-- == 0)
 192      -                                    return (-1);
 193      -                            goto again;
 194      -                    }
      196 +                        if (unitdata->udata.len < sizeof (uint32_t)) {
      197 +                                RPCLOG(1, "rtime: bad rcvd length %d\n",
      198 +                                    unitdata->udata.len);
      199 +                                (void) t_kfree(tiptr, (char *)unitdata,
      200 +                                    T_UNITDATA);
      201 +                                (void) t_kclose(tiptr, 1);
      202 +                                if (retries-- == 0)
      203 +                                        return (-1);
      204 +                                goto again;
      205 +                        }
 195  206  
 196      -                    /* LINTED pointer alignment */
 197      -                    thetime = (time_t)ntohl(*(uint32_t *)unitdata->udata.buf);
 198      -                    (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
      207 +                        thetime = (time_t)ntohl(
      208 +                            /* LINTED pointer alignment */
      209 +                            *(uint32_t *)unitdata->udata.buf);
      210 +                        (void) t_kfree(tiptr, (char *)unitdata, T_UNITDATA);
 199  211  
 200  212                  } else {
 201  213  
 202      -                    if ((error = t_kalloc(tiptr, T_CALL, T_ADDR,
 203      -                        (char **)&server)) != 0) {
 204      -                            RPCLOG(1, "rtime: t_kalloc %d\n", error);
 205      -                            (void) t_kclose(tiptr, 1);
 206      -                            return (-1);
 207      -                    }
 208      -
 209      -                    server->addr.len = addrp->len;
 210      -                    bcopy(addrp->buf, server->addr.buf, server->addr.len);
 211      -
 212      -                    if ((error = t_kconnect(tiptr, server, NULL)) != 0) {
 213      -                            RPCLOG(1, "rtime: t_kconnect %d\n", error);
 214      -                            (void) t_kfree(tiptr, (char *)server, T_CALL);
 215      -                            (void) t_kclose(tiptr, 1);
 216      -                            return (-1);
 217      -                    }
 218      -                    (void) t_kfree(tiptr, (char *)server, T_CALL);
 219      -
 220      -                    timo = TIMEVAL_TO_TICK(wait);
 221      -
 222      -                    RPCLOG(8, "rtime: timo %x\n", timo);
 223      -
 224      -                    i = 0;
 225      -                    dummy = 0;
 226      -
 227      -                    /* now read up to 4 bytes from the TIME server */
 228      -                    while (i < sizeof (dummy)) {
 229      -
 230      -                        error = t_kspoll(tiptr, timo, READWAIT, &type);
 231      -                        if (error != 0) {
 232      -                                RPCLOG(1, "rtime: t_kspoll %d\n", error);
      214 +                        if ((error = t_kalloc(tiptr, T_CALL, T_ADDR,
      215 +                            (char **)&server)) != 0) {
      216 +                                RPCLOG(1, "rtime: t_kalloc %d\n", error);
 233  217                                  (void) t_kclose(tiptr, 1);
 234  218                                  return (-1);
 235  219                          }
 236  220  
 237      -                        if (type == 0) {
 238      -                                RPCLOG0(1, "rtime: t_kspoll timed out\n");
 239      -                                (void) t_kclose(tiptr, 1);
 240      -                                return (-1);
 241      -                        }
      221 +                        server->addr.len = addrp->len;
      222 +                        bcopy(addrp->buf, server->addr.buf, server->addr.len);
 242  223  
 243      -                        error = tli_recv(tiptr, &mp, tiptr->fp->f_flag);
 244      -                        if (error != 0) {
 245      -                                RPCLOG(1, "rtime: tli_recv %d\n", error);
      224 +                        if ((error = t_kconnect(tiptr, server, NULL)) != 0) {
      225 +                                RPCLOG(1, "rtime: t_kconnect %d\n", error);
      226 +                                (void) t_kfree(tiptr, (char *)server, T_CALL);
 246  227                                  (void) t_kclose(tiptr, 1);
 247  228                                  return (-1);
 248  229                          }
      230 +                        (void) t_kfree(tiptr, (char *)server, T_CALL);
 249  231  
 250      -                        if (mp->b_datap->db_type != M_DATA) {
 251      -                                RPCLOG(1, "rtime: wrong msg type %d\n",
 252      -                                        mp->b_datap->db_type);
 253      -                                RPCLOG(1, "rtime: wrong msg type: read %d"
 254      -                                        " bytes\n", i);
 255      -                                (void) t_kclose(tiptr, 1);
 256      -                                freemsg(mp);
 257      -                                return (-1);
 258      -                        }
      232 +                        timo = TIMEVAL_TO_TICK(wait);
 259  233  
 260      -                        mp2 = mp;
      234 +                        RPCLOG(8, "rtime: timo %x\n", timo);
 261  235  
 262      -                        /*
 263      -                         * The outer loop iterates until we reach the end of
 264      -                         * the mblk chain.
 265      -                         */
 266      -                        while (mp2 != NULL) {
      236 +                        i = 0;
      237 +                        dummy = 0;
 267  238  
      239 +                        /* now read up to 4 bytes from the TIME server */
      240 +                        while (i < sizeof (dummy)) {
      241 +
      242 +                                error = t_kspoll(tiptr, timo, READWAIT, &type);
      243 +                                if (error != 0) {
      244 +                                        RPCLOG(1, "rtime: t_kspoll %d\n",
      245 +                                            error);
      246 +                                        (void) t_kclose(tiptr, 1);
      247 +                                        return (-1);
      248 +                                }
      249 +
      250 +                                if (type == 0) {
      251 +                                        RPCLOG0(1,
      252 +                                            "rtime: t_kspoll timed out\n");
      253 +                                        (void) t_kclose(tiptr, 1);
      254 +                                        return (-1);
      255 +                                }
      256 +
      257 +                                error = tli_recv(tiptr, &mp,
      258 +                                    tiptr->fp->f_flag);
      259 +                                if (error != 0) {
      260 +                                        RPCLOG(1, "rtime: tli_recv %d\n",
      261 +                                            error);
      262 +                                        (void) t_kclose(tiptr, 1);
      263 +                                        return (-1);
      264 +                                }
      265 +
      266 +                                if (mp->b_datap->db_type != M_DATA) {
      267 +                                        RPCLOG(1, "rtime: wrong msg type %d\n",
      268 +                                            mp->b_datap->db_type);
      269 +                                        RPCLOG(1,
      270 +                                            "rtime: wrong msg type: read %d"
      271 +                                            " bytes\n", i);
      272 +                                        (void) t_kclose(tiptr, 1);
      273 +                                        freemsg(mp);
      274 +                                        return (-1);
      275 +                                }
      276 +
      277 +                                mp2 = mp;
      278 +
 268  279                                  /*
 269      -                                 * The inner loop iterates until we've gotten
 270      -                                 * 4 bytes or until the mblk is exhausted.
      280 +                                 * The outer loop iterates until we reach the
      281 +                                 * end of the mblk chain.
 271  282                                   */
 272      -                                while (i < sizeof (dummy) &&
 273      -                                    mp2->b_rptr < mp2->b_wptr) {
      283 +                                while (mp2 != NULL) {
 274  284  
 275      -                                        i++;
      285 +                                        /*
      286 +                                         * The inner loop iterates until
      287 +                                         * we've gotten 4 bytes or until
      288 +                                         * the mblk is exhausted.
      289 +                                         */
      290 +                                        while (i < sizeof (dummy) &&
      291 +                                            mp2->b_rptr < mp2->b_wptr) {
 276  292  
      293 +                                                i++;
      294 +
 277  295                                          /*
 278  296                                           * We avoid big-endian/little-endian
 279  297                                           * issues by serializing the result
 280  298                                           * one byte at a time.
 281  299                                           */
 282      -                                        dummy <<= 8;
 283      -                                        dummy += ((*mp2->b_rptr) & 0xFF);
      300 +                                                dummy <<= 8;
      301 +                                                dummy += ((*mp2->b_rptr) &
      302 +                                                    0xFF);
 284  303  
 285      -                                        mp2->b_rptr++;
      304 +                                                mp2->b_rptr++;
      305 +                                        }
      306 +
      307 +                                        mp2 = mp2->b_cont;
 286  308                                  }
 287  309  
 288      -                                mp2 = mp2->b_cont;
      310 +                        freemsg(mp);
 289  311                          }
 290  312  
 291      -                        freemsg(mp);
 292      -                    }
 293      -
 294      -                    thetime = (time_t)dummy;
      313 +                        thetime = (time_t)dummy;
 295  314                  }
 296  315  
 297  316                  (void) t_kclose(tiptr, 1);
 298  317  
 299  318          } else {
 300  319                  CLIENT                  *client;
 301  320                  struct timeval          timout;
 302  321  
 303  322                  RPCLOG0(8, "rtime: using new method\n");
 304  323  
 305  324  new_again:
 306  325                  /*
 307  326                   *      We talk to rpcbind.
 308  327                   */
 309  328                  error = clnt_tli_kcreate(synconfig, addrp, (rpcprog_t)RPCBPROG,
 310  329                      (rpcvers_t)RPCBVERS, 0, retries, CRED(), &client);
 311  330  
 312  331                  if (error != 0) {
 313  332                          RPCLOG(1,
 314  333                              "rtime: clnt_tli_kcreate returned %d\n", error);
 315  334                          return (-1);
 316  335                  }
 317  336                  timout.tv_sec = 60;
 318  337                  timout.tv_usec = 0;
 319  338                  error = clnt_call(client, RPCBPROC_GETTIME, (xdrproc_t)xdr_void,
 320  339                      NULL, (xdrproc_t)xdr_u_int,
 321  340                      (caddr_t)&srvtime, timout);
 322  341                  thetime = srvtime;
 323  342                  auth_destroy(client->cl_auth);
 324  343                  clnt_destroy(client);
 325  344                  if (error == RPC_UDERROR) {
 326  345                          if (retries-- > 0)
 327  346                                  goto new_again;
 328  347                  }
 329  348                  if (error != RPC_SUCCESS) {
 330  349                          RPCLOG(1, "rtime: time sync clnt_call returned %d\n",
 331  350                              error);
 332  351                          error = EIO;
 333  352                          return (-1);
 334  353                  }
 335  354          }
 336  355  
 337  356          if (calltype != 0)
 338  357                  thetime += TOFFSET;
 339  358  
 340  359          RPCLOG(8, "rtime: thetime = %lx\n", thetime);
 341  360  
 342  361          if (thetime < WRITTEN) {
 343  362                  RPCLOG(1, "rtime: time returned is too far in past %lx",
 344  363                      thetime);
 345  364                  RPCLOG(1, "rtime: WRITTEN %x", WRITTEN);
 346  365                  return (-1);
 347  366          }
 348  367          thetime -= TOFFSET;
 349  368  
 350  369          timep->tv_sec = thetime;
 351  370          RPCLOG(8, "rtime: timep->tv_sec = %lx\n", timep->tv_sec);
 352  371          RPCLOG(8, "rtime: machine time  = %lx\n", gethrestime_sec());
 353  372          timep->tv_usec = 0;
 354  373          RPCLOG0(8, "rtime: returning success\n");
 355  374          return (0);
 356  375  }
 357  376  
 358  377  /*
 359  378   * What is my network name?
 360  379   * WARNING: this gets the network name in sun unix format.
 361  380   * Other operating systems (non-unix) are free to put something else
 362  381   * here.
 363  382   *
 364  383   * Return 0 on success
 365  384   * Return RPC errors (non-zero values) if failed.
 366  385   */
 367  386  enum clnt_stat
 368  387  kgetnetname(char *netname)
 369  388  {
 370  389          return (key_getnetname(netname, CRED()));
 371  390  }
  
    | ↓ open down ↓ | 67 lines elided | ↑ open up ↑ | 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX