4 * Manage the rmtab file for mountd.
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
12 #include <netinet/in.h>
13 #include <arpa/inet.h>
22 mountlist_add(nfs_export *exp, const char *path)
28 if ((lockid = xflock(_PATH_RMTAB, "a")) < 0)
31 while ((rep = getrmtabent(1)) != NULL) {
32 if (strcmp (rep->r_client,
33 exp->m_client->m_hostname) == 0
34 && strcmp(rep->r_path, path) == 0) {
41 strncpy(xe.r_client, exp->m_client->m_hostname,
42 sizeof (xe.r_client) - 1);
43 xe.r_client [sizeof (xe.r_client) - 1] = '\0';
44 strncpy(xe.r_path, path, sizeof (xe.r_path) - 1);
45 xe.r_path [sizeof (xe.r_path) - 1] = '\0';
46 if (setrmtabent("a")) {
54 mountlist_del(nfs_export *exp, const char *path)
58 char *hname = exp->m_client->m_hostname;
61 if ((lockid = xflock(_PATH_RMTAB, "w")) < 0)
63 if (!setrmtabent("r")) {
67 if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w"))) {
72 while ((rep = getrmtabent(1)) != NULL) {
73 if (strcmp (rep->r_client, hname)
74 || strcmp(rep->r_path, path))
75 fputrmtabent(fp, rep);
77 if (rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
78 xlog(L_ERROR, "couldn't rename %s to %s",
79 _PATH_RMTABTMP, _PATH_RMTAB);
81 endrmtabent(); /* close & unlink */
87 mountlist_del_all(struct sockaddr_in *sin)
89 struct in_addr addr = sin->sin_addr;
96 if ((lockid = xflock(_PATH_RMTAB, "w")) < 0)
98 if (!(hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET))) {
99 xlog(L_ERROR, "can't get hostname of %s", inet_ntoa(addr));
104 hp = hostent_dup (hp);
106 if (!setrmtabent("r")) {
111 if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w"))) {
117 while ((rep = getrmtabent(1)) != NULL) {
118 if (strcmp(rep->r_client, hp->h_name) == 0 &&
119 (exp = auth_authenticate("umountall", sin, rep->r_path))) {
123 fputrmtabent(fp, rep);
125 if (rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
126 xlog(L_ERROR, "couldn't rename %s to %s",
127 _PATH_RMTABTMP, _PATH_RMTAB);
129 endrmtabent(); /* close & unlink */
138 static mountlist mlist = NULL;
139 static time_t last_mtime = 0;
141 struct rmtabent *rep;
145 if ((lockid = xflock(_PATH_RMTAB, "r")) < 0)
147 if (stat(_PATH_RMTAB, &stb) < 0) {
148 xlog(L_ERROR, "can't stat %s", _PATH_RMTAB);
151 if (stb.st_mtime != last_mtime) {
153 mlist = (m = mlist)->ml_next;
154 xfree(m->ml_hostname);
155 xfree(m->ml_directory);
158 last_mtime = stb.st_mtime;
161 while ((rep = getrmtabent(1)) != NULL) {
162 m = (mountlist) xmalloc(sizeof(*m));
163 m->ml_hostname = xstrdup(rep->r_client);
164 m->ml_directory = xstrdup(rep->r_path);