- free(hostname);
- p += 5;
- q = p;
- while (*q && *q != ',') q++;
- hostname = xstrndup(p,q-p);
- }
-
- if (opts && (p = strstr(opts, "mounthost="))) {
- char *q;
-
- free(hostname);
- p += 10;
- q = p;
- while (*q && *q != ',') q++;
- hostname = xstrndup(p,q-p);
- }
-
- pmap->pm_prog = MOUNTPROG;
- pmap->pm_vers = MOUNTVERS_NFSV3;
- if (opts && (p = strstr(opts, "mountprog=")) && isdigit(*(p+10)))
- pmap->pm_prog = atoi(p+10);
- if (opts && (p = strstr(opts, "mountport=")) && isdigit(*(p+10)))
- pmap->pm_port = atoi(p+10);
- if (opts && hasmntopt(&mnt, "v2"))
- pmap->pm_vers = nfsvers_to_mnt(2);
- if (opts && hasmntopt(&mnt, "v3"))
- pmap->pm_vers = nfsvers_to_mnt(3);
- if (opts && hasmntopt(&mnt, "v4"))
- pmap->pm_vers = nfsvers_to_mnt(4);
- if (opts && (p = strstr(opts, "vers=")) && isdigit(*(p+5)))
- pmap->pm_vers = nfsvers_to_mnt(atoi(p+5));
- if (opts && (p = strstr(opts, "mountvers=")) && isdigit(*(p+10)))
- pmap->pm_vers = atoi(p+10);
- if (opts && (hasmntopt(&mnt, "udp") || hasmntopt(&mnt, "proto=udp")))
- pmap->pm_prot = IPPROTO_UDP;
- if (opts && (hasmntopt(&mnt, "tcp") || hasmntopt(&mnt, "proto=tcp")))
- pmap->pm_prot = IPPROTO_TCP;
-
- if (!nfs_gethostbyname(hostname, &mnt_server.saddr)) {
- nfs_error(_("%s: '%s' does not contain a recognized hostname"),
- progname, spec);
- return EX_USAGE;
- }
+ retval = -1;
+ while (fgets(buffer, sizeof(buffer), f) != NULL) {
+ char *device, *mntdir, *type, *flags;
+ struct mount_options *options;
+ char *line = buffer;
+
+ next = strchr(line, '\n');
+ if (next != NULL)
+ *next = '\0';
+
+ device = strtok(line, " \t");
+ if (device == NULL)
+ continue;
+ mntdir = strtok(NULL, " \t");
+ if (mntdir == NULL)
+ continue;
+ if (strcmp(device, mc->m.mnt_fsname) != 0 &&
+ strcmp(mntdir, mc->m.mnt_dir) != 0)
+ continue;
+
+ type = strtok(NULL, " \t");
+ if (type == NULL)
+ continue;
+ if (strcmp(type, "nfs4") == 0)
+ goto out_nfs4;
+
+ flags = strtok(NULL, " \t");
+ if (flags == NULL)
+ continue;
+ options = po_split(flags);
+ if (options != NULL) {
+ unsigned long version;
+ int rc;
+
+ rc = nfs_nfs_version(options, &version);
+ po_destroy(options);
+ if (rc && version == 4)
+ goto out_nfs4;
+ }