From a2529808d1aaf878eb6fff54ab491bd3d47db894 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Sat, 16 Jun 2001 20:22:14 +0000 Subject: 2001-04-21 Neal H Walfield * iohelp.h (iohelp_create_iouser): Change declaration such that as error_t is now returned and the iouser is a parameter. (iohelp_create_empty_iouser): New funtion. (iohelp_create_simple_iouser): New function. (iohelp_create_complex_iouser): New funtion. * iouser-create.c (iohelp_create_iouser): Implement new semantics. (iohelp_create_empty_iouser): Implement new function. (iohelp_create_simple_iouser): Implement new function. (iohelp_create_complex_iouser): Implement new function. * iouser-dup.c (iohelp_dup_iouser): Implement new semantics. * iouser-reauth.c (iohelp_reauth): Implement new semantics. --- libiohelp/iohelp.h | 38 ++++++++++++++------ libiohelp/iouser-create.c | 90 +++++++++++++++++++++++++++++++++++++++++++---- libiohelp/iouser-dup.c | 21 ++++++----- libiohelp/iouser-reauth.c | 20 ++++++----- 4 files changed, 137 insertions(+), 32 deletions(-) diff --git a/libiohelp/iohelp.h b/libiohelp/iohelp.h index 13af41e5..71adb15f 100644 --- a/libiohelp/iohelp.h +++ b/libiohelp/iohelp.h @@ -1,5 +1,5 @@ /* Library providing helper functions for io servers. - Copyright (C) 1993, 94, 96, 98 Free Software Foundation, Inc. + Copyright (C) 1993,94,96,98,2001 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 @@ -75,24 +75,42 @@ struct iouser void *hook; /* Never used by iohelp library */ }; -/* Return a copy of IOUSER. */ -struct iouser *iohelp_dup_iouser (struct iouser *iouser); +/* 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 for the specified idvecs */ -struct iouser *iohelp_create_iouser (struct idvec *uids, struct idvec *gids); +/* 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); -/* Conduct a reauthentication transaction, returning a new iouser. - AUTHSERVER is the I/O servers auth port. The rendezvous port +/* 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, + uid_t *uids, int nuids, + 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); + +/* 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. */ -struct iouser *iohelp_reauth (auth_t authserver, mach_port_t rend_port, - mach_port_t newright, int permit_failure); + 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, diff --git a/libiohelp/iouser-create.c b/libiohelp/iouser-create.c index fab77787..c67cff77 100644 --- a/libiohelp/iouser-create.c +++ b/libiohelp/iouser-create.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1996 Free Software Foundation + 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 @@ -17,17 +17,95 @@ #include "iohelp.h" -struct iouser * -iohelp_create_iouser (struct idvec *uids, struct idvec *gids) +error_t +iohelp_create_iouser (struct iouser **user, struct idvec *uids, + struct idvec *gids) { struct iouser *new; - new = malloc (sizeof (struct iouser)); + *user = new = malloc (sizeof (struct iouser)); if (!new) - return 0; + return ENOMEM; new->uids = uids; new->gids = gids; new->hook = 0; - return new; + + 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, + uid_t *uvec, int nuids, + 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 index 7bc1f87f..9158d0c4 100644 --- a/libiohelp/iouser-dup.c +++ b/libiohelp/iouser-dup.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1996 Free Software Foundation + 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 @@ -17,21 +17,24 @@ #include "iohelp.h" -struct iouser * -iohelp_dup_iouser (struct iouser *iouser) +error_t +iohelp_dup_iouser (struct iouser **clone, struct iouser *iouser) { struct iouser *new; error_t err = 0; - new = malloc (sizeof (struct iouser)); + *clone = new = malloc (sizeof (struct iouser)); if (!new) - return 0; + return ENOMEM; new->uids = make_idvec (); new->gids = make_idvec (); new->hook = 0; if (!new->uids || !new->gids) - goto lose; + { + err = ENOMEM; + goto lose; + } err = idvec_set (new->uids, iouser->uids); if (!err) @@ -45,7 +48,9 @@ iohelp_dup_iouser (struct iouser *iouser) if (new->gids) idvec_free (new->gids); free (new); - return 0; + *clone = 0; + return err; } - return new; + + return 0; } diff --git a/libiohelp/iouser-reauth.c b/libiohelp/iouser-reauth.c index 3514b5d8..2139bcc6 100644 --- a/libiohelp/iouser-reauth.c +++ b/libiohelp/iouser-reauth.c @@ -1,5 +1,5 @@ /* - Copyright (C) 1996, 1999 Free Software Foundation + Copyright (C) 1996,99,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 @@ -26,8 +26,9 @@ 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. */ -struct iouser *iohelp_reauth (auth_t authserver, mach_port_t rend_port, - mach_port_t newright, int permit_failure) +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; @@ -35,9 +36,9 @@ struct iouser *iohelp_reauth (auth_t authserver, mach_port_t rend_port, error_t err; struct iouser *new; - new = malloc (sizeof (struct iouser)); + *user = new = malloc (sizeof (struct iouser)); if (!new) - return 0; + return ENOMEM; new->uids = make_idvec (); new->gids = make_idvec (); @@ -48,7 +49,7 @@ struct iouser *iohelp_reauth (auth_t authserver, mach_port_t rend_port, if (new->gids) idvec_free (new->gids); free (new); - return 0; + return ENOMEM; } genuidlen = gengidlen = auxuidlen = auxgidlen = 20; @@ -96,7 +97,10 @@ struct iouser *iohelp_reauth (auth_t authserver, mach_port_t rend_port, idvec_free (new->uids); idvec_free (new->gids); free (new); - return 0; + *user = 0; + return err; } - return new; + + *user = new; + return 0; } -- cgit v1.2.3