Print this page
*** NO COMMENTS ***

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/fs.d/nfs/mount/mount.c
          +++ new/usr/src/cmd/fs.d/nfs/mount/mount.c
↓ open down ↓ 117 lines elided ↑ open up ↑
 118  118  
 119  119  #define BIGRETRY        10000
 120  120  
 121  121  /* maximum length of RPC header for NFS messages */
 122  122  #define NFS_RPC_HDR     432
 123  123  
 124  124  #define NFS_ARGS_EXTB_secdata(args, secdata) \
 125  125          { (args)->nfs_args_ext = NFS_ARGS_EXTB, \
 126  126          (args)->nfs_ext_u.nfs_extB.secdata = secdata; }
 127  127  
 128      -extern int __clnt_bindresvport();
      128 +extern int __clnt_bindresvport(CLIENT *);
 129  129  extern char *nfs_get_qop_name();
 130  130  extern AUTH * nfs_create_ah();
 131  131  extern enum snego_stat nfs_sec_nego();
 132  132  
 133  133  static void usage(void);
 134  134  static int retry(struct mnttab *, int);
 135  135  static int set_args(int *, struct nfs_args *, char *, struct mnttab *);
 136  136  static int get_fh_via_pub(struct nfs_args *, char *, char *, bool_t, bool_t,
 137  137          int *, struct netconfig **, ushort_t);
 138  138  static int get_fh(struct nfs_args *, char *, char *, int *, bool_t,
↓ open down ↓ 174 lines elided ↑ open up ↑
 313  313                  (void) setpflags(NET_MAC_AWARE, 1);
 314  314  
 315  315          /*
 316  316           * Read the defaults file to see if the min/max versions have
 317  317           * been set and therefore would override the encoded defaults.
 318  318           * Then check to make sure that if they were set that the
 319  319           * values are reasonable.
 320  320           */
 321  321          read_default();
 322  322          if (vers_min_default > vers_max_default ||
 323      -                vers_min_default < NFS_VERSMIN ||
 324      -                vers_max_default > NFS_VERSMAX) {
      323 +            vers_min_default < NFS_VERSMIN ||
      324 +            vers_max_default > NFS_VERSMAX) {
 325  325                  pr_err("%s %s\n%s %s\n",
 326      -                        gettext("Incorrect configuration of client\'s"),
 327      -                        NFSADMIN,
 328      -                        gettext("NFS_CLIENT_VERSMIN or NFS_CLIENT_VERSMAX"),
 329      -                        gettext("is either out of range or overlaps."));
      326 +                    gettext("Incorrect configuration of client\'s"),
      327 +                    NFSADMIN,
      328 +                    gettext("NFS_CLIENT_VERSMIN or NFS_CLIENT_VERSMAX"),
      329 +                    gettext("is either out of range or overlaps."));
 330  330          }
 331  331  
 332  332          SET_ERR_RET(&retry_error, ERR_PROTO_NONE, 0);
 333  333          r = mount_nfs(&mnt, ro, &retry_error);
 334  334          if (r == RET_RETRY && retries) {
 335  335                  /*
 336  336                   * Check the error code from the last mount attempt if it was
 337  337                   * an RPC error, then retry as is. Otherwise we retry with the
 338  338                   * nfsretry_vers set. It is set by decrementing nfsvers_to_use.
 339  339                   * If we are retrying with nfsretry_vers then we don't print any
↓ open down ↓ 135 lines elided ↑ open up ↑
 475  475                                      "illegal nfs url syntax\n"));
 476  476                                  last_error = RET_ERR;
 477  477                                  goto out;
 478  478                          }
 479  479  
 480  480                          *path = '\0';
 481  481                          if (*host == '[') {
 482  482                                  cb = strchr(host, ']');
 483  483                                  if (cb == NULL) {
 484  484                                          pr_err(gettext(
 485      -                                                "illegal nfs url syntax\n"));
      485 +                                            "illegal nfs url syntax\n"));
 486  486                                          last_error = RET_ERR;
 487  487                                          goto out;
 488  488                                  } else {
 489  489                                          *cb = '\0';
 490  490                                          host++;
 491  491                                          cb++;
 492  492                                          if (*cb == ':')
 493  493                                                  port = htons((ushort_t)
 494      -                                                        atoi(cb+1));
      494 +                                                    atoi(cb+1));
 495  495                                  }
 496  496                          } else {
 497  497                                  sport = strchr(host, ':');
 498  498  
 499  499                                  if (sport != NULL && sport < path) {
 500  500                                          *sport = '\0';
 501  501                                          port = htons((ushort_t)atoi(sport+1));
 502  502                                  }
 503  503                          }
 504  504  
↓ open down ↓ 22 lines elided ↑ open up ↑
 527  527                              " as port (%u) in port option\n"),
 528  528                              (unsigned int)ntohs(port),
 529  529                              (unsigned int)ntohs(nfs_port));
 530  530                          last_error = RET_ERR;
 531  531                          goto out;
 532  532                  }
 533  533  
 534  534  
 535  535                  if (replicated && !(mntflags & MS_RDONLY)) {
 536  536                          pr_err(gettext(
 537      -                                "replicated mounts must be read-only\n"));
      537 +                            "replicated mounts must be read-only\n"));
 538  538                          last_error = RET_ERR;
 539  539                          goto out;
 540  540                  }
 541  541  
 542  542                  if (replicated && (argp->flags & NFSMNT_SOFT)) {
 543  543                          pr_err(gettext(
 544      -                                "replicated mounts must not be soft\n"));
      544 +                            "replicated mounts must not be soft\n"));
 545  545                          last_error = RET_ERR;
 546  546                          goto out;
 547  547                  }
 548  548  
 549  549                  oldvers = vers;
 550  550                  nconf = NULL;
 551  551  
 552  552                  r = RET_ERR;
 553  553  
 554  554                  /*
 555  555                   * If -o public was specified, and/or a URL was specified,
 556  556                   * then try the public file handle method.
 557  557                   */
 558  558                  if ((use_pubfh == TRUE) || (url == TRUE)) {
 559  559                          r = get_fh_via_pub(argp, host, path, url, use_pubfh,
 560      -                                &vers, &nconf, port);
      560 +                            &vers, &nconf, port);
 561  561  
 562  562                          if (r != RET_OK) {
 563  563                                  /*
 564  564                                   * If -o public was specified, then return the
 565  565                                   * error now.
 566  566                                   */
 567  567                                  if (use_pubfh == TRUE) {
 568  568                                          last_error = r;
 569  569                                          goto out;
 570  570                                  }
↓ open down ↓ 19 lines elided ↑ open up ↑
 590  590                           * a leading / then there is good possibility
 591  591                           * that a mount without a leading slash will
 592  592                           * fail.
 593  593                           */
 594  594                          if (url == TRUE && *path != '/')
 595  595                                  loud_on_mnt_err = FALSE;
 596  596                          else
 597  597                                  loud_on_mnt_err = TRUE;
 598  598  
 599  599                          r = get_fh(argp, host, path, &vers,
 600      -                                loud_on_mnt_err, &nconf, port);
      600 +                            loud_on_mnt_err, &nconf, port);
 601  601  
 602  602                          if (r != RET_OK) {
 603  603  
 604  604                                  /*
 605  605                                   * If there was no leading / and the path was
 606  606                                   * derived from a URL, then try again
 607  607                                   * with a leading /.
 608  608                                   */
 609  609                                  if ((r == RET_MNTERR) &&
 610  610                                      (loud_on_mnt_err == FALSE)) {
↓ open down ↓ 4 lines elided ↑ open up ↑
 615  615                                                  pr_err(gettext("memory "
 616  616                                                      "allocation failure\n"));
 617  617                                                  last_error = RET_ERR;
 618  618                                                  goto out;
 619  619                                          }
 620  620  
 621  621                                          strcpy(newpath, "/");
 622  622                                          strcat(newpath, path);
 623  623  
 624  624                                          r = get_fh(argp, host, newpath, &vers,
 625      -                                                TRUE, &nconf, port);
      625 +                                            TRUE, &nconf, port);
 626  626  
 627  627                                          if (r == RET_OK)
 628  628                                                  path = newpath;
 629  629                                  }
 630  630  
 631  631                                  /*
 632  632                                   * map exit code back to RET_ERR.
 633  633                                   */
 634  634                                  if (r == RET_MNTERR)
 635  635                                          r = RET_ERR;
