source: trunk/athena/lib/locker/misc.c @ 12783

Revision 12783, 3.6 KB checked in by danw, 26 years ago (diff)
record zephyr subscriptions, but don't actually make any libzephyr calls unless the caller explicitly asks for the subscription list to be processed.
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 deals with miscellaneous
17 * public locker operations besides attaching and detaching.
18 */
19
20static const char rcsid[] = "$Id: misc.c,v 1.2 1999-03-29 17:33:23 danw Exp $";
21
22#include <errno.h>
23#include <stdlib.h>
24#include <string.h>
25
26#include <hesiod.h>
27
28#include "locker.h"
29#include "locker_private.h"
30
31int locker_auth(locker_context context, char *filesystem, int op)
32{
33  int status;
34  locker_attachent *at;
35
36  status = locker_read_attachent(context, filesystem, &at);
37  if (status)
38    return status;
39
40  status = at->fs->auth(context, at, LOCKER_AUTH_DEFAULT, op);
41
42  locker_free_attachent(context, at);
43  return status;
44}
45
46int locker_zsubs(locker_context context, char *filesystem)
47{
48  int status;
49  locker_attachent *at;
50
51  status = locker_read_attachent(context, filesystem, &at);
52  if (status)
53    return status;
54
55  status = at->fs->zsubs(context, at);
56
57  locker_free_attachent(context, at);
58  return status;
59}
60
61/* See if the owner list for the locker contains the uid pointed to by
62 * ownerp. (For use with locker_iterate_attachtab.)
63 */
64int locker_check_owner(locker_context context, locker_attachent *at,
65                       void *ownerp)
66{
67  uid_t owner;
68  int i;
69
70  owner = *(uid_t *)ownerp;
71
72  for (i = 0; i < at->nowners; i++)
73    {
74      if (at->owners[i] == owner)
75        return 1;
76    }
77  return 0;
78}
79
80/* See if the locker is on the host pointed to by addrp. If *addrp is
81 * 0.0.0.0, always returns true. (For use with
82 * locker_iterate_attachtab.)
83 */
84int locker_check_host(locker_context context, locker_attachent *at,
85                      void *addrp)
86{
87  struct in_addr *addr = addrp;
88  return !addr->s_addr || at->hostaddr.s_addr == addr->s_addr;
89}
90
91
92/* Look up a locker description (in Hesiod or attach.conf). */
93int locker_lookup_filsys(locker_context context, char *name, char ***descs,
94                          void **cleanup)
95{
96  char *conffs;
97
98  /* Look for a locker defined in attach.conf. */
99  conffs = locker__fs_data(context, context->filesystem, NULL, name);
100  if (conffs)
101    {
102      *descs = malloc(2 * sizeof(char *));
103      if (!*descs)
104        {
105          locker__error(context, "Out of memory in looking up filesystem.\n");
106          return LOCKER_ENOMEM;
107        }
108      *descs[0] = conffs;
109      *descs[1] = NULL;
110      *cleanup = NULL;
111
112      return LOCKER_SUCCESS;
113    }
114  else
115    {
116      /* Otherwise, look for a locker in Hesiod--which might be an fsgroup. */
117      *descs = hesiod_resolve(context->hes_context, name, "filsys");
118      if (!*descs && errno == ENOENT)
119        {
120          locker__error(context, "%s: Locker unknown.\n", name);
121          return LOCKER_EUNKNOWN;
122        }
123      if (!*descs || !**descs)
124        {
125          if (*descs)
126            hesiod_free_list(context->hes_context, *descs);
127          locker__error(context, "%s: Could not look up Hesiod entry: %s.\n",
128                        name, strerror(errno));
129          return LOCKER_EHESIOD;
130        }
131
132      *cleanup = context->hes_context;
133      return LOCKER_SUCCESS;
134    }
135}
136
137void locker_free_filesys(locker_context context, char **descs, void *cleanup)
138{
139  if (cleanup)
140    hesiod_free_list(cleanup, descs);
141  else
142    free(descs);
143}
Note: See TracBrowser for help on using the repository browser.