Ejemplo n.º 1
0
void
print_mnttab(int vflg, int pflg)
{
	FILE	*fd;
	FILE	*rfp;			/* this will be NULL if fopen fails */
	int	ret;
	char	time_buf[TIME_MAX];	/* array to hold date and time */
	struct extmnttab	mget;
	time_t	ltime;

	if ((fd = fopen(mnttab, "r")) == NULL) {
		fprintf(stderr, gettext("%s: Cannot open mnttab\n"), myname);
		exit(1);
	}
	rfp = fopen(REMOTE, "r");
	while ((ret = getextmntent(fd, &mget, sizeof (struct extmnttab)))
	    == 0) {
		if (ignore(mget.mnt_mntopts))
			continue;
		if (mget.mnt_special && mget.mnt_mountp &&
		    mget.mnt_fstype && mget.mnt_time) {
			ltime = atol(mget.mnt_time);
			cftime(time_buf, FORMAT, &ltime);
			if (pflg) {
				elide_dev(mget.mnt_mntopts);
				printf("%s - %s %s - no %s\n",
				    mget.mnt_special,
				    mget.mnt_mountp,
				    mget.mnt_fstype,
				    mget.mnt_mntopts != NULL ?
				    mget.mnt_mntopts : "-");
			} else if (vflg) {
				printf("%s on %s type %s %s%s on %s",
				    mget.mnt_special,
				    mget.mnt_mountp,
				    mget.mnt_fstype,
				    remote(mget.mnt_fstype, rfp),
				    flags(mget.mnt_mntopts, NEW),
				    time_buf);
			} else
				printf("%s on %s %s%s on %s",
				    mget.mnt_mountp,
				    mget.mnt_special,
				    remote(mget.mnt_fstype, rfp),
				    flags(mget.mnt_mntopts, OLD),
				    time_buf);
		}
	}
	if (ret > 0)
		mnterror(ret);
}
Ejemplo n.º 2
0
void
print_mnttab(int vflg, int pflg)
{
	FILE	*fd;
	FILE	*rfp;			/* this will be NULL if fopen fails */
	int	ret;
	char	time_buf[TIME_MAX];	/* array to hold date and time */
	struct extmnttab	mget;
	time_t	ltime;
#ifdef MNTFS_DISABLE
	struct mnttab	gmtab;
#endif	/* MNTFS_DISABLE */

	if ((fd = fopen(mnttab, "r")) == NULL) {
		fprintf(stderr, gettext("%s: Cannot open mnttab\n"), myname);
		exit(1);
	}
	rfp = fopen(REMOTE, "r");
#ifndef MNTFS_DISABLE
	while ((ret = getextmntent(fd, &mget, sizeof (struct extmnttab)))
	    == 0) {
#else
	while ((ret = getmntent(fd, &gmtab)) == 0) {
		struct stat64 msb;

		if (stat64(gmtab.mnt_mountp, &msb) == -1) {
			fprintf(stderr,
			    gettext("%s: Cannot stat mnttab\n"), myname);
			exit(2);
		}
		mget.mnt_special = gmtab.mnt_special;
		mget.mnt_mountp = gmtab.mnt_mountp;
		mget.mnt_fstype = gmtab.mnt_fstype;
		mget.mnt_mntopts = gmtab.mnt_mntopts;
		mget.mnt_time = gmtab.mnt_time;
		mget.mnt_major = (uint_t) major(msb.st_dev);
		mget.mnt_minor = (uint_t) minor(msb.st_dev);

#endif	/* MNTFS_DISABLE */
		if (ignore(mget.mnt_mntopts))
			continue;
		if (mget.mnt_special && mget.mnt_mountp &&
		    mget.mnt_fstype && mget.mnt_time) {
			ltime = atol(mget.mnt_time);
			cftime(time_buf, FORMAT, &ltime);
			if (pflg) {
				elide_dev(mget.mnt_mntopts);
				printf("%s - %s %s - no %s\n",
				    mget.mnt_special,
				    mget.mnt_mountp,
				    mget.mnt_fstype,
				    mget.mnt_mntopts != NULL ?
				    mget.mnt_mntopts : "-");
			} else if (vflg) {
				printf("%s on %s type %s %s%s on %s",
				    mget.mnt_special,
				    mget.mnt_mountp,
				    mget.mnt_fstype,
				    remote(mget.mnt_fstype, rfp),
				    flags(mget.mnt_mntopts, NEW),
				    time_buf);
			} else
				printf("%s on %s %s%s on %s",
				    mget.mnt_mountp,
				    mget.mnt_special,
				    remote(mget.mnt_fstype, rfp),
				    flags(mget.mnt_mntopts, OLD),
				    time_buf);
		}
	}
	if (ret > 0)
		mnterror(ret);
}

char	*
flags(char *mntopts, int flag)
{
	char	opts[sizeof (mntflags)];
	char	*value;
	int	rdwr = 1;
	int	suid = 1;
	int	devices = 1;
	int	setuid = 1;

	if (mntopts == NULL || *mntopts == '\0')
		return ("read/write/setuid/devices");

	strcpy(opts, "");
	while (*mntopts != '\0')  {
		switch (getsubopt(&mntopts, myopts, &value)) {
		case READONLY:
			rdwr = 0;
			break;
		case READWRITE:
			rdwr = 1;
			break;
		case SUID:
			suid = 1;
			break;
		case NOSUID:
			suid = 0;
			break;
		case SETUID:
			setuid = 1;
			break;
		case NOSETUID:
			setuid = 0;
			break;
		case DEVICES:
			devices = 1;
			break;
		case NODEVICES:
			devices = 0;
			break;
		default:
			/* cat '/' separator to mntflags */
			if (*opts != '\0' && value != NULL)
				strcat(opts, "/");
			strcat(opts, value);
			break;
		}
	}

	strcpy(mntflags, "");
	if (rdwr)
		strcat(mntflags, "read/write");
	else if (flag == OLD)
		strcat(mntflags, "read only");
	else
		strcat(mntflags, "read-only");
	if (suid) {
		if (setuid)
			strcat(mntflags, "/setuid");
		else
			strcat(mntflags, "/nosetuid");
		if (devices)
			strcat(mntflags, "/devices");
		else
			strcat(mntflags, "/nodevices");
	} else {
		strcat(mntflags, "/nosetuid/nodevices");
	}
	if (*opts != '\0') {
		strcat(mntflags, "/");
		strcat(mntflags, opts);
	}

	/*
	 * The assumed assertion
	 * 	assert (strlen(mntflags) < sizeof mntflags);
	 * is valid at this point in the code. Note that a call to "assert"
	 * is not appropriate in production code since it halts the program.
	 */
	return (mntflags);
}