↓ open down ↓ 26 lines elided ↑ open up ↑
 662  662                   * decide whether to use remote host's
 663  663                   * lockd or do local locking
 664  664                   */
 665  665                  if (!(argp->flags & NFSMNT_LLOCK) && vers == NFS_VERSION &&
 666  666                      remote_lock(host, argp->fh)) {
 667  667                          (void) fprintf(stderr, gettext(
 668  668                              "WARNING: No network locking on %s:%s:"),
 669  669                              host, path);
 670  670                          (void) fprintf(stderr, gettext(
 671  671                              " contact admin to install server change\n"));
 672      -                                argp->flags |= NFSMNT_LLOCK;
      672 +                        argp->flags |= NFSMNT_LLOCK;
 673  673                  }
 674  674  
 675  675                  if (self_check(host))
 676  676                          argp->flags |= NFSMNT_LOOPBACK;
 677  677  
 678  678                  if (use_pubfh == FALSE) {
 679  679                          /*
 680  680                           * Call to get_fh() above may have obtained the
 681  681                           * netconfig info and NULL proc'd the server.
 682  682                           * This would be the case with v4
 683  683                           */
 684  684                          if (!(argp->flags & NFSMNT_KNCONF)) {
 685  685                                  nconf = NULL;
 686  686                                  if (r = getaddr_nfs(argp, host, &nconf,
 687      -                                        FALSE, path, port, retry_error,
 688      -                                        TRUE)) {
 689      -                                                last_error = r;
 690      -                                                goto out;
      687 +                                    FALSE, path, port, retry_error,
      688 +                                    TRUE)) {
      689 +                                        last_error = r;
      690 +                                        goto out;
 691  691                                  }
 692  692                          }
 693  693                  }
 694  694  
 695  695                  if (make_secure(argp, host, nconf, use_pubfh, vers) < 0) {
 696  696                          last_error = RET_ERR;
 697  697                          goto out;
 698  698                  }
 699  699  
 700  700                  if ((url == TRUE) && (use_pubfh == FALSE)) {
↓ open down ↓ 53 lines elided ↑ open up ↑
 754  754  
 755  755          mntflags |= MS_DATA | MS_OPTIONSTR;
 756  756  
 757  757          if (mflg)
 758  758                  mntflags |= MS_NOMNTTAB;
 759  759  
 760  760          if (!qflg)
 761  761                  saveopts = strdup(mntp->mnt_mntopts);
 762  762  
 763  763          if (mount(mntp->mnt_special, mntp->mnt_mountp, mntflags, fstype, args,
 764      -                sizeof (*args), mntp->mnt_mntopts, MAX_MNTOPT_STR) < 0) {
      764 +            sizeof (*args), mntp->mnt_mntopts, MAX_MNTOPT_STR) < 0) {
 765  765                  if (errno != ENOENT) {
 766  766                          pr_err(gettext("mount: %s: %s\n"),
 767      -                                mntp->mnt_mountp, strerror(errno));
      767 +                            mntp->mnt_mountp, strerror(errno));
 768  768                  } else {
 769  769                          struct stat sb;
 770  770                          if (stat(mntp->mnt_mountp, &sb) < 0 && errno == ENOENT)
 771  771                                  pr_err(gettext("mount: %s: %s\n"),
 772      -                                        mntp->mnt_mountp, strerror(ENOENT));
      772 +                                    mntp->mnt_mountp, strerror(ENOENT));
 773  773                          else
 774  774                                  pr_err("%s: %s\n", mntp->mnt_special,
 775      -                                        strerror(ENOENT));
      775 +                                    strerror(ENOENT));
 776  776                  }
 777  777  
 778  778                  last_error = RET_ERR;
 779  779                  goto out;
 780  780          }
 781  781  
 782  782          if (!qflg && saveopts != NULL) {
 783  783                  cmp_requested_to_actual_options(saveopts, mntp->mnt_mntopts,
 784  784                      mntp->mnt_special, mntp->mnt_mountp);
 785  785          }
↓ open down ↓ 234 lines elided ↑ open up ↑
1020 1020                          args->flags |= NFSMNT_NOAC;
1021 1021                          break;
1022 1022                  case OPT_PORT:
1023 1023                          if (bad(val))
1024 1024                                  goto badopt;
1025 1025                          nfs_port = htons((ushort_t)atoi(val));
1026 1026                          break;
1027 1027  
1028 1028                  case OPT_SECURE:
1029 1029                          if (nfs_getseconfig_byname("dh", &nfs_sec)) {
1030      -                            pr_err(gettext("can not get \"dh\" from %s\n"),
1031      -                                                NFSSEC_CONF);
1032      -                            goto badopt;
     1030 +                                pr_err(gettext("can not get \"dh\" from %s\n"),
     1031 +                                    NFSSEC_CONF);
     1032 +                                goto badopt;
1033 1033                          }
1034 1034                          sec_opt++;
1035 1035                          break;
1036 1036  
1037 1037                  case OPT_NOCTO:
1038 1038                          args->flags |= NFSMNT_NOCTO;
1039 1039                          break;
1040 1040  
1041 1041                  case OPT_RSIZE:
1042 1042                          args->flags |= NFSMNT_RSIZE;
↓ open down ↓ 20 lines elided ↑ open up ↑
1063 1063                          args->retrans = atoi(val);
1064 1064                          break;
1065 1065                  case OPT_ACTIMEO:
1066 1066                          args->flags |= NFSMNT_ACDIRMAX;
1067 1067                          args->flags |= NFSMNT_ACREGMAX;
1068 1068                          args->flags |= NFSMNT_ACDIRMIN;
1069 1069                          args->flags |= NFSMNT_ACREGMIN;
1070 1070                          if (bad(val))
1071 1071                                  goto badopt;
1072 1072                          args->acdirmin = args->acregmin = args->acdirmax
1073      -                                = args->acregmax = atoi(val);
     1073 +                            = args->acregmax = atoi(val);
1074 1074                          break;
1075 1075                  case OPT_ACREGMIN:
1076 1076                          args->flags |= NFSMNT_ACREGMIN;
1077 1077                          if (bad(val))
1078 1078                                  goto badopt;
1079 1079                          args->acregmin = atoi(val);
1080 1080                          break;
1081 1081                  case OPT_ACREGMAX:
1082 1082                          args->flags |= NFSMNT_ACREGMAX;
1083 1083                          if (bad(val))
↓ open down ↓ 52 lines elided ↑ open up ↑
1136 1136                  case OPT_LARGEFILES:
1137 1137                          largefiles = 1;
1138 1138                          break;
1139 1139                  case OPT_NOLARGEFILES:
1140 1140                          pr_err(gettext("NFS can't support \"nolargefiles\"\n"));
1141 1141                          free(optstr);
1142 1142                          return (RET_ERR);
1143 1143  
1144 1144                  case OPT_SEC:
1145 1145                          if (nfs_getseconfig_byname(val, &nfs_sec)) {
1146      -                            pr_err(gettext("can not get \"%s\" from %s\n"),
1147      -                                                val, NFSSEC_CONF);
1148      -                            return (RET_ERR);
     1146 +                                pr_err(gettext("can not get \"%s\" from %s\n"),
     1147 +                                    val, NFSSEC_CONF);
     1148 +                                return (RET_ERR);
1149 1149                          }
1150 1150                          sec_opt++;
1151 1151                          break;
1152 1152  
1153 1153                  case OPT_PUBLIC:
1154 1154                          public_opt = TRUE;
1155 1155                          break;
1156 1156  
1157 1157                  case OPT_DIRECTIO:
1158 1158                          args->flags |= NFSMNT_DIRECTIO;
↓ open down ↓ 85 lines elided ↑ open up ↑
1244 1244           */
1245 1245          if (!snego_done && !sec_opt) {
1246 1246                  /*
1247 1247                   *  Get default security mode.
1248 1248                   *  AUTH_UNIX has been the default choice for a long time.
1249 1249                   *  The better NFS security service becomes, the better chance
1250 1250                   *  we will set stronger security service as the default NFS
1251 1251                   *  security mode.
1252 1252                   *
1253 1253                   */
1254      -            if (nfs_getseconfig_default(&nfs_sec)) {
1255      -                pr_err(gettext("error getting default security entry\n"));
1256      -                return (-1);
1257      -            }
1258      -            args->flags |= NFSMNT_SECDEFAULT;
     1254 +                if (nfs_getseconfig_default(&nfs_sec)) {
     1255 +                        pr_err(gettext("error getting default"
     1256 +                            " security entry\n"));
     1257 +                        return (-1);
     1258 +                }
     1259 +                args->flags |= NFSMNT_SECDEFAULT;
1259 1260          }
1260 1261  
1261 1262          /*
1262 1263           * Get the network address for the time service on the server.
1263 1264           * If an RPC based time service is not available then try the
1264 1265           * IP time service.
1265 1266           *
1266 1267           * This is for AUTH_DH processing. We will also pass down syncaddr
1267 1268           * and netname for NFS V4 even if AUTH_DH is not requested right now.
1268 1269           * NFS V4 does security negotiation in the kernel via SECINFO.
↓ open down ↓ 6 lines elided ↑ open up ↑
1275 1276          flags = 0;
1276 1277          syncaddr = NULL;
1277 1278  
1278 1279          if (nfs_sec.sc_rpcnum == AUTH_DH || vers == NFS_V4) {
1279 1280                  /*
1280 1281                   * If using the public fh or nfsv4, we will not contact the
1281 1282                   * remote RPCBINDer, since it is possibly behind a firewall.
1282 1283                   */
1283 1284                  if (use_pubfh == FALSE && vers != NFS_V4) {
1284 1285                          syncaddr = get_the_addr(hostname, RPCBPROG, RPCBVERS,
1285      -                                nconf, 0, NULL, NULL, FALSE, NULL, NULL);
     1286 +                            nconf, 0, NULL, NULL, FALSE, NULL, NULL);
1286 1287                  }
1287 1288  
1288 1289                  if (syncaddr != NULL) {
1289 1290                          /* for flags in sec_data */
1290 1291                          flags |= AUTH_F_RPCTIMESYNC;
1291 1292                  } else {
1292 1293                          struct nd_hostserv hs;
1293 1294                          int error;
1294 1295  
1295 1296                          hs.h_host = hostname;
1296 1297                          hs.h_serv = "timserver";
1297 1298  
1298 1299                          error = netdir_getbyname(nconf, &hs, &retaddrs);
1299 1300  
1300 1301                          if (error != ND_OK && (nfs_sec.sc_rpcnum == AUTH_DH)) {
1301      -                            pr_err(gettext("%s: secure: no time service\n"),
1302      -                                                hostname);
1303      -                            return (-1);
     1302 +                                pr_err(gettext("%s: secure: no time service\n"),
     1303 +                                    hostname);
     1304 +                                return (-1);
1304 1305                          }
1305 1306  
1306 1307                          if (error == ND_OK)
1307 1308                                  syncaddr = retaddrs->n_addrs;
1308 1309  
1309 1310                          /*
1310 1311                           * For NFS_V4 if AUTH_DH is negotiated later in the
1311 1312                           * kernel thru SECINFO, it will need syncaddr
1312 1313                           * and netname data.
1313 1314                           */
1314 1315                          if (vers == NFS_V4 && syncaddr &&
1315      -                                    host2netname(netname, hostname, NULL)) {
1316      -                            args->syncaddr = malloc(sizeof (struct netbuf));
1317      -                            args->syncaddr->buf = malloc(syncaddr->len);
1318      -                            (void) memcpy(args->syncaddr->buf, syncaddr->buf,
1319      -                                                        syncaddr->len);
1320      -                            args->syncaddr->len = syncaddr->len;
1321      -                            args->syncaddr->maxlen = syncaddr->maxlen;
1322      -                            args->netname = strdup(netname);
1323      -                            args->flags |= NFSMNT_SECURE;
     1316 +                            host2netname(netname, hostname, NULL)) {
     1317 +                                args->syncaddr = malloc(sizeof (struct netbuf));
     1318 +                                args->syncaddr->buf = malloc(syncaddr->len);
     1319 +                                (void) memcpy(args->syncaddr->buf,
     1320 +                                    syncaddr->buf, syncaddr->len);
     1321 +                                args->syncaddr->len = syncaddr->len;
     1322 +                                args->syncaddr->maxlen = syncaddr->maxlen;
     1323 +                                args->netname = strdup(netname);
     1324 +                                args->flags |= NFSMNT_SECURE;
1324 1325                          }
1325 1326                  }
1326 1327          }
1327 1328  
1328 1329          /*
1329 1330           * For the initial chosen flavor (any flavor defined in nfssec.conf),
1330 1331           * the data will be stored in the sec_data structure via
1331 1332           * nfs_clnt_secdata() and be passed to the kernel via nfs_args_*
1332 1333           * extended data structure.
1333 1334           */
1334 1335          if (!(secdata = nfs_clnt_secdata(&nfs_sec, hostname, args->knconf,
1335      -                                        syncaddr, flags))) {
     1336 +            syncaddr, flags))) {
1336 1337                  pr_err(gettext("errors constructing security related data\n"));
1337 1338                  if (flags & AUTH_F_RPCTIMESYNC) {
1338 1339                          free(syncaddr->buf);
1339 1340                          free(syncaddr);
1340 1341                  } else if (retaddrs)
1341 1342                          netdir_free((void *)retaddrs, ND_ADDRLIST);
1342 1343                  return (-1);
1343 1344          }
1344 1345  
1345 1346          NFS_ARGS_EXTB_secdata(args, secdata);
↓ open down ↓ 29 lines elided ↑ open up ↑
1375 1376          struct timeval tv;
1376 1377          int fd = -1;
1377 1378          AUTH *ah = NULL;
1378 1379          AUTH *new_ah = NULL;
1379 1380          struct snego_t snego;
1380 1381  
1381 1382          if (nconf == NULL)
1382 1383                  return (NULL);
1383 1384  
1384 1385          if ((fd = t_open(nconf->nc_device, O_RDWR, tinfo)) == -1)
1385      -                    goto done;
     1386 +                goto done;
1386 1387  
1387 1388          /* LINTED pointer alignment */
1388 1389          if ((tbind = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR))
1389      -                == NULL)
     1390 +            == NULL)
1390 1391                  goto done;
1391 1392  
1392 1393          /*
1393 1394           * In the case of public filehandle usage or NFSv4 we want to
1394 1395           * avoid use of the rpcbind/portmap protocol
1395 1396           */
1396 1397          if ((get_pubfh == TRUE) || (vers == NFS_V4)) {
1397 1398                  struct nd_hostserv hs;
1398 1399                  struct nd_addrlist *retaddrs;
1399 1400                  int retval;
1400 1401                  hs.h_host = hostname;
1401 1402  
1402 1403                  /* NFS where vers==4 does not support UDP */
1403 1404                  if (vers == NFS_V4 &&
1404 1405                      strncasecmp(nconf->nc_proto, NC_UDP,
1405      -                                strlen(NC_UDP)) == 0) {
     1406 +                    strlen(NC_UDP)) == 0) {
1406 1407                          SET_ERR_RET(error, ERR_PROTO_UNSUPP, 0);
1407 1408                          goto done;
1408 1409                  }
1409 1410  
1410 1411                  if (port == 0)
1411 1412                          hs.h_serv = "nfs";
1412 1413                  else
1413 1414                          hs.h_serv = NULL;
1414 1415  
1415 1416                  if ((retval = netdir_getbyname(nconf, &hs, &retaddrs))
↓ open down ↓ 2 lines elided ↑ open up ↑
1418 1419                           * Carefully set the error value here. Want to signify
1419 1420                           * that the error was an unknown host.
1420 1421                           */
1421 1422                          if (retval == ND_NOHOST) {
1422 1423                                  SET_ERR_RET(error, ERR_NOHOST, retval);
1423 1424                          }
1424 1425  
1425 1426                          goto done;
1426 1427                  }
1427 1428                  memcpy(tbind->addr.buf, retaddrs->n_addrs->buf,
1428      -                        retaddrs->n_addrs->len);
     1429 +                    retaddrs->n_addrs->len);
1429 1430                  tbind->addr.len = retaddrs->n_addrs->len;
1430 1431                  netdir_free((void *)retaddrs, ND_ADDRLIST);
1431 1432                  (void) netdir_options(nconf, ND_SET_RESERVEDPORT, fd, NULL);
1432 1433  
1433 1434          } else {
1434 1435                  if (rpcb_getaddr(prog, vers, nconf, &tbind->addr,
1435 1436                      hostname) == FALSE) {
1436 1437                          goto done;
1437 1438                  }
1438 1439          }
1439 1440  
1440 1441          if (port) {
1441 1442                  /* LINTED pointer alignment */
1442 1443                  if (strcmp(nconf->nc_protofmly, NC_INET) == 0)
1443 1444                          ((struct sockaddr_in *)tbind->addr.buf)->sin_port
1444      -                                = port;
     1445 +                            = port;
1445 1446                  else if (strcmp(nconf->nc_protofmly, NC_INET6) == 0)
1446 1447                          ((struct sockaddr_in6 *)tbind->addr.buf)->sin6_port
1447      -                                = port;
1448      -
     1448 +                            = port;
1449 1449          }
1450 1450  
1451 1451          cl = clnt_tli_create(fd, nconf, &tbind->addr, prog, vers, 0, 0);
1452 1452          if (cl == NULL) {
1453 1453                  /*
1454 1454                   * clnt_tli_create() returns either RPC_SYSTEMERROR,
1455 1455                   * RPC_UNKNOWNPROTO or RPC_TLIERROR. The RPC_TLIERROR translates
1456 1456                   * to "Misc. TLI error". This is not too helpful. Most likely
1457 1457                   * the connection to the remote server timed out, so this
1458 1458                   * error is at least less perplexing.
↓ open down ↓ 10 lines elided ↑ open up ↑
1469 1469          ah = authsys_create_default();
1470 1470          if (ah != NULL)
1471 1471                  cl->cl_auth = ah;
1472 1472  
1473 1473          tv.tv_sec = 5;
1474 1474          tv.tv_usec = 0;
1475 1475  
1476 1476          (void) clnt_control(cl, CLSET_TIMEOUT, (char *)&tv);
1477 1477  
1478 1478          if ((get_pubfh == TRUE) && (vers != NFS_V4)) {
1479      -            enum snego_stat sec;
     1479 +                enum snego_stat sec;
1480 1480  
1481      -            if (!snego_done) {
1482      -                /*
1483      -                 * negotiate sec flavor.
1484      -                 */
1485      -                snego.cnt = 0;
1486      -                if ((sec = nfs_sec_nego(vers, cl, fspath, &snego)) ==
1487      -                        SNEGO_SUCCESS) {
1488      -                    int jj;
     1481 +                if (!snego_done) {
     1482 +                        /*
     1483 +                         * negotiate sec flavor.
     1484 +                         */
     1485 +                        snego.cnt = 0;
     1486 +                        if ((sec = nfs_sec_nego(vers, cl,
     1487 +                            fspath, &snego)) == SNEGO_SUCCESS) {
     1488 +                                int jj;
1489 1489  
1490      -                /*
1491      -                 * check if server supports the one
1492      -                 * specified in the sec= option.
1493      -                 */
1494      -                    if (sec_opt) {
1495      -                        for (jj = 0; jj < snego.cnt; jj++) {
1496      -                            if (snego.array[jj] == nfs_sec.sc_nfsnum) {
1497      -                                snego_done = TRUE;
1498      -                                break;
1499      -                            }
1500      -                        }
1501      -                    }
1502      -
1503      -                /*
1504      -                 * find a common sec flavor
1505      -                 */
1506      -                    if (!snego_done) {
1507      -                        if (sec_opt) {
1508      -                            pr_err(gettext(
1509      -                                "Server does not support the security"
1510      -                                " flavor specified.\n"));
1511      -                        }
1512      -                        for (jj = 0; jj < snego.cnt; jj++) {
1513      -                            if (!nfs_getseconfig_bynumber(snego.array[jj],
1514      -                                &nfs_sec)) {
1515      -                                snego_done = TRUE;
     1490 +                                /*
     1491 +                                 * check if server supports the one
     1492 +                                 * specified in the sec= option.
     1493 +                                 */
1516 1494                                  if (sec_opt) {
1517      -                                    pr_err(gettext(
1518      -                                        "Security flavor %d was negotiated and"
1519      -                                        " will be used.\n"),
1520      -                                        nfs_sec.sc_nfsnum);
     1495 +                                        for (jj = 0; jj < snego.cnt; jj++) {
     1496 +                                                if (snego.array[jj] ==
     1497 +                                                    nfs_sec.sc_nfsnum) {
     1498 +                                                        snego_done = TRUE;
     1499 +                                                        break;
     1500 +                                                }
     1501 +                                        }
1521 1502                                  }
1522      -                                break;
1523      -                            }
     1503 +
     1504 +                                /*
     1505 +                                 * find a common sec flavor
     1506 +                                 */
     1507 +                                if (!snego_done) {
     1508 +                                        if (sec_opt) {
     1509 +                                                pr_err(gettext(
     1510 +                                                    "Server does not support"
     1511 +                                                    " the security"
     1512 +                                                    " flavor specified.\n"));
     1513 +                                        }
     1514 +
     1515 +                                        for (jj = 0; jj < snego.cnt; jj++) {
     1516 +                                                if (!nfs_getseconfig_bynumber(
     1517 +                                                    snego.array[jj],
     1518 +                                                    &nfs_sec)) {
     1519 +                                                        snego_done = TRUE;
     1520 +                                                        if (sec_opt) {
     1521 +                                                                pr_err(gettext(
     1522 +                "Security flavor %d was negotiated and will be used.\n"),
     1523 +                                                                    nfs_sec.
     1524 +                                                                    sc_nfsnum);
     1525 +                                                        }
     1526 +
     1527 +                                                        break;
     1528 +                                                }
     1529 +                                        }
     1530 +
     1531 +                                        if (!snego_done)
     1532 +                                                return (NULL);
     1533 +                                }
     1534 +
     1535 +                                /*
     1536 +                                 * Now that the flavor has been
     1537 +                                 * negotiated, get the fh.
     1538 +                                 *
     1539 +                                 * First, create an auth handle using
     1540 +                                 * the negotiated sec flavor in the
     1541 +                                 * next lookup to fetch the filehandle.
     1542 +                                 */
     1543 +                                new_ah = nfs_create_ah(cl, hostname, &nfs_sec);
     1544 +                                if (new_ah == NULL)
     1545 +                                        goto done;
     1546 +                                cl->cl_auth = new_ah;
     1547 +                        } else if (sec == SNEGO_ARRAY_TOO_SMALL || sec ==
     1548 +                            SNEGO_FAILURE) {
     1549 +                                goto done;
1524 1550                          }
1525      -                    }
1526      -                    if (!snego_done)
1527      -                        return (NULL);
1528 1551  
1529      -                /*
1530      -                 * Now that the flavor has been
1531      -                 * negotiated, get the fh.
1532      -                 *
1533      -                 * First, create an auth handle using the negotiated
1534      -                 * sec flavor in the next lookup to
1535      -                 * fetch the filehandle.
1536      -                 */
1537      -                    new_ah = nfs_create_ah(cl, hostname, &nfs_sec);
1538      -                    if (new_ah == NULL)
1539      -                        goto done;
1540      -                    cl->cl_auth = new_ah;
1541      -                } else if (sec == SNEGO_ARRAY_TOO_SMALL || sec ==
1542      -                    SNEGO_FAILURE) {
1543      -                        goto done;
     1552 +                        /*
     1553 +                         * Note that if sec == SNEGO_DEF_VALID
     1554 +                         * default sec flavor is acceptable.
     1555 +                         * Use it to get the filehandle.
     1556 +                         */
1544 1557                  }
1545      -                /*
1546      -                 * Note that if sec == SNEGO_DEF_VALID
1547      -                 * default sec flavor is acceptable.
1548      -                 * Use it to get the filehandle.
1549      -                 */
1550      -            }
1551 1558  
1552      -            if (vers == NFS_VERSION) {
1553      -                wnl_diropargs arg;
1554      -                wnl_diropres *res;
     1559 +                if (vers == NFS_VERSION) {
     1560 +                        wnl_diropargs arg;
     1561 +                        wnl_diropres *res;
1555 1562  
1556      -                memset((char *)&arg.dir, 0, sizeof (wnl_fh));
1557      -                arg.name = fspath;
1558      -                res = wnlproc_lookup_2(&arg, cl);
     1563 +                        memset((char *)&arg.dir, 0, sizeof (wnl_fh));
     1564 +                        arg.name = fspath;
     1565 +                        res = wnlproc_lookup_2(&arg, cl);
1559 1566  
1560      -                if (res == NULL || res->status != NFS_OK)
1561      -                    goto done;
1562      -                *fhp = malloc(sizeof (wnl_fh));
     1567 +                        if (res == NULL || res->status != NFS_OK)
     1568 +                                goto done;
     1569 +                        *fhp = malloc(sizeof (wnl_fh));
1563 1570  
1564      -                if (*fhp == NULL) {
1565      -                    pr_err(gettext("no memory\n"));
1566      -                    goto done;
1567      -                }
     1571 +                        if (*fhp == NULL) {
     1572 +                                pr_err(gettext("no memory\n"));
     1573 +                                goto done;
     1574 +                        }
1568 1575  
1569      -                memcpy((char *)*fhp,
1570      -                    (char *)&res->wnl_diropres_u.wnl_diropres.file,
1571      -                    sizeof (wnl_fh));
1572      -            } else {
1573      -                WNL_LOOKUP3args arg;
1574      -                WNL_LOOKUP3res *res;
1575      -                nfs_fh3 *fh3p;
     1576 +                        memcpy((char *)*fhp,
     1577 +                            (char *)&res->wnl_diropres_u.wnl_diropres.file,
     1578 +                            sizeof (wnl_fh));
     1579 +                } else {
     1580 +                        WNL_LOOKUP3args arg;
     1581 +                        WNL_LOOKUP3res *res;
     1582 +                        nfs_fh3 *fh3p;
1576 1583  
1577      -                memset((char *)&arg.what.dir, 0, sizeof (wnl_fh3));
1578      -                arg.what.name = fspath;
1579      -                res = wnlproc3_lookup_3(&arg, cl);
     1584 +                        memset((char *)&arg.what.dir, 0, sizeof (wnl_fh3));
     1585 +                        arg.what.name = fspath;
     1586 +                        res = wnlproc3_lookup_3(&arg, cl);
1580 1587  
1581      -                if (res == NULL || res->status != NFS3_OK)
1582      -                    goto done;
     1588 +                        if (res == NULL || res->status != NFS3_OK)
     1589 +                                goto done;
1583 1590  
1584      -                fh3p = (nfs_fh3 *)malloc(sizeof (*fh3p));
     1591 +                        fh3p = (nfs_fh3 *)malloc(sizeof (*fh3p));
1585 1592  
1586      -                if (fh3p == NULL) {
1587      -                    pr_err(gettext("no memory\n"));
1588      -                    CLNT_FREERES(cl, xdr_WNL_LOOKUP3res, (char *)res);
1589      -                    goto done;
1590      -                }
     1593 +                        if (fh3p == NULL) {
     1594 +                                pr_err(gettext("no memory\n"));
     1595 +                                CLNT_FREERES(cl, xdr_WNL_LOOKUP3res,
     1596 +                                    (char *)res);
     1597 +                                goto done;
     1598 +                        }
1591 1599  
1592      -                fh3p->fh3_length =
1593      -                    res->WNL_LOOKUP3res_u.res_ok.object.data.data_len;
1594      -                memcpy(fh3p->fh3_u.data,
1595      -                    res->WNL_LOOKUP3res_u.res_ok.object.data.data_val,
1596      -                    fh3p->fh3_length);
     1600 +                        fh3p->fh3_length =
     1601 +                            res->WNL_LOOKUP3res_u.res_ok.object.data.data_len;
     1602 +                        memcpy(fh3p->fh3_u.data,
     1603 +                            res->WNL_LOOKUP3res_u.res_ok.object.data.data_val,
     1604 +                            fh3p->fh3_length);
1597 1605  
1598      -                *fhp = (caddr_t)fh3p;
     1606 +                        *fhp = (caddr_t)fh3p;
1599 1607  
1600      -                CLNT_FREERES(cl, xdr_WNL_LOOKUP3res, (char *)res);
1601      -            }
     1608 +                        CLNT_FREERES(cl, xdr_WNL_LOOKUP3res, (char *)res);
     1609 +                }
1602 1610          } else {
1603 1611                  void *res;
1604 1612                  struct rpc_err r_err;
1605 1613  
1606 1614                  if (vers == NFS_VERSION)
1607      -                    res = wnlproc_null_2(NULL, cl);
     1615 +                        res = wnlproc_null_2(NULL, cl);
1608 1616                  else if (vers == NFS_V3)
1609      -                    res = wnlproc3_null_3(NULL, cl);
     1617 +                        res = wnlproc3_null_3(NULL, cl);
1610 1618                  else
1611      -                    res = wnlproc4_null_4(NULL, cl);
     1619 +                        res = wnlproc4_null_4(NULL, cl);
1612 1620  
1613 1621                  if (res == NULL) {
1614 1622                          clnt_geterr(cl, &r_err);
1615 1623                          if (strcmp(nconf->nc_protofmly, NC_LOOPBACK) == 0) {
1616 1624                                  switch (r_err.re_status) {
1617 1625                                  case RPC_TLIERROR:
1618 1626                                  case RPC_CANTRECV:
1619 1627                                  case RPC_CANTSEND:
1620 1628                                          r_err.re_status = RPC_PROGVERSMISMATCH;
1621 1629                                  }
↓ open down ↓ 16 lines elided ↑ open up ↑
1638 1646          if (nb->buf == NULL) {
1639 1647                  pr_err(gettext("no memory\n"));
1640 1648                  free(nb);
1641 1649                  nb = NULL;
1642 1650                  goto done;
1643 1651          }
1644 1652          (void) memcpy(nb->buf, tbind->addr.buf, tbind->addr.len);
1645 1653  
1646 1654  done:
1647 1655          if (cl) {
1648      -            if (ah != NULL) {
1649      -                if (new_ah != NULL)
1650      -                    AUTH_DESTROY(ah);
1651      -                AUTH_DESTROY(cl->cl_auth);
1652      -                cl->cl_auth = NULL;
1653      -            }
1654      -            clnt_destroy(cl);
1655      -            cl = NULL;
     1656 +                if (ah != NULL) {
     1657 +                        if (new_ah != NULL)
     1658 +                                AUTH_DESTROY(ah);
     1659 +                                AUTH_DESTROY(cl->cl_auth);
     1660 +                                cl->cl_auth = NULL;
     1661 +                        }
     1662 +                clnt_destroy(cl);
     1663 +                cl = NULL;
1656 1664          }
1657 1665          if (tbind) {
1658 1666                  t_free((char *)tbind, T_BIND);
1659 1667                  tbind = NULL;
1660 1668          }
1661 1669          if (fd >= 0)
1662 1670                  (void) t_close(fd);
1663 1671          return (nb);
1664 1672  }
1665 1673  
↓ open down ↓ 31 lines elided ↑ open up ↑
1697 1705          int nthtry = FIRST_TRY;
1698 1706          err_ret_t errsave_nohost, errsave_rpcerr;
1699 1707  
1700 1708          SET_ERR_RET(&errsave_nohost, ERR_PROTO_NONE, 0);
1701 1709          SET_ERR_RET(&errsave_rpcerr, ERR_PROTO_NONE, 0);
1702 1710  
1703 1711          SET_ERR_RET(error, ERR_PROTO_NONE, 0);
1704 1712  
1705 1713          if (nconfp && *nconfp)
1706 1714                  return (get_the_addr(hostname, prog, vers, *nconfp, port,
1707      -                        tinfo, fhp, get_pubfh, fspath, error));
     1715 +                    tinfo, fhp, get_pubfh, fspath, error));
1708 1716          /*
1709 1717           * No nconf passed in.
1710 1718           *
1711 1719           * Try to get a nconf from /etc/netconfig filtered by
1712 1720           * the NETPATH environment variable.
1713 1721           * First search for COTS, second for CLTS unless proto
1714 1722           * is specified.  When we retry, we reset the
1715 1723           * netconfig list so that we would search the whole list
1716 1724           * all over again.
1717 1725           */
↓ open down ↓ 14 lines elided ↑ open up ↑
1732 1740                  SET_ERR_RET(error, ERR_PROTO_INVALID, 0);
1733 1741  
1734 1742                  while (nconf = getnetpath(nc)) {
1735 1743                          if (strcmp(nconf->nc_netid, proto))
1736 1744                                  continue;
1737 1745  
1738 1746                          /* may be unsupported */
1739 1747                          SET_ERR_RET(error, ERR_PROTO_UNSUPP, 0);
1740 1748  
1741 1749                          if ((port != 0) &&
1742      -                                ((strcmp(nconf->nc_protofmly, NC_INET) == 0 ||
1743      -                                strcmp(nconf->nc_protofmly, NC_INET6) == 0) &&
1744      -                                (strcmp(nconf->nc_proto, NC_TCP) != 0 &&
1745      -                                strcmp(nconf->nc_proto, NC_UDP) != 0)))
1746      -
     1750 +                            ((strcmp(nconf->nc_protofmly, NC_INET) == 0 ||
     1751 +                            strcmp(nconf->nc_protofmly, NC_INET6) == 0) &&
     1752 +                            (strcmp(nconf->nc_proto, NC_TCP) != 0 &&
     1753 +                            strcmp(nconf->nc_proto, NC_UDP) != 0))) {
1747 1754                                  continue;
1748      -
1749      -                        else {
     1755 +                        } else {
1750 1756                                  nb = get_the_addr(hostname, prog,
1751      -                                        vers, nconf, port, tinfo,
1752      -                                                fhp, get_pubfh, fspath, error);
     1757 +                                    vers, nconf, port, tinfo,
     1758 +                                    fhp, get_pubfh, fspath, error);
1753 1759  
1754 1760                                  if (nb != NULL)
1755 1761                                          break;
1756 1762  
1757 1763                                  /* nb is NULL - deal with errors */
1758 1764                                  if (error) {
1759 1765                                          if (error->error_type == ERR_NOHOST)
1760 1766                                                  SET_ERR_RET(&errsave_nohost,
1761      -                                                        error->error_type,
1762      -                                                        error->error_value);
     1767 +                                                    error->error_type,
     1768 +                                                    error->error_value);
1763 1769                                          if (error->error_type == ERR_RPCERROR)
1764 1770                                                  SET_ERR_RET(&errsave_rpcerr,
1765      -                                                        error->error_type,
1766      -                                                        error->error_value);
     1771 +                                                    error->error_type,
     1772 +                                                    error->error_value);
1767 1773                                  }
1768 1774                                  /*
1769 1775                                   * continue with same protocol
1770 1776                                   * selection
1771 1777                                   */
1772 1778                                  continue;
1773 1779                          }
1774 1780                  } /* end of while */
1775 1781  
1776 1782                  if (nconf == NULL)
1777 1783                          goto done;
1778 1784  
1779 1785                  if ((nb = get_the_addr(hostname, prog, vers, nconf, port,
1780      -                                tinfo, fhp, get_pubfh, fspath, error)) == NULL)
     1786 +                    tinfo, fhp, get_pubfh, fspath, error)) == NULL)
1781 1787                          goto done;
1782      -
1783      -
1784 1788          } else {
1785 1789  retry:
1786 1790                  SET_ERR_RET(error, ERR_NETPATH, 0);
1787 1791                  while (nconf = getnetpath(nc)) {
1788 1792                          SET_ERR_RET(error, ERR_PROTO_NONE, 0);
1789 1793                          if (nconf->nc_flag & NC_VISIBLE) {
1790 1794                                  if (nthtry == FIRST_TRY) {
1791 1795                                          if ((nconf->nc_semantics ==
1792      -                                                NC_TPI_COTS_ORD) ||
     1796 +                                            NC_TPI_COTS_ORD) ||
1793 1797                                              (nconf->nc_semantics ==
1794      -                                                NC_TPI_COTS)) {
     1798 +                                            NC_TPI_COTS)) {
1795 1799  
1796 1800                                                  if (port == 0)
1797 1801                                                          break;
1798 1802  
1799 1803                                                  if ((strcmp(nconf->nc_protofmly,
1800      -                                                        NC_INET) == 0 ||
1801      -                                                        strcmp(nconf->
1802      -                                                        nc_protofmly,
1803      -                                                        NC_INET6) == 0) &&
     1804 +                                                    NC_INET) == 0 ||
     1805 +                                                    strcmp(nconf->nc_protofmly,
     1806 +                                                    NC_INET6) == 0) &&
1804 1807                                                      (strcmp(nconf->nc_proto,
1805      -                                                        NC_TCP) == 0))
1806      -
     1808 +                                                    NC_TCP) == 0))
1807 1809                                                          break;
1808 1810                                          }
1809 1811                                  }
1810 1812                                  if (nthtry == SECOND_TRY) {
1811 1813                                          if (nconf->nc_semantics ==
1812      -                                                NC_TPI_CLTS) {
     1814 +                                            NC_TPI_CLTS) {
1813 1815                                                  if (port == 0)
1814 1816                                                          break;
1815 1817                                                  if ((strcmp(nconf->nc_protofmly,
1816      -                                                        NC_INET) == 0 ||
1817      -                                                        strcmp(nconf->
1818      -                                                        nc_protofmly, NC_INET6)
1819      -                                                        == 0) &&
1820      -                                                        (strcmp(
1821      -                                                        nconf->nc_proto,
1822      -                                                        NC_UDP) == 0))
     1818 +                                                    NC_INET) == 0 ||
     1819 +                                                    strcmp(nconf->nc_protofmly,
     1820 +                                                    NC_INET6) == 0) &&
     1821 +                                                    (strcmp(nconf->nc_proto,
     1822 +                                                    NC_UDP) == 0))
1823 1823                                                          break;
1824 1824                                          }
1825 1825                                  }
1826 1826                          }
1827 1827                  } /* while */
     1828 +
1828 1829                  if (nconf == NULL) {
1829 1830                          if (++nthtry <= MNT_PREF_LISTLEN) {
1830 1831                                  endnetpath(nc);
1831 1832                                  if ((nc = setnetpath()) == NULL)
1832 1833                                          goto done;
1833 1834                                  goto retry;
1834 1835                          } else
1835 1836                                  goto done;
1836 1837                  } else {
1837 1838                          if ((nb = get_the_addr(hostname, prog, vers, nconf,
1838      -                                port, tinfo, fhp, get_pubfh, fspath, error))
1839      -                                == NULL) {
     1839 +                            port, tinfo, fhp, get_pubfh, fspath, error))
     1840 +                            == NULL) {
     1841 +
1840 1842                                  /* nb is NULL - deal with errors */
1841 1843                                  if (error) {
1842 1844                                          if (error->error_type == ERR_NOHOST)
1843 1845                                                  SET_ERR_RET(&errsave_nohost,
1844      -                                                        error->error_type,
1845      -                                                        error->error_value);
     1846 +                                                    error->error_type,
     1847 +                                                    error->error_value);
1846 1848                                          if (error->error_type == ERR_RPCERROR)
1847 1849                                                  SET_ERR_RET(&errsave_rpcerr,
1848      -                                                        error->error_type,
1849      -                                                        error->error_value);
     1850 +                                                    error->error_type,
     1851 +                                                    error->error_value);
1850 1852                                  }
1851 1853                                  /*
1852 1854                                   * Continue the same search path in the
1853 1855                                   * netconfig db until no more matched
1854 1856                                   * nconf (nconf == NULL).
1855 1857                                   */
1856 1858                                  goto retry;
1857 1859                          }
1858 1860                  }
1859 1861          }
↓ open down ↓ 13 lines elided ↑ open up ↑
1873 1875          if (nc)
1874 1876                  endnetpath(nc);
1875 1877  
1876 1878          if (nb == NULL) {
1877 1879                  /*
1878 1880                   * Check the saved errors. The RPC error has *
1879 1881                   * precedence over the no host error.
1880 1882                   */
1881 1883                  if (errsave_nohost.error_type != ERR_PROTO_NONE)
1882 1884                          SET_ERR_RET(error, errsave_nohost.error_type,
1883      -                                        errsave_nohost.error_value);
     1885 +                            errsave_nohost.error_value);
1884 1886  
1885 1887                  if (errsave_rpcerr.error_type != ERR_PROTO_NONE)
1886 1888                          SET_ERR_RET(error, errsave_rpcerr.error_type,
1887      -                                        errsave_rpcerr.error_value);
     1889 +                            errsave_rpcerr.error_value);
1888 1890          }
1889 1891  
1890 1892          return (nb);
1891 1893  }
1892 1894  
1893 1895  /*
1894 1896   * Get a file handle usinging multi-component lookup with the public
1895 1897   * file handle.
1896 1898   */
1897 1899  static int
↓ open down ↓ 27 lines elided ↑ open up ↑
1925 1927          } else  {
1926 1928                  path = fspath;
1927 1929          }
1928 1930  
1929 1931          for (nfsvers_to_use = vers_max; nfsvers_to_use >= vers_min;
1930 1932              nfsvers_to_use--) {
1931 1933                  /*
1932 1934                   * getaddr_nfs will also fill in the fh for us.
1933 1935                   */
1934 1936                  r = getaddr_nfs(args, fshost, nconfp,
1935      -                                TRUE, path, port, NULL, FALSE);
     1937 +                    TRUE, path, port, NULL, FALSE);
1936 1938  
1937 1939                  if (r == RET_OK) {
1938 1940                          /*
1939 1941                           * Since we are using the public fh, and NLM is
1940 1942                           * not firewall friendly, use local locking.
1941 1943                           * Not the case for v4.
1942 1944                           */
1943 1945                          *versp = nfsvers_to_use;
1944 1946                          switch (nfsvers_to_use) {
1945 1947                          case NFS_V4:
↓ open down ↓ 12 lines elided ↑ open up ↑
1958 1960                          return (r);
1959 1961                  }
1960 1962          }
1961 1963  
1962 1964          if (fspath != path) {
1963 1965                  free(path);
1964 1966          }
1965 1967  
1966 1968          if (loud == TRUE) {
1967 1969                  pr_err(gettext("Could not use public filehandle in request to"
1968      -                        " server %s\n"), fshost);
     1970 +                    " server %s\n"), fshost);
