2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* grpunconv - update /etc/group with information from /etc/gshadow.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1996, Michael Meskes <meskes@debian.org>
|
|
|
|
* using sources from Marek Michalkiewicz
|
|
|
|
* <marekm@i17linuxb.ists.pwr.wroc.pl>
|
2007-10-07 17:14:59 +05:30
|
|
|
* This program may be freely used and distributed. If you improve
|
|
|
|
* it, please send me your changes. Thanks!
|
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
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <grp.h>
|
2007-10-07 17:17:22 +05:30
|
|
|
#include "nscd.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
#include "groupio.h"
|
|
|
|
#include "sgroupio.h"
|
2007-10-07 17:17:01 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2007-10-07 17:14:02 +05:30
|
|
|
static int group_locked = 0;
|
|
|
|
static int gshadow_locked = 0;
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:14:59 +05:30
|
|
|
static void fail_exit (int);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void fail_exit (int status)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
if (group_locked)
|
2007-10-07 17:14:59 +05:30
|
|
|
gr_unlock ();
|
2007-10-07 17:14:02 +05:30
|
|
|
if (gshadow_locked)
|
2007-10-07 17:14:59 +05:30
|
|
|
sgr_unlock ();
|
|
|
|
exit (status);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const struct group *gr;
|
|
|
|
struct group grent;
|
|
|
|
const struct sgrp *sg;
|
|
|
|
char *Prog = argv[0];
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!sgr_file_present ())
|
|
|
|
exit (0); /* no /etc/gshadow, nothing to do */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_lock ()) {
|
|
|
|
fprintf (stderr, _("%s: can't lock group file\n"), Prog);
|
|
|
|
fail_exit (5);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
group_locked++;
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_open (O_RDWR)) {
|
|
|
|
fprintf (stderr, _("%s: can't open group file\n"), Prog);
|
|
|
|
fail_exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!sgr_lock ()) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: can't lock shadow group file\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
fail_exit (5);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
gshadow_locked++;
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!sgr_open (O_RDWR)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("%s: can't open shadow group file\n"), Prog);
|
2007-10-07 17:14:59 +05:30
|
|
|
fail_exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update group passwords if non-shadow password is "x".
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
gr_rewind ();
|
|
|
|
while ((gr = gr_next ())) {
|
|
|
|
sg = sgr_locate (gr->gr_name);
|
2007-10-07 17:16:07 +05:30
|
|
|
if (sg && strcmp (gr->gr_passwd, SHADOW_PASSWD_STRING) == 0) {
|
2007-10-07 17:14:59 +05:30
|
|
|
/* add password to /etc/group */
|
|
|
|
grent = *gr;
|
2007-10-07 17:14:02 +05:30
|
|
|
grent.gr_passwd = sg->sg_passwd;
|
2007-10-07 17:14:59 +05:30
|
|
|
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 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!sgr_close ()) {
|
|
|
|
fprintf (stderr, _("%s: can't update shadow group file\n"),
|
|
|
|
Prog);
|
|
|
|
fail_exit (3);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!gr_close ()) {
|
|
|
|
fprintf (stderr, _("%s: can't update group file\n"), Prog);
|
|
|
|
fail_exit (3);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (unlink (SGROUP_FILE) != 0) {
|
|
|
|
fprintf (stderr, _("%s: can't delete shadow group file\n"),
|
|
|
|
Prog);
|
|
|
|
fail_exit (3);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sgr_unlock ();
|
|
|
|
gr_unlock ();
|
2007-10-07 17:16:52 +05:30
|
|
|
|
|
|
|
nscd_flush_cache ("group");
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#else /* !SHADOWGRP */
|
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr,
|
2007-10-07 17:16:07 +05:30
|
|
|
"%s: not configured for shadow group support.\n", argv[0]);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* !SHADOWGRP */
|