pwupd.h revision 50479
120253Sjoerg/*-
220302Sjoerg * Copyright (C) 1996
320302Sjoerg *	David L. Nugent.  All rights reserved.
420253Sjoerg *
520253Sjoerg * Redistribution and use in source and binary forms, with or without
620253Sjoerg * modification, are permitted provided that the following conditions
720253Sjoerg * are met:
820253Sjoerg * 1. Redistributions of source code must retain the above copyright
920302Sjoerg *    notice, this list of conditions and the following disclaimer.
1020253Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1120253Sjoerg *    notice, this list of conditions and the following disclaimer in the
1220253Sjoerg *    documentation and/or other materials provided with the distribution.
1320253Sjoerg *
1420302Sjoerg * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND
1520253Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1620253Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1720302Sjoerg * ARE DISCLAIMED.  IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE
1820253Sjoerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1920253Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2020253Sjoerg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2120253Sjoerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2220253Sjoerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2320253Sjoerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2420253Sjoerg * SUCH DAMAGE.
2520253Sjoerg *
2650479Speter * $FreeBSD: head/usr.sbin/pw/pwupd.h 50479 1999-08-28 01:35:59Z peter $
2720253Sjoerg */
2820253Sjoerg
2920253Sjoerg#ifndef _PWUPD_H_
3020253Sjoerg#define _PWUPD_H_
3120253Sjoerg
3220253Sjoerg#include <sys/types.h>
3320253Sjoerg#include <pwd.h>
3420253Sjoerg#include <grp.h>
3520253Sjoerg
3620253Sjoerg#include <sys/cdefs.h>
3720253Sjoerg
3820253Sjoergenum updtype
3920253Sjoerg{
4020253Sjoerg        UPD_DELETE = -1,
4120253Sjoerg        UPD_CREATE = 0,
4220253Sjoerg        UPD_REPLACE = 1
4320253Sjoerg};
4420253Sjoerg
4520253Sjoerg__BEGIN_DECLS
4620253Sjoergint fileupdate __P((char const * fname, mode_t fm, char const * nline, char const * pfx, int pfxlen, int updmode));
4720253Sjoerg__END_DECLS
4820253Sjoerg
4920253Sjoergenum pwdfmttype
5020253Sjoerg{
5120253Sjoerg        PWF_STANDARD,		/* MASTER format but with '*' as password */
5220253Sjoerg        PWF_PASSWD,		/* V7 format */
5320253Sjoerg        PWF_GROUP = PWF_PASSWD,
5420253Sjoerg        PWF_MASTER		/* MASTER format with password */
5520253Sjoerg};
5620253Sjoerg
5744229Sdavidnstruct pwf
5844229Sdavidn{
5944229Sdavidn	int		    _altdir;
6044229Sdavidn	void		  (*_setpwent)(void);
6144229Sdavidn	void		  (*_endpwent)(void);
6244229Sdavidn	struct passwd * (*_getpwent)(void);
6344229Sdavidn	struct passwd	* (*_getpwuid)(uid_t uid);
6444229Sdavidn	struct passwd	* (*_getpwnam)(const char * nam);
6544229Sdavidn	int             (*_pwdb)(char *arg, ...);
6644229Sdavidn	int		  (*_setgrent)(void);
6744229Sdavidn	void		  (*_endgrent)(void);
6844229Sdavidn	struct group  * (*_getgrent)(void);
6944229Sdavidn	struct group  * (*_getgrgid)(gid_t gid);
7044229Sdavidn	struct group  * (*_getgrnam)(const char * nam);
7144229Sdavidn	int		  (*_grdb)(char *arg, ...);
7244229Sdavidn};
7344229Sdavidn
7444229Sdavidnextern struct pwf PWF;
7544229Sdavidnextern struct pwf VPWF;
7644229Sdavidn
7744229Sdavidn#define SETPWENT()	PWF._setpwent()
7844229Sdavidn#define ENDPWENT()	PWF._endpwent()
7944229Sdavidn#define GETPWENT()	PWF._getpwent()
8044229Sdavidn#define GETPWUID(uid)	PWF._getpwuid(uid)
8144229Sdavidn#define GETPWNAM(nam)	PWF._getpwnam(nam)
8244229Sdavidn#define PWDB(args)	PWF._pwdb(args)
8344229Sdavidn
8444229Sdavidn#define SETGRENT()	PWF._setgrent()
8544229Sdavidn#define ENDGRENT()	PWF._endgrent()
8644229Sdavidn#define GETGRENT()	PWF._getgrent()
8744229Sdavidn#define GETGRGID(gid)	PWF._getgrgid(gid)
8844229Sdavidn#define GETGRNAM(nam)	PWF._getgrnam(nam)
8944229Sdavidn#define GRDB(args)	PWF._grdb(args)
9044229Sdavidn
9144229Sdavidn#define PWALTDIR()	PWF._altdir
9244229Sdavidn#ifndef _PATH_PWD
9344229Sdavidn#define _PATH_PWD	"/etc"
9444229Sdavidn#endif
9544229Sdavidn#ifndef _GROUP
9644229Sdavidn#define _GROUP		"group"
9744229Sdavidn#endif
9844229Sdavidn#ifndef _PASSWD
9944229Sdavidn#define _PASSWD 	"passwd"
10044229Sdavidn#endif
10144229Sdavidn#ifndef _MASTERPASSWD
10244229Sdavidn#define _MASTERPASSWD	"master.passwd"
10344229Sdavidn#endif
10444229Sdavidn#ifndef _GROUP
10544229Sdavidn#define _GROUP		"group"
10644229Sdavidn#endif
10744229Sdavidn
10820253Sjoerg__BEGIN_DECLS
10920253Sjoergint addpwent __P((struct passwd * pwd));
11020253Sjoergint delpwent __P((struct passwd * pwd));
11120253Sjoergint chgpwent __P((char const * login, struct passwd * pwd));
11220253Sjoergint fmtpwent __P((char *buf, struct passwd * pwd));
11320253Sjoergint fmtpwentry __P((char *buf, struct passwd * pwd, int type));
11420747Sdavidn
11544229Sdavidnint setpwdir __P((const char * dir));
11644229Sdavidnchar * getpwpath __P((char const * file));
11744229Sdavidnint pwdb __P((char *arg, ...));
11844229Sdavidn
11920253Sjoergint addgrent __P((struct group * grp));
12020253Sjoergint delgrent __P((struct group * grp));
12120253Sjoergint chggrent __P((char const * name, struct group * grp));
12220747Sdavidnint fmtgrent __P((char **buf, int * buflen, struct group * grp));
12320747Sdavidnint fmtgrentry __P((char **buf, int * buflen, struct group * grp, int type));
12420253Sjoergint editgroups __P((char *name, char **groups));
12520253Sjoerg
12644229Sdavidnint setgrdir __P((const char * dir));
12744229Sdavidnchar * getgrpath __P((const char *file));
12844229Sdavidnint grdb __P((char *arg, ...));
12920253Sjoerg
13044229Sdavidnvoid vsetpwent __P((void));
13144229Sdavidnvoid vendpwent __P((void));
13244229Sdavidnstruct passwd * vgetpwent __P((void));
13344229Sdavidnstruct passwd * vgetpwuid __P((uid_t uid));
13444229Sdavidnstruct passwd * vgetpwnam __P((const char * nam));
13544229Sdavidnstruct passwd * vgetpwent __P((void));
13644229Sdavidnint             vpwdb __P((char *arg, ...));
13744229Sdavidn
13844229Sdavidnint vsetgrent __P((void));
13944229Sdavidnvoid vendgrent __P((void));
14044229Sdavidnstruct group * vgetgrent __P((void));
14144229Sdavidnstruct group * vgetgrgid __P((gid_t gid));
14244229Sdavidnstruct group * vgetgrnam __P((const char * nam));
14344229Sdavidnstruct group * vgetgrent __P((void));
14444229Sdavidnint	       vgrdb __P((char *arg, ...));
14544229Sdavidnint	        vsetgrent __P((void));
14644229Sdavidnvoid            vendgrent __P((void));
14744229Sdavidn
14820253Sjoergvoid copymkdir __P((char const * dir, char const * skel, mode_t mode, uid_t uid, gid_t gid));
14920253Sjoergvoid rm_r __P((char const * dir, uid_t uid));
15020747Sdavidnint extendline __P((char **buf, int *buflen, int needed));
15120747Sdavidnint extendarray __P((char ***buf, int *buflen, int needed));
15220253Sjoerg__END_DECLS
15320253Sjoerg
15444229Sdavidn#define PWBUFSZ 1024
15544229Sdavidn
15620253Sjoerg#endif				/* !_PWUPD_H */
157