1969 1971          }
1970 1972  
1971 1973          return (r);
1972 1974  }
1973 1975  
1974 1976  /*
1975 1977   * get fhandle of remote path from server's mountd
1976 1978   */
1977 1979  static int
1978 1980  get_fh(struct nfs_args *args, char *fshost, char *fspath, int *versp,
↓ open down ↓ 55 lines elided ↑ open up ↑
2034 2036           * processing.
2035 2037           */
2036 2038          if (vers_to_try == NFS_V4) {
2037 2039                  int savevers = nfsvers_to_use;
2038 2040                  err_ret_t error;
2039 2041                  int retval;
2040 2042                  SET_ERR_RET(&error, ERR_PROTO_NONE, 0);
2041 2043  
2042 2044                  /* Let's hope for the best */
2043 2045                  nfsvers_to_use = NFS_V4;
2044      -                retval =
2045      -                        getaddr_nfs(args, fshost, nconfp, FALSE,
2046      -                                    fspath, port, &error, vers_min == NFS_V4);
     2046 +                retval = getaddr_nfs(args, fshost, nconfp, FALSE,
     2047 +                    fspath, port, &error, vers_min == NFS_V4);
2047 2048  
2048 2049                  if (retval == RET_OK) {
2049 2050                          *versp = nfsvers_to_use = NFS_V4;
2050 2051                          fstype = MNTTYPE_NFS4;
2051 2052                          args->fh = strdup(fspath);
2052 2053                          if (args->fh == NULL) {
2053 2054                                  pr_err(gettext("no memory\n"));
2054 2055                                  *versp = nfsvers_to_use = savevers;
2055 2056                                  return (RET_ERR);
2056 2057                          }
↓ open down ↓ 12 lines elided ↑ open up ↑
2069 2070                   * there has been an error of some sort.  If it is not
2070 2071                   * an RPC error (e.g. host unknown), we just stop and
2071 2072                   * return the error since the other versions would see
2072 2073                   * the same error as well.
2073 2074                   */
2074 2075                  if (retval == RET_ERR && error.error_type != ERR_RPCERROR)
2075 2076                          return (retval);
2076 2077          }
2077 2078  
2078 2079          while ((cl = clnt_create_vers(fshost, MOUNTPROG, &outvers,
2079      -                        vers_min, vers_to_try, "datagram_v")) == NULL) {
     2080 +            vers_min, vers_to_try, "datagram_v")) == NULL) {
2080 2081                  if (rpc_createerr.cf_stat == RPC_UNKNOWNHOST) {
2081 2082                          pr_err(gettext("%s: %s\n"), fshost,
2082 2083                              clnt_spcreateerror(""));
2083 2084                          return (RET_ERR);
2084 2085                  }
2085 2086  
2086 2087                  /*
2087 2088                   * We don't want to downgrade version on lost packets
2088 2089                   */
2089 2090                  if ((rpc_createerr.cf_stat == RPC_TIMEDOUT) ||
2090      -                        (rpc_createerr.cf_stat == RPC_PMAPFAILURE)) {
     2091 +                    (rpc_createerr.cf_stat == RPC_PMAPFAILURE)) {
2091 2092                          pr_err(gettext("%s: %s\n"), fshost,
2092 2093                              clnt_spcreateerror(""));
2093 2094                          return (RET_RETRY);
2094 2095                  }
2095 2096  
2096 2097                  /*
2097 2098                   * back off and try the previous version - patch to the
2098 2099                   * problem of version numbers not being contigous and
2099 2100                   * clnt_create_vers failing (SunOS4.1 clients & SGI servers)
2100 2101                   * The problem happens with most non-Sun servers who
↓ open down ↓ 40 lines elided ↑ open up ↑
2141 2142                      gettext("Couldn't create default authentication handle\n"));
2142 2143                  clnt_destroy(cl);
2143 2144                  return (RET_RETRY);
2144 2145          }
2145 2146  
2146 2147          switch (outvers) {
2147 2148          case MOUNTVERS:
2148 2149          case MOUNTVERS_POSIX:
2149 2150                  *versp = nfsvers_to_use = NFS_VERSION;
2150 2151                  rpc_stat = clnt_call(cl, MOUNTPROC_MNT, xdr_dirpath,
2151      -                        (caddr_t)&fspath, xdr_fhstatus, (caddr_t)&fhs, timeout);
     2152 +                    (caddr_t)&fspath, xdr_fhstatus, (caddr_t)&fhs, timeout);
2152 2153                  if (rpc_stat != RPC_SUCCESS) {
2153 2154                          pr_err(gettext("%s:%s: server not responding %s\n"),
2154 2155                              fshost, fspath, clnt_sperror(cl, ""));
2155 2156                          clnt_destroy(cl);
2156 2157                          return (RET_RETRY);
2157 2158                  }
2158 2159  
2159 2160                  if ((errno = fhs.fhs_status) != MNT_OK) {
2160 2161                          if (loud_on_mnt_err) {
2161      -                            if (errno == EACCES) {
2162      -                                pr_err(gettext("%s:%s: access denied\n"),
2163      -                                    fshost, fspath);
2164      -                            } else {
2165      -                                pr_err(gettext("%s:%s: %s\n"), fshost, fspath,
2166      -                                    strerror(errno));
2167      -                            }
     2162 +                                if (errno == EACCES) {
     2163 +                                        pr_err(gettext(
     2164 +                                            "%s:%s: access denied\n"),
     2165 +                                            fshost, fspath);
     2166 +                                } else {
     2167 +                                        pr_err(gettext("%s:%s: %s\n"),
     2168 +                                            fshost, fspath, strerror(errno));
     2169 +                                }
2168 2170                          }
2169 2171                          clnt_destroy(cl);
2170 2172                          return (RET_MNTERR);
2171 2173                  }
2172 2174                  args->fh = malloc(sizeof (fhs.fhstatus_u.fhs_fhandle));
2173 2175                  if (args->fh == NULL) {
2174 2176                          pr_err(gettext("no memory\n"));
2175 2177                          return (RET_ERR);
2176 2178                  }
2177 2179                  memcpy((caddr_t)args->fh, (caddr_t)&fhs.fhstatus_u.fhs_fhandle,
2178      -                        sizeof (fhs.fhstatus_u.fhs_fhandle));
     2180 +                    sizeof (fhs.fhstatus_u.fhs_fhandle));
2179 2181                  if (!errno && posix) {
2180 2182                          rpc_stat = clnt_call(cl, MOUNTPROC_PATHCONF,
2181      -                                xdr_dirpath, (caddr_t)&fspath, xdr_ppathcnf,
2182      -                                (caddr_t)&p, timeout);
     2183 +                            xdr_dirpath, (caddr_t)&fspath, xdr_ppathcnf,
     2184 +                            (caddr_t)&p, timeout);
2183 2185                          if (rpc_stat != RPC_SUCCESS) {
2184 2186                                  pr_err(gettext(
2185 2187                                      "%s:%s: server not responding %s\n"),
2186 2188                                      fshost, fspath, clnt_sperror(cl, ""));
2187 2189                                  free(args->fh);
2188 2190                                  clnt_destroy(cl);
2189 2191                                  return (RET_RETRY);
2190 2192                          }
2191 2193                          if (_PC_ISSET(_PC_ERROR, p.pc_mask)) {
2192 2194                                  pr_err(gettext(
↓ open down ↓ 5 lines elided ↑ open up ↑
2198 2200                          }
2199 2201                          args->flags |= NFSMNT_POSIX;
2200 2202                          args->pathconf = malloc(sizeof (p));
2201 2203                          if (args->pathconf == NULL) {
2202 2204                                  pr_err(gettext("no memory\n"));
2203 2205                                  free(args->fh);
2204 2206                                  clnt_destroy(cl);
2205 2207                                  return (RET_ERR);
2206 2208                          }
2207 2209                          memcpy((caddr_t)args->pathconf, (caddr_t)&p,
2208      -                                sizeof (p));
     2210 +                            sizeof (p));
2209 2211                  }
2210 2212                  break;
2211 2213  
2212 2214          case MOUNTVERS3:
2213 2215                  *versp = nfsvers_to_use = NFS_V3;
2214 2216                  rpc_stat = clnt_call(cl, MOUNTPROC_MNT, xdr_dirpath,
2215      -                                (caddr_t)&fspath,
2216      -                                xdr_mountres3, (caddr_t)&mountres3, timeout);
     2217 +                    (caddr_t)&fspath, xdr_mountres3,
     2218 +                    (caddr_t)&mountres3, timeout);
2217 2219                  if (rpc_stat != RPC_SUCCESS) {
2218 2220                          pr_err(gettext("%s:%s: server not responding %s\n"),
2219 2221                              fshost, fspath, clnt_sperror(cl, ""));
2220 2222                          clnt_destroy(cl);
2221 2223                          return (RET_RETRY);
2222 2224                  }
2223 2225  
2224 2226                  /*
2225 2227                   * Assume here that most of the MNT3ERR_*
2226 2228                   * codes map into E* errors.
2227 2229                   */
2228 2230                  if ((errno = mountres3.fhs_status) != MNT_OK) {
2229      -                    if (loud_on_mnt_err) {
2230      -                        switch (errno) {
2231      -                        case MNT3ERR_NAMETOOLONG:
2232      -                                msg = "path name is too long";
2233      -                                break;
2234      -                        case MNT3ERR_NOTSUPP:
2235      -                                msg = "operation not supported";
2236      -                                break;
2237      -                        case MNT3ERR_SERVERFAULT:
2238      -                                msg = "server fault";
2239      -                                break;
2240      -                        default:
2241      -                                msg = strerror(errno);
2242      -                                break;
     2231 +                        if (loud_on_mnt_err) {
     2232 +                                switch (errno) {
     2233 +                                case MNT3ERR_NAMETOOLONG:
     2234 +                                        msg = "path name is too long";
     2235 +                                        break;
     2236 +                                case MNT3ERR_NOTSUPP:
     2237 +                                        msg = "operation not supported";
     2238 +                                        break;
     2239 +                                case MNT3ERR_SERVERFAULT:
     2240 +                                        msg = "server fault";
     2241 +                                        break;
     2242 +                                default:
     2243 +                                        msg = strerror(errno);
     2244 +                                        break;
     2245 +                                }
     2246 +
     2247 +                                pr_err(gettext("%s:%s: %s\n"),
     2248 +                                    fshost, fspath, msg);
2243 2249                          }
2244      -                        pr_err(gettext("%s:%s: %s\n"), fshost, fspath, msg);
2245      -                    }
2246      -                    clnt_destroy(cl);
2247      -                    return (RET_MNTERR);
     2250 +
     2251 +                        clnt_destroy(cl);
     2252 +                        return (RET_MNTERR);
2248 2253                  }
2249 2254  
2250 2255                  fh3p = (nfs_fh3 *)malloc(sizeof (*fh3p));
2251 2256                  if (fh3p == NULL) {
2252 2257                          pr_err(gettext("no memory\n"));
2253 2258                          return (RET_ERR);
2254 2259                  }
2255 2260                  fh3p->fh3_length =
2256      -                        mountres3.mountres3_u.mountinfo.fhandle.fhandle3_len;
     2261 +                    mountres3.mountres3_u.mountinfo.fhandle.fhandle3_len;
2257 2262                  (void) memcpy(fh3p->fh3_u.data,
2258      -                        mountres3.mountres3_u.mountinfo.fhandle.fhandle3_val,
2259      -                        fh3p->fh3_length);
     2263 +                    mountres3.mountres3_u.mountinfo.fhandle.fhandle3_val,
     2264 +                    fh3p->fh3_length);
2260 2265                  args->fh = (caddr_t)fh3p;
2261 2266                  fstype = MNTTYPE_NFS3;
2262 2267  
2263 2268                  /*
2264 2269                   * Check the security flavor to be used.
2265 2270                   *
2266 2271                   * If "secure" or "sec=flavor" is a mount
2267 2272                   * option, check if the server supports the "flavor".
2268 2273                   * If the server does not support the flavor, return
2269 2274                   * error.
2270 2275                   *
2271 2276                   * If no mount option is given then use the first supported
2272 2277                   * security flavor (by the client) in the auth list returned
2273 2278                   * from the server.
2274 2279                   *
2275 2280                   */
2276 2281                  auths =
2277      -                mountres3.mountres3_u.mountinfo.auth_flavors.auth_flavors_val;
     2282 +                    mountres3.mountres3_u.mountinfo.auth_flavors.
     2283 +                    auth_flavors_val;
2278 2284                  count =
2279      -                mountres3.mountres3_u.mountinfo.auth_flavors.auth_flavors_len;
     2285 +                    mountres3.mountres3_u.mountinfo.auth_flavors.
     2286 +                    auth_flavors_len;
2280 2287  
2281 2288                  if (sec_opt) {
2282 2289                          for (i = 0; i < count; i++) {
2283 2290                                  if (auths[i] == nfs_sec.sc_nfsnum)
2284      -                                    break;
     2291 +                                        break;
2285 2292                          }
2286      -                        if (i >= count) {
     2293 +                        if (i >= count)
2287 2294                                  goto autherr;
2288      -                        }
2289 2295                  } else {
2290      -                    if (count > 0) {
2291      -                        for (i = 0; i < count; i++) {
2292      -                            if (!nfs_getseconfig_bynumber(auths[i], &nfs_sec)) {
2293      -                                sec_opt++;
2294      -                                break;
2295      -                            }
     2296 +                        if (count > 0) {
     2297 +                                for (i = 0; i < count; i++) {
     2298 +                                        if (!nfs_getseconfig_bynumber(auths[i],
     2299 +                                            &nfs_sec)) {
     2300 +                                                sec_opt++;
     2301 +                                                break;
     2302 +                                        }
     2303 +                                }
     2304 +
     2305 +                                if (i >= count)
     2306 +                                        goto autherr;
2296 2307                          }
2297      -                        if (i >= count) {
2298      -                            goto autherr;
2299      -                        }
2300      -                    }
2301 2308                  }
2302 2309                  break;
2303 2310          default:
2304 2311                  pr_err(gettext("%s:%s: Unknown MOUNT version %d\n"),
2305 2312                      fshost, fspath, outvers);
2306 2313                  clnt_destroy(cl);
2307 2314                  return (RET_ERR);
2308 2315          }
2309 2316  
2310 2317          clnt_destroy(cl);
2311 2318          return (RET_OK);
2312 2319  
2313 2320  autherr:
2314 2321          pr_err(gettext(
2315      -                "security mode does not match the server exporting %s:%s\n"),
2316      -                fshost, fspath);
     2322 +            "security mode does not match the server exporting %s:%s\n"),
     2323 +            fshost, fspath);
