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
↓ 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
↓ 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  
↓ open down ↓ 67 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX