Example #1
0
int
rmtab_read(void)
{
	struct rmtabent		*rep;

	setrmtabent("r");
	while ((rep = getrmtabent(1, NULL)) != NULL) {
		int			htype;

		htype = client_gettype(rep->r_client);
		if (htype == MCL_FQDN || htype == MCL_SUBNETWORK)
			rmtab_read_wildcard(rep);
	}

	if (errno == EINVAL) {
		/* Something goes wrong. We need to fix the rmtab
		   file. */
		int	lockid;
		FILE	*fp;
		if ((lockid = xflock(_PATH_RMTABLCK, "w")) < 0)
			return -1;
		rewindrmtabent();
		if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w"))) {
			endrmtabent ();
			xfunlock(lockid);
			return -1;
		}
		while ((rep = getrmtabent(0, NULL)) != NULL) {
			fputrmtabent(fp, rep, NULL);
		}
		if (rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
			xlog(L_ERROR, "couldn't rename %s to %s",
			     _PATH_RMTABTMP, _PATH_RMTAB);
		}
		endrmtabent();
		fendrmtabent(fp);
		xfunlock(lockid);
	}
	else {
		endrmtabent();
	}
	return 0;
}
Example #2
0
void
mountlist_del_all(const struct sockaddr *sap)
{
	char		*hostname;
	struct rmtabent	*rep;
	FILE		*fp;
	int		lockid;

	if ((lockid = xflock(_PATH_RMTABLCK, "w")) < 0)
		return;
	hostname = host_canonname(sap);
	if (hostname == NULL) {
		char buf[INET6_ADDRSTRLEN];
		xlog(L_ERROR, "can't get hostname of %s",
			host_ntop(sap, buf, sizeof(buf)));
		goto out_unlock;
	}

	if (!setrmtabent("r"))
		goto out_free;

	if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w")))
		goto out_close;

	while ((rep = getrmtabent(1, NULL)) != NULL) {
		if (strcmp(rep->r_client, hostname) == 0 &&
		    auth_authenticate("umountall", sap, rep->r_path) != NULL)
			continue;
		fputrmtabent(fp, rep, NULL);
	}
	if (slink_safe_rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
		xlog(L_ERROR, "couldn't rename %s to %s",
				_PATH_RMTABTMP, _PATH_RMTAB);
	}
	fendrmtabent(fp);
out_close:
	endrmtabent();	/* close & unlink */
out_free:
	free(hostname);
out_unlock:
	xfunlock(lockid);
}
Example #3
0
void
mountlist_del(char *hname, const char *path)
{
	struct rmtabent	*rep;
	FILE		*fp;
	int		lockid;
	int		match;

	if ((lockid = xflock(_PATH_RMTABLCK, "w")) < 0)
		return;
	if (!setrmtabent("r")) {
		xfunlock(lockid);
		return;
	}
	if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w"))) {
		endrmtabent();
		xfunlock(lockid);
		return;
	}
	while ((rep = getrmtabent(1, NULL)) != NULL) {
		match = !strcmp (rep->r_client, hname)
			&& !strcmp(rep->r_path, path);
		if (match) {
			rep->r_count--;
			/* PRC: do the HA callout: */
			ha_callout("unmount", rep->r_client, rep->r_path, rep->r_count);
		}
		if (!match || rep->r_count)
			fputrmtabent(fp, rep, NULL);
	}
	if (slink_safe_rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
		xlog(L_ERROR, "couldn't rename %s to %s",
				_PATH_RMTABTMP, _PATH_RMTAB);
	}
	endrmtabent();	/* close & unlink */
	fendrmtabent(fp);
	xfunlock(lockid);
}
Example #4
0
void
putrmtabent(struct rmtabent *rep, long *pos)
{
	fputrmtabent(rmfp, rep, pos);
}