2317 2324          clnt_destroy(cl);
2318 2325          return (RET_ERR);
2319 2326  }
2320 2327  
2321 2328  /*
2322 2329   * Fill in the address for the server's NFS service and
2323 2330   * fill in a knetconfig structure for the transport that
2324 2331   * the service is available on.
2325 2332   */
2326 2333  static int
↓ open down ↓ 50 lines elided ↑ open up ↑
2377 2384                   */
2378 2385                  if (get_pubfh == TRUE)
2379 2386                          return (RET_ERR);
2380 2387  
2381 2388                  if (!printed) {
2382 2389                          switch (addr_error.error_type) {
2383 2390                          case 0:
2384 2391                                  printed = 1;
2385 2392                                  break;
2386 2393                          case ERR_RPCERROR:
     2394 +                                /* no error print at this time */
2387 2395                                  if (!print_rpcerror)
2388      -                                        /* no error print at this time */
2389 2396                                          break;
2390 2397                                  pr_err(gettext("%s NFS service not"
2391      -                                            " available %s\n"), fshost,
     2398 +                                    " available %s\n"), fshost,
2392 2399                                      clnt_sperrno(addr_error.error_value));
2393 2400                                  printed = 1;
2394 2401                                  break;
2395 2402                          case ERR_NETPATH:
2396 2403                                  pr_err(gettext("%s: Error in NETPATH.\n"),
2397      -                                        fshost);
     2404 +                                    fshost);
2398 2405                                  printed = 1;
2399 2406                                  break;
2400 2407                          case ERR_PROTO_INVALID:
2401 2408                                  pr_err(gettext("%s: NFS service does not"
2402      -                                        " recognize protocol: %s.\n"), fshost,
2403      -                                        nfs_proto);
     2409 +                                    " recognize protocol: %s.\n"), fshost,
     2410 +                                    nfs_proto);
2404 2411                                  printed = 1;
2405 2412                                  break;
2406 2413                          case ERR_PROTO_UNSUPP:
2407 2414                                  if (nfsvers || nfsvers_to_use == NFS_VERSMIN) {
2408 2415                                          /*
2409 2416                                           * Don't set "printed" here. Since we
2410 2417                                           * have to keep checking here till we
2411 2418                                           * exhaust transport errors on all vers.
2412 2419                                           *
2413 2420                                           * Print this message if:
↓ open down ↓ 2 lines elided ↑ open up ↑
2416 2423                                           *    transport.
2417 2424                                           *
2418 2425                                           * 2. If a version is specified and it
2419 2426                                           *    does'nt support the asked
2420 2427                                           *    transport.
2421 2428                                           *
2422 2429                                           * Otherwise we decrement the version
2423 2430                                           * and retry below.
2424 2431                                           */
2425 2432                                          pr_err(gettext("%s: NFS service does"
2426      -                                                " not support protocol: %s.\n"),
2427      -                                                fshost, nfs_proto);
     2433 +                                            " not support protocol: %s.\n"),
     2434 +                                            fshost, nfs_proto);
2428 2435                                  }
2429 2436                                  break;
2430 2437                          case ERR_NOHOST:
2431 2438                                  pr_err("%s: %s\n", fshost, "Unknown host");
2432 2439                                  printed = 1;
2433 2440                                  break;
2434 2441                          default:
2435 2442                                  /* case ERR_PROTO_NONE falls through */
2436 2443                                  pr_err(gettext("%s: NFS service not responding"
2437      -                                        "\n"), fshost);
     2444 +                                    "\n"), fshost);
2438 2445                                  printed = 1;
2439 2446                                  break;
2440 2447                          }
2441 2448                  }
     2449 +
2442 2450                  SET_ERR_RET(error,
2443      -                        addr_error.error_type, addr_error.error_value);
     2451 +                    addr_error.error_type, addr_error.error_value);
2444 2452                  if (addr_error.error_type == ERR_PROTO_NONE)
2445 2453                          return (RET_RETRY);
2446 2454                  else if (addr_error.error_type == ERR_RPCERROR &&
2447      -                        ! IS_UNRECOVERABLE_RPC(addr_error.error_value)) {
     2455 +                    ! IS_UNRECOVERABLE_RPC(addr_error.error_value)) {
2448 2456                          return (RET_RETRY);
2449 2457                  } else if (nfsvers == 0 && addr_error.error_type ==
2450      -                        ERR_PROTO_UNSUPP && nfsvers_to_use != NFS_VERSMIN) {
     2458 +                    ERR_PROTO_UNSUPP && nfsvers_to_use != NFS_VERSMIN) {
2451 2459                          /*
2452 2460                           * If no version is specified, and the error is due
2453 2461                           * to an unsupported transport, then decrement the
2454 2462                           * version and retry.
2455 2463                           */
2456 2464                          return (RET_RETRY);
2457 2465                  } else
2458 2466                          return (RET_ERR);
2459 2467          }
2460 2468          nconf = *nconfp;
↓ open down ↓ 52 lines elided ↑ open up ↑
2513 2521  
2514 2522          while (count--) {
2515 2523                  if ((r = mount_nfs(mntp, ro, NULL)) == RET_OK) {
2516 2524                          pr_err(gettext("%s: mounted OK\n"), mntp->mnt_mountp);
2517 2525                          return (RET_OK);
2518 2526                  }
2519 2527                  if (r != RET_RETRY)
2520 2528                          break;
2521 2529  
2522 2530                  if (count > 0) {
2523      -                    (void) sleep(delay);
2524      -                    delay *= 2;
2525      -                    if (delay > 120)
2526      -                            delay = 120;
     2531 +                        (void) sleep(delay);
     2532 +                        delay *= 2;
     2533 +                        if (delay > 120)
     2534 +                                delay = 120;
2527 2535                  }
2528 2536          }
2529 2537  
2530 2538          if (!nfsretry_vers)
2531 2539                  pr_err(gettext("giving up on: %s\n"), mntp->mnt_mountp);
2532 2540  
2533 2541          return (RET_ERR);
2534 2542  }
2535 2543  
2536 2544  /*
↓ open down ↓ 36 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX