2008-04-27 06:10:09 +05:30
|
|
|
/*
|
|
|
|
* Copyright (c) 1990 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2001 , Michał Moskal
|
|
|
|
* Copyright (c) 2005 , Tomasz Kłoczko
|
2009-04-20 16:59:17 +05:30
|
|
|
* Copyright (c) 2007 - 2009, Nicolas François
|
2008-04-27 06:10:09 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the copyright holders or contributors may not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2009-04-28 01:48:00 +05:30
|
|
|
#include <assert.h>
|
2008-01-26 23:11:20 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#include "defines.h"
|
|
|
|
#include "commonio.h"
|
2007-11-24 05:58:25 +05:30
|
|
|
#include "getdef.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "groupio.h"
|
2008-01-05 20:05:13 +05:30
|
|
|
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
static /*@null@*/struct commonio_entry *merge_group_entries (
|
2009-04-25 04:56:31 +05:30
|
|
|
/*@null@*/ /*@returned@*/struct commonio_entry *gr1,
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
/*@null@*/struct commonio_entry *gr2);
|
2008-01-06 19:08:16 +05:30
|
|
|
static int split_groups (unsigned int max_members);
|
2007-11-23 05:37:59 +05:30
|
|
|
static int group_open_hook (void);
|
|
|
|
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
static /*@null@*/ /*@only@*/void *group_dup (const void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct group *gr = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
|
|
|
return __gr_dup (gr);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
* libmisc/utmp.c, libmisc/age.c, libmisc/shell.c, lib/groupio.c,
lib/groupio.h, lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c,
lib/pwio.c, lib/commonio.c, lib/shadowio.h, lib/pwio.h,
lib/commonio.h, lib/prototypes.h: Added splint annotations.
2009-04-23 02:51:14 +05:30
|
|
|
static void group_free (/*@out@*/ /*@only@*/void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
struct group *gr = ent;
|
|
|
|
|
2009-04-22 03:44:10 +05:30
|
|
|
gr_free (gr);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static const char *group_getname (const void *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct group *gr = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
return gr->gr_name;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void *group_parse (const char *line)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return (void *) sgetgrent (line);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static int group_put (const void *ent, FILE * file)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct group *gr = ent;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
|
|
|
return (putgrent (gr, file) == -1) ? -1 : 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-11-23 05:37:59 +05:30
|
|
|
static int group_close_hook (void)
|
|
|
|
{
|
|
|
|
unsigned int max_members = getdef_unum("MAX_MEMBERS_PER_GROUP", 0);
|
|
|
|
|
2008-06-14 03:09:24 +05:30
|
|
|
if (0 == max_members) {
|
2007-11-23 05:37:59 +05:30
|
|
|
return 1;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
|
|
|
|
return split_groups (max_members);
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
static struct commonio_ops group_ops = {
|
|
|
|
group_dup,
|
|
|
|
group_free,
|
|
|
|
group_getname,
|
|
|
|
group_parse,
|
|
|
|
group_put,
|
|
|
|
fgetsx,
|
2007-11-23 05:37:59 +05:30
|
|
|
fputsx,
|
|
|
|
group_open_hook,
|
|
|
|
group_close_hook
|
2007-10-07 17:14:02 +05:30
|
|
|
};
|
|
|
|
|
2009-04-25 04:56:31 +05:30
|
|
|
static /*@owned@*/struct commonio_db group_db = {
|
2007-10-07 17:16:07 +05:30
|
|
|
GROUP_FILE, /* filename */
|
|
|
|
&group_ops, /* ops */
|
|
|
|
NULL, /* fp */
|
2007-11-20 01:55:36 +05:30
|
|
|
#ifdef WITH_SELINUX
|
|
|
|
NULL, /* scontext */
|
|
|
|
#endif
|
2007-10-07 17:16:07 +05:30
|
|
|
NULL, /* head */
|
|
|
|
NULL, /* tail */
|
|
|
|
NULL, /* cursor */
|
2008-05-26 14:04:04 +05:30
|
|
|
false, /* changed */
|
|
|
|
false, /* isopen */
|
|
|
|
false, /* locked */
|
|
|
|
false /* readonly */
|
2007-10-07 17:14:02 +05:30
|
|
|
};
|
|
|
|
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
int gr_setdbname (const char *filename)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_setname (&group_db, filename);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
* libmisc/utmp.c, libmisc/age.c, libmisc/shell.c, lib/groupio.c,
lib/groupio.h, lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c,
lib/pwio.c, lib/commonio.c, lib/shadowio.h, lib/pwio.h,
lib/commonio.h, lib/prototypes.h: Added splint annotations.
2009-04-23 02:51:14 +05:30
|
|
|
/*@observer@*/const char *gr_dbname (void)
|
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
Added *_dbname() functions to retrieve the name of the databases.
* lib/groupio.c, lib/groupio.h, lib/pwio.c, lib/pwio.h,
lib/sgroupio.c, lib/sgroupio.h, lib/shadowio.c, lib/shadowio.h:
*_name() functions renamed *setname().
* src/grpck.c, src/pwck.c: Likewise.
* lib/groupio.h, lib/pwio.h, lib/sgroupio.h, lib/shadowio.h: Added
the name of the arguments to the prototypes.
* src/chage, src/chfn.c, src/chgpasswd.c, src/chpasswd.c,
src/chsh.c, src/gpasswd.c, src/groupadd.c, src/groupdel.c,
src/groupmod.c, src/grpck.c, src/grpconv.c, src/grpunconv.c,
src/newusers.c, src/passwd.c, src/pwck.c, src/pwconv.c,
src/pwunconv.c, src/useradd.c, src/userdel.c, src/usermod.c:
Harmonize the erro & syslog messages in case of failure of the
*_lock(), *_open(), *_close(), *_unlock(), *_remove() functions.
* src/chgpasswd.c, src/chpasswd.c, src/usermod.c: Avoid
capitalized messages.
* src/chpasswd.c, src/useradd.c, src/usermod.c: Harmonize messages
in case of inexistent entries.
* src/usermod.c: Harmonize messages in case of already existing
entries.
* src/newusers.c, src/useradd.c: Simplify PAM error handling.
* src/useradd.c: Report failures to unlock files (stderr, syslog,
and audit). But do not fail (continue).
* src/useradd.c (open_files): Do not report to syslog & audit
failures to lock or open the databases. This might be harmless,
and the logs were not already informed that a change was
requested.
* src/usermod.c: It's not the account which is unlocked, but its
password.
2008-08-06 21:27:31 +05:30
|
|
|
{
|
|
|
|
return group_db.filename;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int gr_lock (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_lock (&group_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int gr_open (int mode)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_open (&group_db, mode);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2009-04-24 02:49:02 +05:30
|
|
|
/*@observer@*/ /*@null@*/const struct group *gr_locate (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_locate (&group_db, name);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2009-04-24 02:49:02 +05:30
|
|
|
/*@observer@*/ /*@null@*/const struct group *gr_locate_gid (gid_t gid)
|
2008-02-03 22:21:08 +05:30
|
|
|
{
|
|
|
|
const struct group *grp;
|
|
|
|
|
|
|
|
gr_rewind ();
|
|
|
|
while ( ((grp = gr_next ()) != NULL)
|
|
|
|
&& (grp->gr_gid != gid)) {
|
|
|
|
}
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int gr_update (const struct group *gr)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_update (&group_db, (const void *) gr);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int gr_remove (const char *name)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_remove (&group_db, name);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int gr_rewind (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_rewind (&group_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2009-04-24 02:49:02 +05:30
|
|
|
/*@observer@*/ /*@null@*/const struct group *gr_next (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_next (&group_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int gr_close (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_close (&group_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
int gr_unlock (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_unlock (&group_db);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void __gr_set_changed (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-05-26 14:04:04 +05:30
|
|
|
group_db.changed = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2009-04-25 04:56:31 +05:30
|
|
|
/*@dependent@*/ /*@null@*/struct commonio_entry *__gr_get_head (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
return group_db.head;
|
|
|
|
}
|
|
|
|
|
2009-04-25 04:56:31 +05:30
|
|
|
/*@observer@*/const struct commonio_db *__gr_get_db (void)
|
2007-10-07 17:14:51 +05:30
|
|
|
{
|
|
|
|
return &group_db;
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
void __gr_del_entry (const struct commonio_entry *ent)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
commonio_del_entry (&group_db, ent);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:51 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static int gr_cmp (const void *p1, const void *p2)
|
2007-10-07 17:14:51 +05:30
|
|
|
{
|
|
|
|
gid_t u1, u2;
|
|
|
|
|
2008-06-14 03:09:24 +05:30
|
|
|
if ((*(struct commonio_entry **) p1)->eptr == NULL) {
|
2007-10-07 17:14:51 +05:30
|
|
|
return 1;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
|
|
|
if ((*(struct commonio_entry **) p2)->eptr == NULL) {
|
2007-10-07 17:14:51 +05:30
|
|
|
return -1;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
|
|
|
|
u1 = ((struct group *) (*(struct commonio_entry **) p1)->eptr)->gr_gid;
|
|
|
|
u2 = ((struct group *) (*(struct commonio_entry **) p2)->eptr)->gr_gid;
|
2007-10-07 17:14:51 +05:30
|
|
|
|
2008-06-14 03:09:24 +05:30
|
|
|
if (u1 < u2) {
|
2007-10-07 17:14:51 +05:30
|
|
|
return -1;
|
2008-06-14 03:09:24 +05:30
|
|
|
} else if (u1 > u2) {
|
2007-10-07 17:14:51 +05:30
|
|
|
return 1;
|
2008-06-14 03:09:24 +05:30
|
|
|
} else {
|
2007-10-07 17:14:51 +05:30
|
|
|
return 0;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2007-10-07 17:14:51 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:25 +05:30
|
|
|
/* Sort entries by GID */
|
2007-10-07 17:16:07 +05:30
|
|
|
int gr_sort ()
|
2007-10-07 17:14:51 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
return commonio_sort (&group_db, gr_cmp);
|
2007-10-07 17:14:51 +05:30
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
|
|
|
|
static int group_open_hook (void)
|
|
|
|
{
|
|
|
|
unsigned int max_members = getdef_unum("MAX_MEMBERS_PER_GROUP", 0);
|
|
|
|
struct commonio_entry *gr1, *gr2;
|
|
|
|
|
2008-06-14 03:09:24 +05:30
|
|
|
if (0 == max_members) {
|
2007-11-23 05:37:59 +05:30
|
|
|
return 1;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
for (gr1 = group_db.head; NULL != gr1; gr1 = gr1->next) {
|
|
|
|
for (gr2 = gr1->next; NULL != gr2; gr2 = gr2->next) {
|
2007-11-23 05:37:59 +05:30
|
|
|
struct group *g1 = (struct group *)gr1->eptr;
|
|
|
|
struct group *g2 = (struct group *)gr2->eptr;
|
|
|
|
if (NULL != g1 &&
|
|
|
|
NULL != g2 &&
|
|
|
|
0 == strcmp (g1->gr_name, g2->gr_name) &&
|
|
|
|
0 == strcmp (g1->gr_passwd, g2->gr_passwd) &&
|
|
|
|
g1->gr_gid == g2->gr_gid) {
|
|
|
|
/* Both group entries refer to the same
|
|
|
|
* group. It is a split group. Merge the
|
|
|
|
* members. */
|
|
|
|
gr1 = merge_group_entries (gr1, gr2);
|
|
|
|
if (NULL == gr1)
|
|
|
|
return 0;
|
|
|
|
/* Unlink gr2 */
|
2008-06-14 03:09:24 +05:30
|
|
|
if (NULL != gr2->next) {
|
2007-11-23 05:37:59 +05:30
|
|
|
gr2->next->prev = gr2->prev;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2009-04-25 04:56:31 +05:30
|
|
|
/* gr2 does not start with head */
|
|
|
|
assert (NULL != gr2->prev);
|
2007-11-23 05:37:59 +05:30
|
|
|
gr2->prev->next = gr2->next;
|
|
|
|
}
|
|
|
|
}
|
2009-04-25 04:56:31 +05:30
|
|
|
assert (NULL != gr1);
|
2007-11-23 05:37:59 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Merge the list of members of the two group entries.
|
|
|
|
*
|
|
|
|
* The commonio_entry arguments shall be group entries.
|
|
|
|
*
|
|
|
|
* You should not merge the members of two groups if they don't have the
|
|
|
|
* same name, password and gid.
|
|
|
|
*
|
|
|
|
* It merge the members of the second entry in the first one, and return
|
2008-01-26 23:11:20 +05:30
|
|
|
* the modified first entry on success, or NULL on failure (with errno
|
2007-11-23 05:37:59 +05:30
|
|
|
* set).
|
|
|
|
*/
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
static /*@null@*/struct commonio_entry *merge_group_entries (
|
2009-04-25 04:56:31 +05:30
|
|
|
/*@null@*/ /*@returned@*/struct commonio_entry *gr1,
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
/*@null@*/struct commonio_entry *gr2)
|
2007-11-23 05:37:59 +05:30
|
|
|
{
|
|
|
|
struct group *gptr1;
|
|
|
|
struct group *gptr2;
|
|
|
|
char **new_members;
|
2008-06-14 03:09:24 +05:30
|
|
|
size_t members = 0;
|
2007-11-23 05:37:59 +05:30
|
|
|
char *new_line;
|
2008-06-14 03:09:24 +05:30
|
|
|
size_t new_line_len, i;
|
2007-11-23 05:37:59 +05:30
|
|
|
if (NULL == gr2 || NULL == gr1) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gptr1 = (struct group *)gr1->eptr;
|
|
|
|
gptr2 = (struct group *)gr2->eptr;
|
|
|
|
if (NULL == gptr2 || NULL == gptr1) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Concatenate the 2 lines */
|
|
|
|
new_line_len = strlen (gr1->line) + strlen (gr2->line) +1;
|
|
|
|
new_line = (char *)malloc ((new_line_len + 1) * sizeof(char*));
|
|
|
|
if (NULL == new_line) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
snprintf(new_line, new_line_len, "%s\n%s", gr1->line, gr2->line);
|
|
|
|
new_line[new_line_len] = '\0';
|
|
|
|
|
|
|
|
/* Concatenate the 2 list of members */
|
|
|
|
for (i=0; NULL != gptr1->gr_mem[i]; i++);
|
|
|
|
members += i;
|
|
|
|
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
|
|
|
char **pmember = gptr1->gr_mem;
|
|
|
|
while (NULL != *pmember) {
|
2008-06-14 03:09:24 +05:30
|
|
|
if (0 == strcmp(*pmember, gptr2->gr_mem[i])) {
|
2007-11-23 05:37:59 +05:30
|
|
|
break;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
pmember++;
|
|
|
|
}
|
2008-06-14 03:09:24 +05:30
|
|
|
if (NULL == *pmember) {
|
2007-11-23 05:37:59 +05:30
|
|
|
members++;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
}
|
|
|
|
new_members = (char **)malloc ( (members+1) * sizeof(char*) );
|
|
|
|
if (NULL == new_members) {
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
free (new_line);
|
2007-11-23 05:37:59 +05:30
|
|
|
errno = ENOMEM;
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-14 03:09:24 +05:30
|
|
|
for (i=0; NULL != gptr1->gr_mem[i]; i++) {
|
2007-11-23 05:37:59 +05:30
|
|
|
new_members[i] = gptr1->gr_mem[i];
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
members = i;
|
|
|
|
for (i=0; NULL != gptr2->gr_mem[i]; i++) {
|
|
|
|
char **pmember = new_members;
|
|
|
|
while (NULL != *pmember) {
|
2008-06-14 03:09:24 +05:30
|
|
|
if (0 == strcmp(*pmember, gptr2->gr_mem[i])) {
|
2007-11-23 05:37:59 +05:30
|
|
|
break;
|
2008-06-14 03:09:24 +05:30
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
pmember++;
|
|
|
|
}
|
|
|
|
if (NULL == *pmember) {
|
2008-06-14 03:09:24 +05:30
|
|
|
new_members[members] = gptr2->gr_mem[i];
|
|
|
|
members++;
|
2007-11-23 05:37:59 +05:30
|
|
|
new_members[members] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gr1->line = new_line;
|
|
|
|
gptr1->gr_mem = new_members;
|
|
|
|
|
|
|
|
return gr1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the group database and split the groups which have more members
|
|
|
|
* than specified, if this is the result from a current change.
|
|
|
|
*
|
|
|
|
* Return 0 on failure (errno set) and 1 on success.
|
|
|
|
*/
|
|
|
|
static int split_groups (unsigned int max_members)
|
|
|
|
{
|
|
|
|
struct commonio_entry *gr;
|
|
|
|
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
for (gr = group_db.head; NULL != gr; gr = gr->next) {
|
2007-11-23 05:37:59 +05:30
|
|
|
struct group *gptr = (struct group *)gr->eptr;
|
|
|
|
struct commonio_entry *new;
|
|
|
|
struct group *new_gptr;
|
|
|
|
unsigned int members = 0;
|
2010-03-20 15:51:40 +05:30
|
|
|
int i;
|
2007-11-23 05:37:59 +05:30
|
|
|
|
|
|
|
/* Check if this group must be split */
|
|
|
|
if (!gr->changed)
|
|
|
|
continue;
|
|
|
|
if (NULL == gptr)
|
|
|
|
continue;
|
|
|
|
for (members = 0; NULL != gptr->gr_mem[members]; members++);
|
|
|
|
if (members <= max_members)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
new = (struct commonio_entry *) malloc (sizeof *new);
|
2008-01-02 02:17:31 +05:30
|
|
|
if (NULL == new) {
|
|
|
|
errno = ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
new->eptr = group_dup(gr->eptr);
|
|
|
|
if (NULL == new->eptr) {
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
free (new);
|
2007-11-23 05:37:59 +05:30
|
|
|
errno = ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
new_gptr = (struct group *)new->eptr;
|
|
|
|
new->line = NULL;
|
2008-05-26 14:04:04 +05:30
|
|
|
new->changed = true;
|
2007-11-23 05:37:59 +05:30
|
|
|
|
|
|
|
/* Enforce the maximum number of members on gptr */
|
2010-03-20 15:51:40 +05:30
|
|
|
for (i = max_members; NULL != gptr->gr_mem[i]; i++) {
|
|
|
|
free (gptr->gr_mem[i]);
|
|
|
|
gptr->gr_mem[i] = NULL;
|
|
|
|
}
|
|
|
|
/* Shift all the members */
|
2007-11-23 05:37:59 +05:30
|
|
|
/* The number of members in new_gptr will be check later */
|
2010-03-20 15:51:40 +05:30
|
|
|
for (i = 0; NULL != new_gptr->gr_mem[i + max_members]; i++) {
|
|
|
|
if (NULL != new_gptr->gr_mem[i]) {
|
|
|
|
free (new_gptr->gr_mem[i]);
|
|
|
|
}
|
|
|
|
new_gptr->gr_mem[i] = new_gptr->gr_mem[i + max_members];
|
|
|
|
new_gptr->gr_mem[i + max_members] = NULL;
|
|
|
|
}
|
|
|
|
for (; NULL != new_gptr->gr_mem[i]; i++) {
|
|
|
|
free (new_gptr->gr_mem[i]);
|
|
|
|
new_gptr->gr_mem[i] = NULL;
|
|
|
|
}
|
2007-11-23 05:37:59 +05:30
|
|
|
|
|
|
|
/* insert the new entry in the list */
|
|
|
|
new->prev = gr;
|
|
|
|
new->next = gr->next;
|
|
|
|
gr->next = new;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|