source: trunk/athena/lib/locker/miscfs.c @ 13171

Revision 13171, 4.5 KB checked in by danw, 26 years ago (diff)
Rework locker__canonicalize_path and locker__build_mountpoint to deal with the possibility that a UFS/NFS mountpoint directory might already exist. Gets rid of "Directory should not exist" errors on some machines that have crufty directories lying around before taking 8.3.
Line 
1/* Copyright 1998 by the Massachusetts Institute of Technology.
2 *
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose.  It is provided "as is"
13 * without express or implied warranty.
14 */
15
16/* This file is part of liblocker. It implements UFS and ERR lockers. */
17
18static const char rcsid[] = "$Id: miscfs.c,v 1.3 1999-06-04 14:06:41 danw Exp $";
19
20#include <sys/stat.h>
21#include <errno.h>
22#include <netdb.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include "locker.h"
27#include "locker_private.h"
28
29static int ufs_parse(locker_context context, char *name, char *desc,
30                     char *mountpoint, locker_attachent **atp);
31static int ufs_auth(locker_context context, locker_attachent *at,
32                    int mode, int op);
33static int ufs_zsubs(locker_context context, locker_attachent *at);
34
35struct locker_ops locker__ufs_ops = {
36  "UFS",
37  LOCKER_FS_NEEDS_MOUNTDIR,
38  ufs_parse,
39  locker__mount,
40  locker__unmount,
41  ufs_auth,
42  ufs_zsubs
43};
44
45static int err_parse(locker_context context, char *name, char *desc,
46                     char *mountpoint, locker_attachent **at);
47
48struct locker_ops locker__err_ops = {
49  "ERR",
50  0,
51  err_parse,
52  NULL,
53  NULL,
54  NULL,
55  NULL
56};
57
58static int ufs_parse(locker_context context, char *name, char *desc,
59                     char *mountpoint, locker_attachent **atp)
60{
61  locker_attachent *at;
62  char *p, *dup = NULL, *lasts = NULL;
63  int status;
64
65  at = locker__new_attachent(context, &locker__ufs_ops);
66  if (!at)
67    return LOCKER_ENOMEM;
68
69  if (!name)
70    {
71      at->name = strdup(desc);
72      at->hostdir = strdup(desc);
73      if (mountpoint)
74        at->mountpoint = strdup(mountpoint);
75      else
76        at->mountpoint = strdup(LOCKER_UFS_MOUNT_DIR);
77      at->mode = LOCKER_AUTH_READWRITE;
78
79      if (!at->name || !at->hostdir || !at->mountpoint)
80        goto mem_error;
81    }
82  else
83    {
84      /* A Hesiod UFS description (if we had any) would look like:
85       * UFS /dev/dsk/c0t0d0s2 w /u1
86       */
87
88      at->name = strdup(name);
89      if (!at->name)
90        goto mem_error;
91
92      dup = strdup(desc);
93      if (!dup)
94        goto mem_error;
95
96      /* Skip "UFS". */
97      if (!strtok_r(dup, " ", &lasts))
98        goto parse_error;
99
100      /* Hostdir */
101      at->hostdir = strtok_r(NULL, " ", &lasts);
102      if (!at->hostdir)
103        goto parse_error;
104      at->hostdir = strdup(at->hostdir);
105      if (!at->hostdir)
106        goto mem_error;
107
108      /* Mount mode */
109      p = strtok_r(NULL, " ", &lasts);
110      if (!p || *(p + 1))
111        goto parse_error;
112
113      switch (*p)
114        {
115        case 'r':
116          at->mode = LOCKER_AUTH_READONLY;
117          break;
118        case 'w':
119          at->mode = LOCKER_AUTH_READWRITE;
120          break;
121        case 'n':
122          at->mode = LOCKER_AUTH_READWRITE;
123          break;
124        default:
125          locker__error(context, "%s: Unrecognized mount option '%c' in "
126                        "description:\n%s\n", name, *p, desc);
127          status = LOCKER_EPARSE;
128          goto cleanup;
129        }
130
131      /* Mountpoint */
132      p = strtok_r(NULL, " ", &lasts);
133      if (!p)
134        goto parse_error;
135      if (mountpoint)
136        at->mountpoint = strdup(mountpoint);
137      else
138        at->mountpoint = strdup(at->mountpoint);
139      if (!at->mountpoint)
140        goto mem_error;
141
142      free(dup);
143      dup = NULL;
144    }
145
146  status = locker__canonicalize_path(context, LOCKER_CANON_CHECK_ALL,
147                                     &(at->mountpoint), &(at->buildfrom));
148  if (status != LOCKER_SUCCESS)
149    goto cleanup;
150
151  *atp = at;
152  return LOCKER_SUCCESS;
153
154mem_error:
155  locker__error(context, "Out of memory parsing locker description.\n");
156  status = LOCKER_ENOMEM;
157  goto cleanup;
158
159parse_error:
160  locker__error(context, "Could not parse locker description "
161                "\"%s\".\n", desc);
162  status = LOCKER_EPARSE;
163
164cleanup:
165  free(dup);
166  locker_free_attachent(context, at);
167  return status;
168}
169
170static int ufs_auth(locker_context context, locker_attachent *at,
171                    int mode, int op)
172{
173  return LOCKER_SUCCESS;
174}
175
176static int ufs_zsubs(locker_context context, locker_attachent *at)
177{
178  return LOCKER_SUCCESS;
179}
180
181
182static int err_parse(locker_context context, char *name, char *desc,
183                     char *mountpoint, locker_attachent **atp)
184{
185  if (name)
186    locker__error(context, "%s: %s\n", name, desc + 4);
187  else
188    locker__error(context, "%s\n", desc);
189  return LOCKER_EATTACH;
190}
Note: See TracBrowser for help on using the repository browser.