- struct mountlist ml;
- off_t off, pos;
-
- off = -1;
- pos = 0;
- lseek(mlfile, (off_t)0, L_SET);
- while (read(mlfile, (caddr_t)&ml, sizeof(ml)) == sizeof(ml)) {
- if (!strcmp(host, ml.ml_host) && !strcmp(dirp, ml.ml_dirp)) {
- lseek(mlfile, (off_t)-sizeof(ml), L_INCR);
- return (TRUE);
- } else if (ml.ml_host[0] == '\0') {
- off = pos;
+ register struct mountlist *mlp, **mlpp;
+ register char *eos, *dirp;
+ int len;
+ char str[STRSIZ];
+ FILE *mlfile;
+
+ if (((mlfile = fopen(_PATH_RMOUNTLIST, "r")) == NULL) &&
+ ((mlfile = fopen(_PATH_RMOUNTLIST, "w")) == NULL)) {
+ syslog(LOG_WARNING, "Can't open %s", _PATH_RMOUNTLIST);
+ return;
+ }
+ mlpp = &mlhead;
+ while (fgets(str, STRSIZ, mlfile) != NULL) {
+ if ((dirp = index(str, '\t')) == NULL &&
+ (dirp = index(str, ' ')) == NULL)
+ continue;
+ mlp = (struct mountlist *)malloc(sizeof (*mlp));
+ len = dirp-str;
+ if (len > RPCMNT_NAMELEN)
+ len = RPCMNT_NAMELEN;
+ bcopy(str, mlp->ml_host, len);
+ mlp->ml_host[len] = '\0';
+ while (*dirp == '\t' || *dirp == ' ')
+ dirp++;
+ if ((eos = index(dirp, '\t')) == NULL &&
+ (eos = index(dirp, ' ')) == NULL &&
+ (eos = index(dirp, '\n')) == NULL)
+ len = strlen(dirp);
+ else
+ len = eos-dirp;
+ if (len > RPCMNT_PATHLEN)
+ len = RPCMNT_PATHLEN;
+ bcopy(dirp, mlp->ml_dirp, len);
+ mlp->ml_dirp[len] = '\0';
+ mlp->ml_next = (struct mountlist *)0;
+ *mlpp = mlp;
+ mlpp = &mlp->ml_next;
+ }
+ fclose(mlfile);
+}
+
+void del_mlist(hostp, dirp)
+ register char *hostp, *dirp;
+{
+ register struct mountlist *mlp, **mlpp;
+ FILE *mlfile;
+ int fnd = 0;
+
+ mlpp = &mlhead;
+ mlp = mlhead;
+ while (mlp) {
+ if (!strcmp(mlp->ml_host, hostp) &&
+ (!dirp || !strcmp(mlp->ml_dirp, dirp))) {
+ fnd = 1;
+ *mlpp = mlp->ml_next;
+ free((caddr_t)mlp);
+ }
+ mlpp = &mlp->ml_next;
+ mlp = mlp->ml_next;
+ }
+ if (fnd) {
+ if ((mlfile = fopen(_PATH_RMOUNTLIST, "w")) == NULL) {
+ syslog(LOG_WARNING, "Can't update %s", _PATH_RMOUNTLIST);
+ return;
+ }
+ mlp = mlhead;
+ while (mlp) {
+ fprintf(mlfile, "%s %s\n", mlp->ml_host, mlp->ml_dirp);
+ mlp = mlp->ml_next;