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)
29 if ((lockid = xflock(_PATH_RMTAB, "a")) < 0)
32 while ((rep = getrmtabent(1, &pos)) != NULL) {
33 if (strcmp (rep->r_client,
34 exp->m_client->m_hostname) == 0
35 && strcmp(rep->r_path, path) == 0) {
37 putrmtabent(rep, &pos);
44 strncpy(xe.r_client, exp->m_client->m_hostname,
45 sizeof (xe.r_client) - 1);
46 xe.r_client [sizeof (xe.r_client) - 1] = '\0';
47 strncpy(xe.r_path, path, sizeof (xe.r_path) - 1);
48 xe.r_path [sizeof (xe.r_path) - 1] = '\0';
50 if (setrmtabent("a")) {
51 putrmtabent(&xe, NULL);
58 mountlist_del(nfs_export *exp, const char *path)
62 char *hname = exp->m_client->m_hostname;
66 if ((lockid = xflock(_PATH_RMTAB, "w")) < 0)
68 if (!setrmtabent("r")) {
72 if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w"))) {
77 while ((rep = getrmtabent(1, NULL)) != NULL) {
78 match = !strcmp (rep->r_client, hname)
79 && !strcmp(rep->r_path, path);
82 if (!match || rep->r_count)
83 fputrmtabent(fp, rep, NULL);
85 if (rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
86 xlog(L_ERROR, "couldn't rename %s to %s",
87 _PATH_RMTABTMP, _PATH_RMTAB);
89 endrmtabent(); /* close & unlink */
95 mountlist_del_all(struct sockaddr_in *sin)
97 struct in_addr addr = sin->sin_addr;
104 if ((lockid = xflock(_PATH_RMTAB, "w")) < 0)
106 if (!(hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET))) {
107 xlog(L_ERROR, "can't get hostname of %s", inet_ntoa(addr));
112 hp = hostent_dup (hp);
114 if (!setrmtabent("r")) {
119 if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w"))) {
125 while ((rep = getrmtabent(1, NULL)) != NULL) {
126 if (strcmp(rep->r_client, hp->h_name) == 0 &&
127 (exp = auth_authenticate("umountall", sin, rep->r_path))) {
131 fputrmtabent(fp, rep, NULL);
133 if (rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
134 xlog(L_ERROR, "couldn't rename %s to %s",
135 _PATH_RMTABTMP, _PATH_RMTAB);
137 endrmtabent(); /* close & unlink */
146 static mountlist mlist = NULL;
147 static time_t last_mtime = 0;
149 struct rmtabent *rep;
153 if ((lockid = xflock(_PATH_RMTAB, "r")) < 0)
155 if (stat(_PATH_RMTAB, &stb) < 0) {
156 xlog(L_ERROR, "can't stat %s", _PATH_RMTAB);
159 if (stb.st_mtime != last_mtime) {
161 mlist = (m = mlist)->ml_next;
162 xfree(m->ml_hostname);
163 xfree(m->ml_directory);
166 last_mtime = stb.st_mtime;
169 while ((rep = getrmtabent(1, NULL)) != NULL) {
170 m = (mountlist) xmalloc(sizeof(*m));
171 m->ml_hostname = xstrdup(rep->r_client);
172 m->ml_directory = xstrdup(rep->r_path);