/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <strings.h>
/*
* Password file editor with locking.
*/
static int copyfile(char *, char *);
static int sanity_check(char *, time_t *, char *);
static int validsh(char *);
int
main(void)
{
int fd;
char *editor;
int ok = 0;
char c;
if (editor == 0)
if (editor == 0)
(void)umask(0077);
goto bad;
}
goto bad;
"vipw: can't stat ptemp file, %s unchanged\n",
passwd);
goto bad;
}
goto bad;
goto bad;
}
ok++;
"Press 'e' to edit the shadow file for consistency,\n 'q' to quit: ");
if ((c = getchar()) == 'q') {
perror("chmod");
goto bad;
}
perror("rename");
goto bad;
}
perror("chown");
}
goto bad;
} else if (c == 'e') {
"vipw: can't stat shadow file.\n");
goto bad;
}
goto bad;
"vipw: can't stat stmp file.\n");
goto bad;
}
goto bad;
ok++;
perror("chmod");
goto bad;
}
perror("chmod");
goto bad;
}
perror("rename");
goto bad;
}
perror("chown");
}
perror("rename");
goto bad;
perror("chown");
}
}
}
bad:
return (ok ? 0 : 1);
/* NOTREACHED */
}
int
{
int fd;
if (fd < 0) {
exit(1);
}
exit(1);
}
return( 1 );
}
return( 1 );
}
return( 0 );
}
int
{
}
return(1);
}
int
{
int ret = 0;
setusershell();
ret = 1;
break;
}
}
endusershell();
return(ret);
}
/*
* sanity checks
* return 0 if ok, 1 otherwise
*/
int
{
int i, ok = 0;
char *ldir;
int isshadow = 0;
isshadow = 1;
/* sanity checks */
"vipw: can't stat %s file, %s unchanged\n",
return(1);
}
return(1);
}
"vipw: can't reopen %s file, %s unchanged\n",
return(1);
}
char *cp;
if (cp == 0)
continue; /* ??? allow very long lines
* and passwd files that do
* not end in '\n' ???
*/
*cp = '\0';
if (cp == 0) /* lines without colon
* separated fields
*/
continue;
*cp = '\0';
continue;
/* root password */
*cp = ':';
if (cp == 0)
goto bad_root;
/* root uid for password */
if (!isshadow)
buf);
break;
}
/* root uid for passwd and sp_lstchg for shadow */
if (cp == 0)
goto bad_root;
/* root's gid for passwd and sp_min for shadow*/
if (cp == 0)
goto bad_root;
/* root's gecos for passwd and sp_max for shadow*/
if (isshadow) {
for (i=0; i<3; i++)
goto bad_root;
} else {
if (cp == 0) {
"Missing fields in root entry:\n%s\n", buf);
break;
}
}
if (!isshadow) {
/* root's login directory */
if (cp == 0)
goto bad_root;
*cp = '\0';
*cp = ':';
"root login dir doesn't exist:\n%s\n",
buf);
break;
*cp = ':';
"root login dir is not a directory:\n%s\n",
buf);
break;
}
*cp = ':';
/* root's login shell */
++cp;
"Invalid root shell:\n%s\n", buf);
break;
}
}
ok++;
}
if (ok)
return(0);
else {
"vipw: you mangled the %s file, %s unchanged\n",
return(1);
}
}