xref: /freebsd/usr.sbin/pw/pw.h (revision f936ccb5f8563a034f2d2ca9ccbea2a6beff62fa)
1d6f907dcSJoerg Wunsch /*-
2ad7cf975SJoerg Wunsch  * Copyright (C) 1996
3ad7cf975SJoerg Wunsch  *	David L. Nugent.  All rights reserved.
4d6f907dcSJoerg Wunsch  *
5d6f907dcSJoerg Wunsch  * Redistribution and use in source and binary forms, with or without
6d6f907dcSJoerg Wunsch  * modification, are permitted provided that the following conditions
7d6f907dcSJoerg Wunsch  * are met:
8d6f907dcSJoerg Wunsch  * 1. Redistributions of source code must retain the above copyright
9ad7cf975SJoerg Wunsch  *    notice, this list of conditions and the following disclaimer.
10d6f907dcSJoerg Wunsch  * 2. Redistributions in binary form must reproduce the above copyright
11d6f907dcSJoerg Wunsch  *    notice, this list of conditions and the following disclaimer in the
12d6f907dcSJoerg Wunsch  *    documentation and/or other materials provided with the distribution.
13d6f907dcSJoerg Wunsch  *
14ad7cf975SJoerg Wunsch  * THIS SOFTWARE IS PROVIDED BY DAVID L. NUGENT AND CONTRIBUTORS ``AS IS'' AND
15d6f907dcSJoerg Wunsch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16d6f907dcSJoerg Wunsch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17ad7cf975SJoerg Wunsch  * ARE DISCLAIMED.  IN NO EVENT SHALL DAVID L. NUGENT OR CONTRIBUTORS BE LIABLE
18d6f907dcSJoerg Wunsch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19d6f907dcSJoerg Wunsch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20d6f907dcSJoerg Wunsch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21d6f907dcSJoerg Wunsch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22d6f907dcSJoerg Wunsch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23d6f907dcSJoerg Wunsch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24d6f907dcSJoerg Wunsch  * SUCH DAMAGE.
25d6f907dcSJoerg Wunsch  *
2697d92980SPeter Wemm  * $FreeBSD$
27d6f907dcSJoerg Wunsch  */
28d6f907dcSJoerg Wunsch 
29c145c34cSBaptiste Daroussin #define _WITH_GETLINE
30d6f907dcSJoerg Wunsch #include <stdio.h>
31d6f907dcSJoerg Wunsch #include <stdlib.h>
32d6f907dcSJoerg Wunsch #include <string.h>
33d6f907dcSJoerg Wunsch #include <unistd.h>
34d6f907dcSJoerg Wunsch #include <stdarg.h>
35d6f907dcSJoerg Wunsch #include <errno.h>
36d6f907dcSJoerg Wunsch #include <sys/types.h>
37d6f907dcSJoerg Wunsch #include <sys/stat.h>
385f12594aSDavid Nugent #include <sys/param.h>
39d6f907dcSJoerg Wunsch #include <pwd.h>
40d6f907dcSJoerg Wunsch #include <grp.h>
41d6f907dcSJoerg Wunsch #include <sys/queue.h>
4248aee7f3SJoerg Wunsch #include <sysexits.h>
43d6f907dcSJoerg Wunsch 
44d6f907dcSJoerg Wunsch #include "psdate.h"
455f12594aSDavid Nugent #include "pwupd.h"
46d6f907dcSJoerg Wunsch 
47d6f907dcSJoerg Wunsch enum _mode
48d6f907dcSJoerg Wunsch {
49d6f907dcSJoerg Wunsch         M_ADD,
50d6f907dcSJoerg Wunsch         M_DELETE,
51d6f907dcSJoerg Wunsch         M_UPDATE,
52d6f907dcSJoerg Wunsch         M_PRINT,
5348aee7f3SJoerg Wunsch 	M_NEXT,
542399cd14SDavid Nugent 	M_LOCK,
552399cd14SDavid Nugent 	M_UNLOCK,
56d6f907dcSJoerg Wunsch         M_NUM
57d6f907dcSJoerg Wunsch };
58d6f907dcSJoerg Wunsch 
59d6f907dcSJoerg Wunsch enum _which
60d6f907dcSJoerg Wunsch {
61d6f907dcSJoerg Wunsch         W_USER,
62d6f907dcSJoerg Wunsch         W_GROUP,
63d6f907dcSJoerg Wunsch         W_NUM
64d6f907dcSJoerg Wunsch };
65d6f907dcSJoerg Wunsch 
66d6f907dcSJoerg Wunsch struct carg
67d6f907dcSJoerg Wunsch {
68d6f907dcSJoerg Wunsch 	int		  ch;
69d6f907dcSJoerg Wunsch 	char		  *val;
70e3975643SJake Burkholder 	LIST_ENTRY(carg)  list;
71d6f907dcSJoerg Wunsch };
72d6f907dcSJoerg Wunsch 
733ce1d6bbSStefan Farfeleder LIST_HEAD(cargs, carg);
74d6f907dcSJoerg Wunsch 
75644af48dSJung-uk Kim #define	_DEF_DIRMODE	(S_IRWXU | S_IRWXG | S_IRWXO)
76d6f907dcSJoerg Wunsch #define _PATH_PW_CONF	"/etc/pw.conf"
77d6f907dcSJoerg Wunsch #define _UC_MAXLINE	1024
78d6f907dcSJoerg Wunsch #define _UC_MAXSHELLS	32
79d6f907dcSJoerg Wunsch 
80d6f907dcSJoerg Wunsch struct userconf *read_userconfig(char const * file);
81d6f907dcSJoerg Wunsch int write_userconfig(char const * file);
82d6f907dcSJoerg Wunsch struct carg *addarg(struct cargs * _args, int ch, char *argstr);
83d6f907dcSJoerg Wunsch struct carg *getarg(struct cargs * _args, int ch);
84d6f907dcSJoerg Wunsch 
85a9237189SBaptiste Daroussin int pw_user(int mode, char *name, long id, struct cargs * _args);
86*f936ccb5SBaptiste Daroussin int pw_usernext(struct userconf *cnf, bool quiet);
87a9237189SBaptiste Daroussin int pw_group(int mode, char *name, long id,  struct cargs * _args);
88*f936ccb5SBaptiste Daroussin int pw_groupnext(struct userconf *cnf, bool quiet);
891238a919SBaptiste Daroussin char *pw_checkname(char *name, int gecos);
90d6f907dcSJoerg Wunsch 
91f1d684faSDavid Nugent int addnispwent(const char *path, struct passwd *pwd);
92f1d684faSDavid Nugent int delnispwent(const char *path, const char *login);
93f1d684faSDavid Nugent int chgnispwent(const char *path, const char *login, struct passwd *pwd);
94f1d684faSDavid Nugent 
95d6f907dcSJoerg Wunsch int boolean_val(char const * str, int dflt);
96d6f907dcSJoerg Wunsch char const *boolean_str(int val);
97d6f907dcSJoerg Wunsch char *newstr(char const * p);
98d6f907dcSJoerg Wunsch 
99cab0fb4eSKris Kennaway void pw_log(struct userconf * cnf, int mode, int which, char const * fmt,...) __printflike(4, 5);
100d6f907dcSJoerg Wunsch char *pw_pwcrypt(char *password);
101d6f907dcSJoerg Wunsch 
102d6f907dcSJoerg Wunsch extern const char *Modes[];
103d6f907dcSJoerg Wunsch extern const char *Which[];
104