aboutsummaryrefslogtreecommitdiff
path: root/libiohelp
diff options
context:
space:
mode:
Diffstat (limited to 'libiohelp')
-rw-r--r--libiohelp/ChangeLog37
-rw-r--r--libiohelp/Makefile16
-rw-r--r--libiohelp/handle_io_release_conch.c7
-rw-r--r--libiohelp/iohelp.h70
-rw-r--r--libiohelp/iouser-create.c111
-rw-r--r--libiohelp/iouser-dup.c56
-rw-r--r--libiohelp/iouser-free.c28
-rw-r--r--libiohelp/iouser-reauth.c106
-rw-r--r--libiohelp/iouser-restrict.c83
-rw-r--r--libiohelp/return-buffer.c54
-rw-r--r--libiohelp/shared.c33
11 files changed, 552 insertions, 49 deletions
diff --git a/libiohelp/ChangeLog b/libiohelp/ChangeLog
deleted file mode 100644
index b890e9a8..00000000
--- a/libiohelp/ChangeLog
+++ /dev/null
@@ -1,37 +0,0 @@
-Thu May 9 12:42:51 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu>
-
- * Makefile: All occurrences of `ioserver' replaced with `iohelp'.
-
-Mon May 6 16:27:20 1996 Michael I. Bushnell, p/BSG <mib@gnu.ai.mit.edu>
-
- * iohelp.h: Renamed from `ioserver.h'. All local includes
- updated.
- * get_conch.c: All occurrences of `ioserver' replaced with
- `iohelp'.
- * handle_io_get_conch.c: Likewise.
- * handle_io_release_conch.c: Likewise.
- * initialize_conch.c: Likewise.
- * verify_user_conch.c: Likewise.
- * iohelp.h: Likewise.
-
-Mon Oct 9 14:57:48 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
-
- * Makefile: Specify shared library dependencies.
-
-Thu Jul 6 15:35:56 1995 Michael I Bushnell <mib@duality.gnu.ai.mit.edu>
-
- * Makefile: Removed dependencies that are now automatically
- generated.
-
-Fri Jul 22 11:43:56 1994 Michael I Bushnell <mib@geech.gnu.ai.mit.edu>
-
- * Makefile: Converted to new scheme.
-
-Tue Jul 5 14:13:09 1994 Michael I Bushnell (mib@churchy.gnu.ai.mit.edu)
-
- * Makefile (TAGSHDRS): New variable.
-
-Thu May 5 07:48:45 1994 Roland McGrath (roland@churchy.gnu.ai.mit.edu)
-
- * Makefile: Change uses of $(headers) to $(includedir).
-
diff --git a/libiohelp/Makefile b/libiohelp/Makefile
index 9dfc8ca4..ba73282b 100644
--- a/libiohelp/Makefile
+++ b/libiohelp/Makefile
@@ -1,5 +1,5 @@
-#
-# Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation
+# Copyright (C) 1993, 1994, 1995, 1996, 1998, 2002, 2008 Free Software
+# Foundation, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
@@ -19,13 +19,13 @@ dir := libiohelp
makemode := library
SRCS = get_conch.c handle_io_get_conch.c handle_io_release_conch.c \
- initialize_conch.c verify_user_conch.c
-OBJS = get_conch.o handle_io_get_conch.o handle_io_release_conch.o \
- initialize_conch.o verify_user_conch.o
-LCLHDRS = iohelp.h
+ initialize_conch.c verify_user_conch.c iouser-create.c \
+ iouser-dup.c iouser-reauth.c iouser-free.c iouser-restrict.c \
+ shared.c return-buffer.c
+OBJS = $(SRCS:.c=.o)
+LCLHDRS = iohelp.h
+HURDLIBS = threads shouldbeinlibc
libname = libiohelp
installhdrs = iohelp.h
include ../Makeconf
-
-libfshelp.so: ../libthreads/libthreads.so
diff --git a/libiohelp/handle_io_release_conch.c b/libiohelp/handle_io_release_conch.c
index fa95a6e5..8a6bd32d 100644
--- a/libiohelp/handle_io_release_conch.c
+++ b/libiohelp/handle_io_release_conch.c
@@ -23,13 +23,16 @@
void
iohelp_handle_io_release_conch (struct conch *c, void *user)
{
-
+ struct shared_io *user_sh = c->holder_shared_page;
+
+ spin_lock (&user_sh->lock);
if (c->holder_shared_page->conch_status != USER_HAS_NOT_CONCH)
{
c->holder_shared_page->conch_status = USER_HAS_NOT_CONCH;
iohelp_fetch_shared_data (c->holder);
}
-
+ spin_unlock (&user_sh->lock);
+
if (c->holder == user)
{
c->holder = 0;
diff --git a/libiohelp/iohelp.h b/libiohelp/iohelp.h
index 2897653d..a52d5985 100644
--- a/libiohelp/iohelp.h
+++ b/libiohelp/iohelp.h
@@ -1,5 +1,5 @@
-/*
- Copyright (C) 1993, 1994, 1996 Free Software Foundation
+/* Library providing helper functions for io servers.
+ Copyright (C) 1993,94,96,98,2001,02 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -64,4 +64,70 @@ void iohelp_fetch_shared_data (void *);
void iohelp_put_shared_data (void *);
+
+/* User identification */
+
+#include <idvec.h>
+
+struct iouser
+{
+ struct idvec *uids, *gids;
+ void *hook; /* Never used by iohelp library */
+};
+
+/* Return a copy of IOUSER in CLONE. On error, *CLONE is set to NULL. */
+error_t iohelp_dup_iouser (struct iouser **clone, struct iouser *iouser);
+
+/* Free a reference to IOUSER. */
+void iohelp_free_iouser (struct iouser *iouser);
+
+/* Create a new IOUSER in USER for the specified idvecs. On error, *USER
+ is set to NULL. */
+error_t iohelp_create_iouser (struct iouser **user, struct idvec *uids,
+ struct idvec *gids);
+
+/* Create a new IOUSER in USER for the specified arrays. On error, *USER
+ is set to NULL. */
+error_t iohelp_create_complex_iouser (struct iouser **user,
+ const uid_t *uids, int nuids,
+ const gid_t *gids, int ngids);
+
+/* Create a new IOUSER in USER for the specified uid and gid. On error,
+ *USER is set to NULL. */
+error_t iohelp_create_simple_iouser (struct iouser **user,
+ uid_t uid, gid_t gid);
+
+/* Create a new IOUSER in USER with no identity. On error, *USER is set
+ to NULL. */
+error_t iohelp_create_empty_iouser (struct iouser **user);
+
+/* Create a new IOUSER in NEW_USER that restricts OLD_USER to the subset
+ specified by the two ID lists. This is appropriate for implementing
+ io_restrict_auth. */
+error_t iohelp_restrict_iouser (struct iouser **new_user,
+ const struct iouser *old_user,
+ const uid_t *uids, int nuids,
+ const gid_t *gids, int ngids);
+
+/* Conduct a reauthentication transaction, returning a new iouser in
+ USER. AUTHSERVER is the I/O servers auth port. The rendezvous port
+ provided by the user is REND_PORT. If the transaction cannot be
+ completed, return zero, unless PERMIT_FAILURE is non-zero. If
+ PERMIT_FAILURE is nonzero, then should the transaction fail, return
+ an iouser that has no ids. The new port to be sent to the user is
+ newright. On error, *USER is set to NULL. */
+error_t iohelp_reauth (struct iouser **user, auth_t authserver,
+ mach_port_t rend_port, mach_port_t newright,
+ int permit_failure);
+
+
+/* Puts data from the malloced buffer BUF, LEN bytes long, into RBUF & RLEN,
+ suitable for returning from a mach rpc. If LEN > 0, BUF is freed,
+ regardless of whether an error is returned or not. */
+error_t iohelp_return_malloced_buffer (char *buf, size_t len,
+ char **rbuf,
+ mach_msg_type_number_t *rlen);
+
+
+
#endif
diff --git a/libiohelp/iouser-create.c b/libiohelp/iouser-create.c
new file mode 100644
index 00000000..f1dd2f0e
--- /dev/null
+++ b/libiohelp/iouser-create.c
@@ -0,0 +1,111 @@
+/*
+ Copyright (C) 1996,2001,02 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "iohelp.h"
+
+error_t
+iohelp_create_iouser (struct iouser **user, struct idvec *uids,
+ struct idvec *gids)
+{
+ struct iouser *new;
+ *user = new = malloc (sizeof (struct iouser));
+ if (!new)
+ return ENOMEM;
+
+ new->uids = uids;
+ new->gids = gids;
+ new->hook = 0;
+
+ return 0;
+}
+
+#define E(err) \
+ do { \
+ if (err) \
+ { \
+ *user = 0; \
+ if (! uids) \
+ return err; \
+ idvec_free (uids); \
+ if (! gids) \
+ return err; \
+ idvec_free (gids); \
+ return err; \
+ } \
+ } while (0)
+
+error_t
+iohelp_create_empty_iouser (struct iouser **user)
+{
+ struct idvec *uids, *gids;
+
+ uids = make_idvec ();
+ if (! uids)
+ E (ENOMEM);
+
+ gids = make_idvec ();
+ if (! gids)
+ E (ENOMEM);
+
+ E (iohelp_create_iouser (user, uids, gids));
+
+ return 0;
+}
+
+error_t
+iohelp_create_simple_iouser (struct iouser **user, uid_t uid, gid_t gid)
+{
+ struct idvec *uids, *gids;
+
+ uids = make_idvec ();
+ if (! uids)
+ E (ENOMEM);
+
+ gids = make_idvec ();
+ if (! gids)
+ E (ENOMEM);
+
+ E (idvec_add (uids, uid));
+ E (idvec_add (gids, gid));
+
+ E (iohelp_create_iouser (user, uids, gids));
+
+ return 0;
+}
+
+error_t
+iohelp_create_complex_iouser (struct iouser **user,
+ const uid_t *uvec, int nuids,
+ const gid_t *gvec, int ngids)
+{
+ struct idvec *uids, *gids;
+
+ uids = make_idvec ();
+ if (! uids)
+ E (ENOMEM);
+
+ gids = make_idvec ();
+ if (! gids)
+ E (ENOMEM);
+
+ E (idvec_set_ids (uids, uvec, nuids));
+ E (idvec_set_ids (gids, gvec, ngids));
+
+ E (iohelp_create_iouser (user, uids, gids));
+
+ return 0;
+}
diff --git a/libiohelp/iouser-dup.c b/libiohelp/iouser-dup.c
new file mode 100644
index 00000000..9158d0c4
--- /dev/null
+++ b/libiohelp/iouser-dup.c
@@ -0,0 +1,56 @@
+/*
+ Copyright (C) 1996,2001 Free Software Foundation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "iohelp.h"
+
+error_t
+iohelp_dup_iouser (struct iouser **clone, struct iouser *iouser)
+{
+ struct iouser *new;
+ error_t err = 0;
+
+ *clone = new = malloc (sizeof (struct iouser));
+ if (!new)
+ return ENOMEM;
+
+ new->uids = make_idvec ();
+ new->gids = make_idvec ();
+ new->hook = 0;
+ if (!new->uids || !new->gids)
+ {
+ err = ENOMEM;
+ goto lose;
+ }
+
+ err = idvec_set (new->uids, iouser->uids);
+ if (!err)
+ err = idvec_set (new->gids, iouser->gids);
+
+ if (err)
+ {
+ lose:
+ if (new->uids)
+ idvec_free (new->uids);
+ if (new->gids)
+ idvec_free (new->gids);
+ free (new);
+ *clone = 0;
+ return err;
+ }
+
+ return 0;
+}
diff --git a/libiohelp/iouser-free.c b/libiohelp/iouser-free.c
new file mode 100644
index 00000000..4cfdc954
--- /dev/null
+++ b/libiohelp/iouser-free.c
@@ -0,0 +1,28 @@
+/*
+ Copyright (C) 1996 Free Software Foundation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "iohelp.h"
+
+void
+iohelp_free_iouser (struct iouser *iouser)
+{
+ idvec_free (iouser->uids);
+ idvec_free (iouser->gids);
+ free (iouser);
+}
+
+
diff --git a/libiohelp/iouser-reauth.c b/libiohelp/iouser-reauth.c
new file mode 100644
index 00000000..4125cfb8
--- /dev/null
+++ b/libiohelp/iouser-reauth.c
@@ -0,0 +1,106 @@
+/*
+ Copyright (C) 1996,99,2001,02 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "iohelp.h"
+#include <hurd/auth.h>
+#include <sys/mman.h>
+
+/* Conduct a reauthentication transaction, returning a new iouser.
+ AUTHSERVER is the I/O servers auth port. The rendezvous port
+ provided by the user is REND_PORT. If the transaction cannot be
+ completed, return zero, unless PERMIT_FAILURE is non-zero. If
+ PERMIT_FAILURE is nonzero, then should the transaction fail, return
+ an iouser that has no ids. The new port to be sent to the user is
+ newright. */
+error_t iohelp_reauth (struct iouser **user,
+ auth_t authserver, mach_port_t rend_port,
+ mach_port_t newright, int permit_failure)
+{
+ uid_t gubuf[20], ggbuf[20], aubuf[20], agbuf[20];
+ uid_t *gen_uids, *gen_gids, *aux_uids, *aux_gids;
+ size_t genuidlen, gengidlen, auxuidlen, auxgidlen;
+ error_t err;
+ struct iouser *new;
+
+ *user = new = malloc (sizeof (struct iouser));
+ if (!new)
+ return ENOMEM;
+
+ new->uids = make_idvec ();
+ new->gids = make_idvec ();
+ if (!new->uids || !new->gids)
+ {
+ if (new->uids)
+ idvec_free (new->uids);
+ if (new->gids)
+ idvec_free (new->gids);
+ free (new);
+ return ENOMEM;
+ }
+
+ genuidlen = gengidlen = auxuidlen = auxgidlen = 20;
+ gen_uids = gubuf;
+ gen_gids = ggbuf;
+ aux_uids = aubuf;
+ aux_gids = agbuf;
+
+ do
+ err = auth_server_authenticate (authserver,
+ rend_port,
+ MACH_MSG_TYPE_COPY_SEND,
+ newright,
+ MACH_MSG_TYPE_COPY_SEND,
+ &gen_uids, &genuidlen,
+ &aux_uids, &auxuidlen,
+ &gen_gids, &gengidlen,
+ &aux_gids, &auxgidlen);
+ while (err == EINTR);
+
+ if (err)
+ {
+ if (permit_failure)
+ genuidlen = gengidlen = 0;
+ else
+ goto out;
+ }
+
+ err = idvec_set_ids (new->uids, gen_uids, genuidlen);
+ if (!err)
+ err = idvec_set_ids (new->gids, gen_gids, gengidlen);
+
+ if (gubuf != gen_uids)
+ munmap ((caddr_t) gen_uids, genuidlen * sizeof (uid_t));
+ if (ggbuf != gen_gids)
+ munmap ((caddr_t) gen_gids, gengidlen * sizeof (uid_t));
+ if (aubuf != aux_uids)
+ munmap ((caddr_t) aux_uids, auxuidlen * sizeof (uid_t));
+ if (agbuf != aux_gids)
+ munmap ((caddr_t) aux_gids, auxgidlen * sizeof (uid_t));
+
+ if (err)
+ {
+ out:
+ idvec_free (new->uids);
+ idvec_free (new->gids);
+ free (new);
+ *user = 0;
+ return err;
+ }
+
+ *user = new;
+ return 0;
+}
diff --git a/libiohelp/iouser-restrict.c b/libiohelp/iouser-restrict.c
new file mode 100644
index 00000000..853820ea
--- /dev/null
+++ b/libiohelp/iouser-restrict.c
@@ -0,0 +1,83 @@
+/* iohelp_restrict_iouser -- helper for io_restrict_auth implementations
+ Copyright (C) 2002 Free Software Foundation
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include "iohelp.h"
+
+/* Tell if the array LIST (of size N) contains a member equal to QUERY. */
+static inline int
+listmember (const uid_t *list, int query, int n)
+{
+ int i;
+ for (i = 0; i < n; i++)
+ if (list[i] == query)
+ return 1;
+ return 0;
+}
+
+error_t
+iohelp_restrict_iouser (struct iouser **new_user,
+ const struct iouser *old_user,
+ const uid_t *uids, int nuids,
+ const gid_t *gids, int ngids)
+{
+ if (idvec_contains (old_user->uids, 0))
+ /* OLD_USER has root access, and so may use any ids. */
+ return iohelp_create_complex_iouser (new_user, uids, nuids, gids, ngids);
+ else
+ {
+ struct idvec *uvec, *gvec;
+ int i;
+ error_t err;
+
+ uvec = make_idvec ();
+ if (! uvec)
+ return ENOMEM;
+
+ gvec = make_idvec ();
+ if (! gvec)
+ {
+ idvec_free (uvec);
+ return ENOMEM;
+ }
+
+ /* Otherwise, use any of the requested ids that OLD_USER already has. */
+ for (i = 0; i < old_user->uids->num; i++)
+ if (listmember (uids, old_user->uids->ids[i], nuids))
+ {
+ err = idvec_add (uvec, old_user->uids->ids[i]);
+ if (err)
+ goto out;
+ }
+ for (i = 0; i < old_user->gids->num; i++)
+ if (listmember (gids, old_user->gids->ids[i], ngids))
+ {
+ err = idvec_add (gvec, old_user->gids->ids[i]);
+ if (err)
+ goto out;
+ }
+
+ err = iohelp_create_iouser (new_user, uvec, gvec);
+
+ if (err)
+ {
+ out:
+ idvec_free (uvec);
+ idvec_free (gvec);
+ }
+ return err;
+ }
+}
diff --git a/libiohelp/return-buffer.c b/libiohelp/return-buffer.c
new file mode 100644
index 00000000..3095dfb6
--- /dev/null
+++ b/libiohelp/return-buffer.c
@@ -0,0 +1,54 @@
+/* Make a malloced buffer suitable for returning from a mach rpc
+
+ Copyright (C) 1996, 1998, 1999 Free Software Foundation, Inc.
+
+ Written by Miles Bader <miles@gnu.org>
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <string.h>
+#include <mach.h>
+#include <sys/mman.h>
+
+#include "iohelp.h"
+
+/* Puts data from the malloced buffer BUF, LEN bytes long, into RBUF & RLEN,
+ suitable for returning from a mach rpc. If LEN > 0, BUF is freed,
+ regardless of whether an error is returned or not. */
+error_t
+iohelp_return_malloced_buffer (char *buf, size_t len,
+ char **rbuf, mach_msg_type_number_t *rlen)
+{
+ error_t err = 0;
+
+ if (*rlen < len)
+ {
+ *rbuf = mmap (0, len, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0);
+ err = (*rbuf == (char *) -1) ? errno : 0;
+ }
+ if (! err)
+ {
+ if (len)
+ bcopy (buf, *rbuf, len);
+ *rlen = len;
+ }
+
+ if (len > 0)
+ free (buf);
+
+ return err;
+}
diff --git a/libiohelp/shared.c b/libiohelp/shared.c
new file mode 100644
index 00000000..082b526b
--- /dev/null
+++ b/libiohelp/shared.c
@@ -0,0 +1,33 @@
+/* Default functions
+ Copyright (C) 1996, 2002 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+
+#include "iohelp.h"
+
+/* These definitions exist to satisfy the linker. */
+
+void __attribute__ ((weak))
+iohelp_fetch_shared_data (void *foo)
+{
+ abort ();
+}
+
+void __attribute__ ((weak))
+iohelp_put_shared_data (void *foo)
+{
+ abort ();
+}