Browse Source

libutil

OPENBSD_2_0
deraadt 28 years ago
parent
commit
a5010d31aa
19 changed files with 1248 additions and 32 deletions
  1. +11
    -8
      src/include/Makefile
  2. +2
    -1
      src/include/pwd.h
  3. +67
    -0
      src/include/util.h
  4. +19
    -3
      src/lib/libutil/Makefile
  5. +58
    -0
      src/lib/libutil/getmaxpartitions.3
  6. +60
    -0
      src/lib/libutil/getmaxpartitions.c
  7. +69
    -0
      src/lib/libutil/getrawpartition.3
  8. +60
    -0
      src/lib/libutil/getrawpartition.c
  9. +107
    -0
      src/lib/libutil/login.3
  10. +2
    -3
      src/lib/libutil/login.c
  11. +2
    -3
      src/lib/libutil/login_tty.c
  12. +4
    -4
      src/lib/libutil/logout.c
  13. +3
    -4
      src/lib/libutil/logwtmp.c
  14. +153
    -0
      src/lib/libutil/openpty.3
  15. +347
    -0
      src/lib/libutil/passwd.c
  16. +9
    -5
      src/lib/libutil/pty.c
  17. +174
    -0
      src/lib/libutil/pw_init.3
  18. +100
    -0
      src/lib/libutil/pw_lock.3
  19. +1
    -1
      src/lib/libutil/shlib_version

+ 11
- 8
src/include/Makefile View File

@ -1,23 +1,26 @@
# $OpenBSD: Makefile,v 1.7 1996/05/06 21:44:19 deraadt Exp $
# $NetBSD: Makefile,v 1.57 1996/04/25 00:55:44 jtc Exp $
# $OpenBSD: Makefile,v 1.8 1996/05/22 11:34:45 deraadt Exp $
# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
# Doing a make install builds /usr/include
#
# The ``rm -rf''s used below are safe because rm doesn't follow symbolic
# links.
# Missing: mp.h
FILES= a.out.h ar.h assert.h bitstring.h bm.h cpio.h ctype.h db.h dirent.h \
disktab.h dlfcn.h elf_abi.h err.h fnmatch.h fstab.h fts.h glob.h \
grp.h ieeefp.h iso646.h kvm.h langinfo.h limits.h link.h locale.h \
disktab.h elf_abi.h err.h fnmatch.h fstab.h fts.h glob.h \
grp.h ieeefp.h iso646.h kvm.h langinfo.h limits.h locale.h \
malloc.h math.h memory.h mpool.h ndbm.h netdb.h netgroup.h nlist.h \
nl_types.h paths.h pwd.h ranlib.h re_comp.h regex.h regexp.h resolv.h \
nl_types.h paths.h poll.h pwd.h ranlib.h re_comp.h regex.h regexp.h \
resolv.h \
search.h setjmp.h sgtty.h signal.h stab.h stddef.h stdio.h stdlib.h \
string.h strings.h struct.h sysexits.h tar.h time.h ttyent.h tzfile.h \
unistd.h utime.h utmp.h vis.h
unistd.h util.h utime.h utmp.h vis.h
.if (${MACHINE_ARCH} != "alpha")
FILES+= dlfcn.h link.h
.endif
MFILES= float.h frame.h stdarg.h varargs.h
LFILES= errno.h fcntl.h syslog.h termios.h


+ 2
- 1
src/include/pwd.h View File

@ -1,4 +1,4 @@
/* $NetBSD: pwd.h,v 1.8 1995/07/28 05:30:52 phil Exp $ */
/* $NetBSD: pwd.h,v 1.9 1996/05/15 21:36:45 jtc Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -49,6 +49,7 @@
#ifndef _POSIX_SOURCE
#define _PATH_PASSWD "/etc/passwd"
#define _PATH_MASTERPASSWD "/etc/master.passwd"
#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
#define _PATH_MP_DB "/etc/pwd.db"
#define _PATH_SMP_DB "/etc/spwd.db"


+ 67
- 0
src/include/util.h View File

@ -0,0 +1,67 @@
/* $NetBSD: util.h,v 1.2 1996/05/16 07:00:22 thorpej Exp $ */
/*-
* Copyright (c) 1995
* The Regents of the University of California. 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#ifndef _UTIL_H_
#define _UTIL_H_
#include <pwd.h>
#include <utmp.h>
#include <termios.h>
#include <sys/ttycom.h>
#include <sys/types.h>
#include <sys/cdefs.h>
__BEGIN_DECLS
void login __P((struct utmp *));
int login_tty __P((int));
int logout __P((const char *));
void logwtmp __P((const char *, const char *, const char *));
int pw_lock __P((int retries));
int pw_mkdb __P((void));
int pw_abort __P((void));
void pw_init __P((void));
void pw_edit __P((int notsetuid, const char *filename));
void pw_prompt __P((void));
void pw_copy __P((int ffd, int tfd, struct passwd *pw));
int pw_scan __P((char *bp, struct passwd *pw, int *flags));
void pw_error __P((const char *name, int err, int eval));
int openpty __P((int *, int *, char *, struct termios *,
struct winsize *));
pid_t forkpty __P((int *, char *, struct termios *, struct winsize *));
int getmaxpartitions __P((void));
int getrawpartition __P((void));
__END_DECLS
#endif /* !_UTIL_H_ */

+ 19
- 3
src/lib/libutil/Makefile View File

@ -1,8 +1,24 @@
# from: @(#)Makefile 8.1 (Berkeley) 6/4/93
# $Id: Makefile,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $
# $OpenBSD: Makefile,v 1.2 1996/05/22 11:34:58 deraadt Exp $
# $NetBSD: Makefile,v 1.8 1996/05/16 07:03:28 thorpej Exp $
LIB= util
CFLAGS+=-DLIBC_SCCS
SRCS= login.c login_tty.c logout.c logwtmp.c pty.c
SRCS= getmaxpartitions.c getrawpartition.c login.c login_tty.c logout.c \
logwtmp.c passwd.c pty.c
MAN= getmaxpartitions.3 getrawpartition.3 login.3 openpty.3 pw_init.3 \
pw_lock.3
MLINKS+=login.3 logout.3
MLINKS+=login.3 logwtmp.3
MLINKS+=openpty.3 login_tty.3
MLINKS+=openpty.3 forkpty.3
MLINKS+=pw_init.3 pw_edit.3
MLINKS+=pw_init.3 pw_prompt.3
MLINKS+=pw_init.3 pw_copy.3
MLINKS+=pw_init.3 pw_scan.3
MLINKS+=pw_init.3 pw_error.3
MLINKS+=pw_lock.3 pw_mkdb.3
MLINKS+=pw_lock.3 pw_abort.3
.include <bsd.lib.mk>

+ 58
- 0
src/lib/libutil/getmaxpartitions.3 View File

@ -0,0 +1,58 @@
.\" $NetBSD: getmaxpartitions.3,v 1.1 1996/05/16 07:03:30 thorpej Exp $
.\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jason R. Thorpe.
.\"
.\" 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. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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.
.\"
.Dd May 15, 1996
.Dt GETMAXPARTITIONS 3
.Os NetBSD
.Sh NAME
.Nm getmaxpartitions
.Nd get the maximum number of partitions allowed per disk
.Sh SYNOPSIS
.Fd #include <util.h>
.Ft int
.Fn getmaxpartitions void
.Sh DESCRIPTION
.Fn Getmaxpartitions
returns the number of partitions that are allowed per disk on the
system.
.Sh SEE ALSO
.Xr getrawpartition 3 ,
.Xr sysctl 3
.Sh HISTORY
The
.Nm
function call appeared in
.Nx 1.2 .

+ 60
- 0
src/lib/libutil/getmaxpartitions.c View File

@ -0,0 +1,60 @@
/* $NetBSD: getmaxpartitions.c,v 1.1 1996/05/16 07:03:31 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: getmaxpartitions.c,v 1.1 1996/05/16 07:03:31 thorpej Exp $";
#endif
#include <sys/param.h>
#include <sys/sysctl.h>
#include <util.h>
int
getmaxpartitions()
{
int maxpart, mib[2];
size_t varlen;
mib[0] = CTL_KERN;
mib[1] = KERN_MAXPARTITIONS;
varlen = sizeof(maxpart);
if (sysctl(mib, 2, &maxpart, &varlen, NULL, 0) < 0)
return (-1);
return (maxpart);
}

+ 69
- 0
src/lib/libutil/getrawpartition.3 View File

@ -0,0 +1,69 @@
.\" $NetBSD: getrawpartition.3,v 1.1 1996/05/16 07:03:32 thorpej Exp $
.\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Jason R. Thorpe.
.\"
.\" 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. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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.
.\"
.Dd May 15, 1996
.Dt GETRAWPARTITION 3
.Os NetBSD
.Sh NAME
.Nm getrawpartition
.Nd get the system
.Dq raw
partition
.Sh SYNOPSIS
.Fd #include <util.h>
.Ft int
.Fn getrawpartition void
.Sh DESCRIPTION
.Fn Getrawpartition
returns the partition number (
.Sq a
== 0,
.Sq b
== 1, ...) of the
.Dq raw
partition of the system's disks.
The
.Dq raw
partition is defined as the partition which provides access to the entire
disk, regardless of the disk's partition map.
.Sh SEE ALSO
.Xr getmaxpartitions 3 ,
.Xr sysctl 3
.Sh HISTORY
The
.Nm
function call appeared in
.Nx 1.2 .

+ 60
- 0
src/lib/libutil/getrawpartition.c View File

@ -0,0 +1,60 @@
/* $NetBSD: getrawpartition.c,v 1.1 1996/05/16 07:03:33 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 REGENTS 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: getrawpartition.c,v 1.1 1996/05/16 07:03:33 thorpej Exp $";
#endif
#include <sys/param.h>
#include <sys/sysctl.h>
#include <util.h>
int
getrawpartition()
{
int rawpart, mib[2];
size_t varlen;
mib[0] = CTL_KERN;
mib[1] = KERN_RAWPARTITION;
varlen = sizeof(rawpart);
if (sysctl(mib, 2, &rawpart, &varlen, NULL, 0) < 0)
return (-1);
return (rawpart);
}

+ 107
- 0
src/lib/libutil/login.3 View File

@ -0,0 +1,107 @@
.\" Copyright (c) 1995
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software developed by the Computer Systems
.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
.\" BG 91-66 and contributed to Berkeley.
.\"
.\" 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. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
.\"
.Dd December 14, 1995
.Dt LOGIN 3
.Os
.Sh NAME
.Nm login ,
.Nm logout ,
.Nm logwtmp
.Nd login utility functions
.Sh SYNOPSIS
.Fd #include <util.h>
.Ft void
.Fn login "struct utmp *ut"
.Ft int
.Fn logout "const char *line"
.Ft void
.Fn logwtmp "const char *line" "const char *name" "const char *host"
.Sh DESCRIPTION
The
.Fn login ,
.Fn logout ,
and
.Fn logwtmp
functions operate on the database of current users in
.Pa /var/run/utmp
and on the logfile
.Pa /var/log/wtmp
of logins and logouts.
.Pp
The
.Fn login
function updates the
.Pa /var/run/utmp
and
.Pa /var/log/wtmp
files with user information contained in
.Fa ut .
.Pp
The
.Fn logout
function removes the entry from
.Pa /var/run/utmp
corresponding to the device
.Fa line .
.Pp
The
.Fn logwtmp
function adds an entry to
.Pa /var/log/wtmp .
Since
.Fn login
will add the appropriate entry for
.Pa /var/log/wtmp
during a login,
.Fn logwtmp
is usually used for logouts.
.Sh RETURN VALUES
.Fn logout
returns non-zero if it was able to find and delete an entry for
.Fa line ,
and zero if there is no entry for
.Fa line
in
.Pa /var/run/utmp .
.Sh FILES
.Bl -tag -width /var/run/wtmp -compact
.It Pa /dev/\(**
.It Pa /etc/ttys
.It Pa /var/run/utmp
.It Pa /var/log/wtmp
.El
.Sh SEE ALSO
.Xr utmp 5

+ 2
- 3
src/lib/libutil/login.c View File

@ -33,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)login.c 8.1 (Berkeley) 6/4/93"; */
static char *rcsid = "$Id: login.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
static char *rcsid = "$Id: login.c,v 1.2 1996/05/22 11:35:05 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -43,8 +43,7 @@ static char *rcsid = "$Id: login.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
#include <stdlib.h>
#include <utmp.h>
#include <stdio.h>
void login __P((struct utmp *));
#include <util.h>
void
login(ut)


+ 2
- 3
src/lib/libutil/login_tty.c View File

@ -33,14 +33,13 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)login_tty.c 8.1 (Berkeley) 6/4/93"; */
static char *rcsid = "$Id: login_tty.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
static char *rcsid = "$Id: login_tty.c,v 1.2 1996/05/22 11:35:06 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
#include <sys/ioctl.h>
#include <unistd.h>
int login_tty __P((int));
#include <util.h>
int
login_tty(fd)


+ 4
- 4
src/lib/libutil/logout.c View File

@ -33,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)logout.c 8.1 (Berkeley) 6/4/93"; */
static char *rcsid = "$Id: logout.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
static char *rcsid = "$Id: logout.c,v 1.2 1996/05/22 11:35:07 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -44,16 +44,16 @@ static char *rcsid = "$Id: logout.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $"
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <util.h>
typedef struct utmp UTMP;
int
logout(line)
register char *line;
const char *line;
{
register int fd;
int fd, rval;
UTMP ut;
int rval;
if ((fd = open(_PATH_UTMP, O_RDWR, 0)) < 0)
return(0);


+ 3
- 4
src/lib/libutil/logwtmp.c View File

@ -33,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)logwtmp.c 8.1 (Berkeley) 6/4/93"; */
static char *rcsid = "$Id: logwtmp.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
static char *rcsid = "$Id: logwtmp.c,v 1.2 1996/05/22 11:35:08 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@ -44,12 +44,11 @@ static char *rcsid = "$Id: logwtmp.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $
#include <string.h>
#include <unistd.h>
#include <utmp.h>
void logwtmp __P((char *, char *, char *));
#include <util.h>
void
logwtmp(line, name, host)
char *line, *name, *host;
const char *line, *name, *host;
{
struct utmp ut;
struct stat buf;


+ 153
- 0
src/lib/libutil/openpty.3 View File

@ -0,0 +1,153 @@
.\" Copyright (c) 1995
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software developed by the Computer Systems
.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
.\" BG 91-66 and contributed to Berkeley.
.\"
.\" 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. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
.\"
.Dd December 14, 1995
.Dt OPENPTY 3
.Os
.Sh NAME
.Nm openpty ,
.Nm login_tty ,
.Nm forkpty
.Nd tty utility functions
.Sh SYNOPSIS
.Fd #include <util.h>
.Ft void
.Fn openpty "int *amaster" "int *aslave" "char *name" "struct termios *termp" "struct winsize *winp"
.Ft int
.Fn login_tty "int fd"
.Ft pid_t
.Fn forkpty "int *amaster" "char *name" "struct termios *termp" "struct winsize *winp"
.Sh DESCRIPTION
The
.Fn openpty ,
.Fn login_tty ,
and
.Fn login_tty
functions perform manipulations on ttys and pseudo-ttys.
.Pp
The
.Fn openpty
function finds an available pseudo-tty and returns file descriptors
for the master and slave in
.Fa amaster
and
.Fa aslave .
If
.Fa name
is non-null, the filename of the slave is returned in
.Fa name .
If
.Fa termp
is non-null, the terminal parameters of the slave will be set to the
values in
.Fa termp .
If
.Fa winp
is non-null, the window size of the slave will be set to the values in
.Fa winp .
.Pp
The
.Fn login_tty
function prepares for a login on the tty
.Fa fd
(which may be a real tty device, or the slave of a pseudo-tty as
returned by
.Fn openpty )
by creating a new session, making
.Fa fd
the controlling terminal for the current process, setting
.Fa fd
to be the standard input, output, and error streams of the current
process, and closing
.Fa fd .
.Pp
The
.Fn forkpty
function combines
.Fn openpty ,
.Fn fork ,
and
.Fn login_tty
to creates a new process operating in a pseudo-tty. The file
descriptor of the master side of the pseudo-tty is returned in
.Fa amaster ,
and the filename of the slave in
.Fa name
if it is non-null. The
.Fa termp
and
.Fa winp
parameters, if non-null, will determine the terminal attributes and
window size of the slave side of the pseudo-tty.
.Sh RETURN VALUES
If a call to
.Fn openpty ,
.Fn login_tty ,
or
.fn forkpty
is not successful, -1 is returned and
.Va errno
is set to indicate the error. Otherwise, they return 0.
.Sh ERRORS
.Fn openpty
will fail if:
.Bl -tag -width Er
.It Bq Er ENOENT
There are no available ttys.
.El
.Pp
.Fn login_tty
will fail if
.Fn ioctl
fails to set
.Fa fd
to the controlling terminal of the current process.
.Fn forkpty
will fail if either
.Fn openpty
or
.Fn fork
fails.
.Sh FILES
.Bl -tag -width /dev/[pt]ty[pqrstuwxyzPQRST][0123456789abcdef] -compact
.It Pa /dev/[pt]ty[pqrstuwxyzPQRST][0123456789abcdef]
.El
.Sh BUGS
The names of the virtual consoles for the i386 PCVT console driver
conflict with what would be the seventh group of pseudo-ttys, so
.Fn openpty
skips
.Pa /dev/[pt]tyv[0123456789abcdef]
while looking for pseudo-ttys.

+ 347
- 0
src/lib/libutil/passwd.c View File

@ -0,0 +1,347 @@
/*
* Copyright (c) 1987, 1993, 1994, 1995
* The Regents of the University of California. 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$NetBSD: passwd.c,v 1.1 1996/05/15 21:42:31 jtc Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pwd.h>
#include <errno.h>
#include <paths.h>
#include <signal.h>
#include <limits.h>
#include <util.h>
static void pw_cont __P((int sig));
int
pw_lock(retries)
int retries;
{
int i, fd;
mode_t old_mode;
/* Acquire the lock file. */
old_mode = umask(0);
fd = open(_PATH_MASTERPASSWD_LOCK, O_WRONLY|O_CREAT|O_EXCL, 0600);
for (i = 0; i < retries && fd < 0 && errno == EEXIST; i++) {
sleep(1);
fd = open(_PATH_MASTERPASSWD_LOCK, O_WRONLY|O_CREAT|O_EXCL,
0600);
}
umask(old_mode);
return(fd);
}
int
pw_mkdb()
{
int pstat;
pid_t pid;
pid = vfork();
if (pid == 0) {
execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p",
_PATH_MASTERPASSWD_LOCK, NULL);
exit(1);
}
pid = waitpid(pid, &pstat, 0);
if (pid == -1 || !WIFEXITED(pstat) || WEXITSTATUS(pstat) != 0) {
unlink(_PATH_MASTERPASSWD_LOCK);
return(-1);
}
return(0);
}
int
pw_abort()
{
return(unlink(_PATH_MASTERPASSWD_LOCK));
}
/* Everything below this point is intended for the convenience of programs
* which allow a user to interactively edit the passwd file. Errors in the
* routines below will cause the process to abort. */
static pid_t editpid = -1;
static void
pw_cont(sig)
int sig;
{
if (editpid != -1)
kill(editpid, sig);
}
void
pw_init()
{
struct rlimit rlim;
/* Unlimited resource limits. */
rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
(void)setrlimit(RLIMIT_CPU, &rlim);
(void)setrlimit(RLIMIT_FSIZE, &rlim);
(void)setrlimit(RLIMIT_STACK, &rlim);
(void)setrlimit(RLIMIT_DATA, &rlim);
(void)setrlimit(RLIMIT_RSS, &rlim);
/* Don't drop core (not really necessary, but GP's). */
rlim.rlim_cur = rlim.rlim_max = 0;
(void)setrlimit(RLIMIT_CORE, &rlim);
/* Turn off signals. */
(void)signal(SIGALRM, SIG_IGN);
(void)signal(SIGHUP, SIG_IGN);
(void)signal(SIGINT, SIG_IGN);
(void)signal(SIGPIPE, SIG_IGN);
(void)signal(SIGQUIT, SIG_IGN);
(void)signal(SIGTERM, SIG_IGN);
(void)signal(SIGCONT, pw_cont);
}
void
pw_edit(notsetuid, filename)
int notsetuid;
const char *filename;
{
int pstat;
char *p, *editor;
if (!filename)
filename = _PATH_MASTERPASSWD_LOCK;
if (!(editor = getenv("EDITOR")))
editor = _PATH_VI;
if (p = strrchr(editor, '/'))
++p;
else
p = editor;
if (!(editpid = vfork())) {
if (notsetuid) {
setgid(getgid());
setuid(getuid());
}
execlp(editor, p, filename, NULL);
_exit(1);
}
for (;;) {
editpid = waitpid(editpid, (int *)&pstat, WUNTRACED);
if (editpid == -1)
pw_error(editor, 1, 1);
else if (WIFSTOPPED(pstat))
raise(WSTOPSIG(pstat));
else if (WIFEXITED(pstat) && WEXITSTATUS(pstat) == 0)
break;
else
pw_error(editor, 1, 1);
}
editpid = -1;
}
void
pw_prompt()
{
int c;
(void)printf("re-edit the password file? [y]: ");
(void)fflush(stdout);
c = getchar();
if (c != EOF && c != '\n')
while (getchar() != '\n');
if (c == 'n')
pw_error(NULL, 0, 0);
}
void
pw_copy(ffd, tfd, pw)
int ffd, tfd;
struct passwd *pw;
{
FILE *from, *to;
int done;
char *p, buf[8192];
if (!(from = fdopen(ffd, "r")))
pw_error(_PATH_MASTERPASSWD, 1, 1);
if (!(to = fdopen(tfd, "w")))
pw_error(_PATH_MASTERPASSWD_LOCK, 1, 1);
for (done = 0; fgets(buf, sizeof(buf), from);) {
if (!strchr(buf, '\n')) {
warnx("%s: line too long", _PATH_MASTERPASSWD);
pw_error(NULL, 0, 1);
}
if (done) {
(void)fprintf(to, "%s", buf);
if (ferror(to))
goto err;
continue;
}
if (!(p = strchr(buf, ':'))) {
warnx("%s: corrupted entry", _PATH_MASTERPASSWD);
pw_error(NULL, 0, 1);
}
*p = '\0';
if (strcmp(buf, pw->pw_name)) {
*p = ':';
(void)fprintf(to, "%s", buf);
if (ferror(to))
goto err;
continue;
}
(void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
pw->pw_dir, pw->pw_shell);
done = 1;
if (ferror(to))
goto err;
}
if (!done)
(void)fprintf(to, "%s:%s:%d:%d:%s:%ld:%ld:%s:%s:%s\n",
pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid,
pw->pw_class, pw->pw_change, pw->pw_expire, pw->pw_gecos,
pw->pw_dir, pw->pw_shell);
if (ferror(to))
err: pw_error(NULL, 1, 1);
(void)fclose(to);
}
int
pw_scan(bp, pw, flags)
char *bp;
struct passwd *pw;
int *flags;
{
long id;
int root;
char *p, *sh;
if (flags != (int *)NULL)
*flags = 0;
if (!(pw->pw_name = strsep(&bp, ":"))) /* login */
goto fmt;
root = !strcmp(pw->pw_name, "root");
if (!(pw->pw_passwd = strsep(&bp, ":"))) /* passwd */
goto fmt;
if (!(p = strsep(&bp, ":"))) /* uid */
goto fmt;
id = atol(p);
if (root && id) {
warnx("root uid should be 0");
return (0);
}
if (id > USHRT_MAX) {
warnx("%s > max uid value (%d)", p, USHRT_MAX);
return (0);
}
pw->pw_uid = id;
if ((*p == '\0') && (flags != (int *)NULL))
*flags |= _PASSWORD_NOUID;
if (!(p = strsep(&bp, ":"))) /* gid */
goto fmt;
id = atol(p);
if (id > USHRT_MAX) {
warnx("%s > max gid value (%d)", p, USHRT_MAX);
return (0);
}
pw->pw_gid = id;
if ((*p == '\0') && (flags != (int *)NULL))
*flags |= _PASSWORD_NOGID;
pw->pw_class = strsep(&bp, ":"); /* class */
if (!(p = strsep(&bp, ":"))) /* change */
goto fmt;
pw->pw_change = atol(p);
if ((*p == '\0') && (flags != (int *)NULL))
*flags |= _PASSWORD_NOCHG;
if (!(p = strsep(&bp, ":"))) /* expire */
goto fmt;
pw->pw_expire = atol(p);
if ((*p == '\0') && (flags != (int *)NULL))
*flags |= _PASSWORD_NOEXP;
pw->pw_gecos = strsep(&bp, ":"); /* gecos */
pw->pw_dir = strsep(&bp, ":"); /* directory */
if (!(pw->pw_shell = strsep(&bp, ":"))) /* shell */
goto fmt;
p = pw->pw_shell;
if (root && *p) /* empty == /bin/sh */
for (setusershell();;) {
if (!(sh = getusershell())) {
warnx("warning, unknown root shell");
break;
}
if (!strcmp(p, sh))
break;
}
if (p = strsep(&bp, ":")) { /* too many */
fmt: warnx("corrupted entry");
return (0);
}
return (1);
}
void
pw_error(name, err, eval)
const char *name;
int err, eval;
{
if (err)
warn(name);
warnx("%s: unchanged", _PATH_MASTERPASSWD);
pw_abort();
exit(eval);
}

+ 9
- 5
src/lib/libutil/pty.c View File

@ -33,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/* from: static char sccsid[] = "@(#)pty.c 8.1 (Berkeley) 6/4/93"; */
static char *rcsid = "$Id: pty.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
static char *rcsid = "$Id: pty.c,v 1.2 1996/05/22 11:35:11 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/cdefs.h>
@ -47,10 +47,14 @@ static char *rcsid = "$Id: pty.c,v 1.1.1.1 1995/10/18 08:43:13 deraadt Exp $";
#include <stdio.h>
#include <string.h>
#include <grp.h>
#include <util.h>
int login_tty __P((int));
int openpty __P((int *, int *, char *, struct termios *, struct winsize *));
pid_t forkpty __P((int *, char *, struct termios *, struct winsize *));
#ifdef i386
/* PCVT conflicts with ttyv*. */
#define TTY_LETTERS "pqrstuwxyzPQRST"
#else
#define TTY_LETTERS "pqrstuvwxyzPQRST"
#endif
int
openpty(amaster, aslave, name, termp, winp)
@ -69,7 +73,7 @@ openpty(amaster, aslave, name, termp, winp)
else
ttygid = -1;
for (cp1 = "pqrstuvwxyzPQRST"; *cp1; cp1++) {
for (cp1 = TTY_LETTERS; *cp1; cp1++) {
line[8] = *cp1;
for (cp2 = "0123456789abcdef"; *cp2; cp2++) {
line[9] = *cp2;


+ 174
- 0
src/lib/libutil/pw_init.3 View File

@ -0,0 +1,174 @@
.\" Copyright (c) 1995
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software developed by the Computer Systems
.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
.\" BG 91-66 and contributed to Berkeley.
.\"
.\" 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. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
.\"
.Dd December 15, 1995
.Dt PW_INIT 3
.Os
.Sh NAME
.Nm pw_init ,
.Nm pw_edit ,
.Nm pw_prompt ,
.Nm pw_copy ,
.Nm pw_scan ,
.Nm pw_error
.Nd utility functions for interactive passwd file updates
.Sh SYNOPSIS
.Fd #indlude <pwd.h>
.Fd #include <util.h>
.Ft void
.Fn pw_init
.Ft void
.Fn pw_edit "int notsetuid" "const char *filename"
.Ft void
.Fn pw_prompt
.Ft void
.Fn pw_copy "int ffd" "int tfd" "struct passwd *pw"
.Ft int
.Fn pw_scan "char *bp" "struct passwd *pw" "int *flags"
.Ft void
.Fn pw_error "const char *name" "int err" "int eval"
.Sh DESCRIPTION
These functions are designed as conveniences for interactive programs
which update the passwd file and do nothing else. They generally
handle errors by printing out a message to the standard error stream
and possibly aborting the process.
.Pp
The
.Fn pw_init
function prepares for a passwd update by unlimiting all resource
constraints, disabling core dumps (thus preventing dumping the
contents of the passwd database into a world-readable file), and
disabling most signals.
.Pp
The
.Fn pw_edit
function runs an editor (named by the environment variable EDITOR, or
.Pa /usr/bin/vi
if EDITOR is not set) on the file
.Fa filename
(or
.Pa /etc/ptmp
if
.Fa filename
is NULL). If
.Fa notsetuid
is nonzero,
.Fn pw_edit
will set the effective user and group ID to the real user and group ID
before running the editor.
.Pp
The
.Fn pw_prompt
function asks the user whether he or she wants to re-edit the password
file; if the answer is no,
.Fn pw_prompt
deletes the lock file and exits the process.
.Pp
The
.Fn pw_copy
function reads a passwd file from
.Fa ffd
and writes it to
.Fa tfd ,
updating the entry corresponding to pw->pw_name with the information
in
.Fa pw .
.Pp
The
.Fn pw_scan
function accepts in
.Fa bp
a passwd entry as it would be represented in
.Pa /etc/master.passwd
and fills in
.Fa pw
with corresponding values; string fields in
.Fa pw
will be pointers into
.Fa bp .
Some characters in
.Fa bp
will be overwritten with 0s in order to terminate the strings pointed
to by
.Fa pw .
If
.Fa flags
is non-null, it is filled in with the following flags:
.Bl -tag -width _PASSWORD_NOGIDxxx
.It Dv _PASSWORD_NOUID
The uid field of
.Fa bp
is empty.
.It Dv _PASSWORD_NOGID
The gid field of
.Fa bp
is empty.
.It Dv _PASSWD_NOCHG
The change field of
.Fa bp
is empty.
.It Dv _PASSWD_NOEXP
The expire field of
.Fa bp
is empty.
.El
.Pp
The
.Fn pw_error
function displays an error message, aborts the current passwd update,
and exits the current process. If
.Fa err
is non-zero, a warning message beginning with
.Fa name
is printed for the current value of
.Va errno .
The process exits with status
.Fa eval .
.Sh RETURN VALUES
The
.Fn pw_scan
function prints a warning message and returns 0 if the string in the
.Fa bp
argument is not a valid passwd string. Otherwise,
.Fn pw_scan
returns 1.
.Sh FILES
.Bl -tag -width /etc/master.passwd -compact
.It Pa /etc/master.passwd
.It Pa /etc/ptmp
.El
.Sh SEE ALSO
.Xr pw_lock 3 ,
.Xr passwd 5

+ 100
- 0
src/lib/libutil/pw_lock.3 View File

@ -0,0 +1,100 @@
.\" Copyright (c) 1995
.\" The Regents of the University of California. All rights reserved.
.\"
.\" This code is derived from software developed by the Computer Systems
.\" Engineering group at Lawrence Berkeley Laboratory under DARPA contract
.\" BG 91-66 and contributed to Berkeley.
.\"
.\" 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. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
.\"
.Dd December 15, 1995
.Dt PW_LOCK 3
.Os
.Sh NAME
.Nm pw_lock ,
.Nm pw_mkdb ,
.Nm pw_abort
.Nd passwd file update functions
.Sh SYNOPSIS
.Fd #include <util.h>
.Ft int
.Fn pw_lock "int retries"
.Ft int
.Fn pw_mkdb
.Ft void
.Fn pw_abort
.Sh DESCRIPTION
The
.Fn pw_lock ,
.Fn pw_mkdb ,
and
.Fn pw_abort
functions allow a program to update the system passwd database.
.Pp
The
.Fn pw_lock
function attempts to lock the passwd database by creating the file
.Pa /etc/ptmp ,
and returns the file descriptor of that file. If
.Fa retries
is greater than zero,
.Fn pw_lock
will try multiple times to open
.Pa /etc/ptmp ,
waiting one second between tries. In addition to being a lock file,
.Pa /etc/ptmp
will also hold the contents of the new passwd file.
.Pp
The
.Fn pw_mkdb
function updates the passwd file from the contents of
.Pa /etc/ptmp .
You should finish writing to and close the file descriptor returned by
.Fn pw_lock
before calling
.Fn pw_mkdb .
.Pp
The
.Fn pw_abort
function aborts a passwd file update by deleting
.Pa /etc/ptmp .
The passwd database remains unchanged.
.Sh RETURN VALUES
The
.Fn pw_lock
and
.Fn pw_mkdb
functions return -1 if they are unable to complete properly.
.Sh FILES
.Bl -tag -width /etc/master.passwd -compact
.It Pa /etc/master.passwd
.It Pa /etc/ptmp
.El
.Sh SEE ALSO
.Xr pw_init 3

+ 1
- 1
src/lib/libutil/shlib_version View File

@ -1,2 +1,2 @@
major=3
minor=1
minor=2

Loading…
Cancel
Save