2008-04-27 00:40:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 , Michael Meskes
|
|
|
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2002 - 2006, Tomasz Kłoczko
|
|
|
|
* 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 11:44:02 +00:00
|
|
|
/*
|
|
|
|
* grpunconv - update /etc/group with information from /etc/gshadow.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-10 23:46:11 +00:00
|
|
|
#ident "$Id$"
|
2007-10-07 11:47:01 +00:00
|
|
|
|
2007-10-07 11:44:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <grp.h>
|
2007-10-07 11:47:22 +00:00
|
|
|
#include "nscd.h"
|
2007-10-07 11:44:02 +00:00
|
|
|
#include "prototypes.h"
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
#include "groupio.h"
|
|
|
|
#include "sgroupio.h"
|
2007-10-07 11:47:01 +00:00
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2007-10-07 11:44:02 +00:00
|
|
|
static int group_locked = 0;
|
|
|
|
static int gshadow_locked = 0;
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 11:44:59 +00:00
|
|
|
static void fail_exit (int);
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
static void fail_exit (int status)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
|
|
|
if (group_locked)
|
2007-10-07 11:44:59 +00:00
|
|
|
gr_unlock ();
|
2007-10-07 11:44:02 +00:00
|
|
|
if (gshadow_locked)
|
2007-10-07 11:44:59 +00:00
|
|
|
sgr_unlock ();
|
|
|
|
exit (status);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
int main (int argc, char **argv)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
|
|
|
const struct group *gr;
|
|
|
|
struct group grent;
|
|
|
|
const struct sgrp *sg;
|
|
|
|
char *Prog = argv[0];
|
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
if (!sgr_file_present ())
|
|
|
|
exit (0); /* no /etc/gshadow, nothing to do */
|
2007-10-07 11:44:02 +00:00
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
if (!gr_lock ()) {
|
|
|
|
fprintf (stderr, _("%s: can't lock group file\n"), Prog);
|
|
|
|
fail_exit (5);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
group_locked++;
|
2007-10-07 11:44:59 +00:00
|
|
|
if (!gr_open (O_RDWR)) {
|
|
|
|
fprintf (stderr, _("%s: can't open group file\n"), Prog);
|
|
|
|
fail_exit (1);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
if (!sgr_lock ()) {
|
2007-10-07 11:46:07 +00:00
|
|
|
fprintf (stderr, _("%s: can't lock shadow group file\n"), Prog);
|
2007-10-07 11:44:59 +00:00
|
|
|
fail_exit (5);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
gshadow_locked++;
|
2007-10-07 11:44:59 +00:00
|
|
|
if (!sgr_open (O_RDWR)) {
|
2007-10-07 11:46:07 +00:00
|
|
|
fprintf (stderr, _("%s: can't open shadow group file\n"), Prog);
|
2007-10-07 11:44:59 +00:00
|
|
|
fail_exit (1);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update group passwords if non-shadow password is "x".
|
|
|
|
*/
|
2007-10-07 11:44:59 +00:00
|
|
|
gr_rewind ();
|
|
|
|
while ((gr = gr_next ())) {
|
|
|
|
sg = sgr_locate (gr->gr_name);
|
2007-10-07 11:46:07 +00:00
|
|
|
if (sg && strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) == 0) {
|
2007-10-07 11:44:59 +00:00
|
|
|
/* add password to /etc/group */
|
|
|
|
grent = *gr;
|
2007-10-07 11:44:02 +00:00
|
|
|
grent.gr_passwd = sg->sg_passwd;
|
2007-10-07 11:44:59 +00:00
|
|
|
if (!gr_update (&grent)) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_
|
|
|
|
("%s: can't update entry for group %s\n"),
|
|
|
|
Prog, grent.gr_name);
|
|
|
|
fail_exit (3);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
if (!sgr_close ()) {
|
|
|
|
fprintf (stderr, _("%s: can't update shadow group file\n"),
|
|
|
|
Prog);
|
|
|
|
fail_exit (3);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
if (!gr_close ()) {
|
|
|
|
fprintf (stderr, _("%s: can't update group file\n"), Prog);
|
|
|
|
fail_exit (3);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
if (unlink (SGROUP_FILE) != 0) {
|
|
|
|
fprintf (stderr, _("%s: can't delete shadow group file\n"),
|
|
|
|
Prog);
|
|
|
|
fail_exit (3);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 11:44:59 +00:00
|
|
|
sgr_unlock ();
|
|
|
|
gr_unlock ();
|
2007-10-07 11:46:52 +00:00
|
|
|
|
|
|
|
nscd_flush_cache ("group");
|
|
|
|
|
2007-10-07 11:44:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-10-07 11:44:59 +00:00
|
|
|
#else /* !SHADOWGRP */
|
|
|
|
int main (int argc, char **argv)
|
2007-10-07 11:44:02 +00:00
|
|
|
{
|
2007-10-07 11:44:59 +00:00
|
|
|
fprintf (stderr,
|
2007-10-07 11:46:07 +00:00
|
|
|
"%s: not configured for shadow group support.\n", argv[0]);
|
2007-10-07 11:44:59 +00:00
|
|
|
exit (1);
|
2007-10-07 11:44:02 +00:00
|
|
|
}
|
2007-10-07 11:44:59 +00:00
|
|
|
#endif /* !SHADOWGRP */
|