113137Speter/*
256626Speter * Copyright (c) 1996  Peter Wemm <peter@FreeBSD.org>.
313137Speter * All rights reserved.
496199Sdes * Copyright (c) 2002 Networks Associates Technology, Inc.
596199Sdes * All rights reserved.
613137Speter *
796199Sdes * Portions of this software were developed for the FreeBSD Project by
896199Sdes * ThinkSec AS and NAI Labs, the Security Research Division of Network
996199Sdes * Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
1096199Sdes * ("CBOSS"), as part of the DARPA CHATS research program.
1196199Sdes *
1213137Speter * Redistribution and use in source and binary forms, with or without
1313137Speter * modification, is permitted provided that the following conditions
1413137Speter * are met:
1513137Speter * 1. Redistributions of source code must retain the above copyright
1656626Speter *    notice, this list of conditions and the following disclaimer.
1713137Speter * 2. Redistributions in binary form must reproduce the above copyright
1813137Speter *    notice, this list of conditions and the following disclaimer in the
1913137Speter *    documentation and/or other materials provided with the distribution.
2096199Sdes * 3. The name of the author may not be used to endorse or promote
2196199Sdes *    products derived from this software without specific prior written
2296199Sdes *    permission.
2313137Speter *
2456626Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2556626Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2656626Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2756626Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2856626Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2956626Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3056626Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3156626Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3256626Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3356626Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3456626Speter * SUCH DAMAGE.
3556626Speter *
3650476Speter * $FreeBSD$
3713137Speter */
3813137Speter
3913137Speter#ifndef _LIBUTIL_H_
4013137Speter#define	_LIBUTIL_H_
4113137Speter
42200035Sed#include <sys/cdefs.h>
43200035Sed#include <sys/_types.h>
44221502Sobrien#include <sys/_stdint.h>
45200035Sed
46200035Sed#ifndef _GID_T_DECLARED
47200035Sedtypedef	__gid_t		gid_t;
48200035Sed#define	_GID_T_DECLARED
49200035Sed#endif
50200035Sed
51230037Sghelmer#ifndef _MODE_T_DECLARED
52230233Sghelmertypedef	__mode_t	mode_t;
53230233Sghelmer#define	_MODE_T_DECLARED
54230037Sghelmer#endif
55230037Sghelmer
56200035Sed#ifndef _PID_T_DECLARED
57200035Sedtypedef	__pid_t		pid_t;
58200035Sed#define	_PID_T_DECLARED
59200035Sed#endif
60200035Sed
61200035Sed#ifndef _SIZE_T_DECLARED
62200035Sedtypedef	__size_t	size_t;
63200035Sed#define	_SIZE_T_DECLARED
64200035Sed#endif
65200035Sed
66200035Sed#ifndef _UID_T_DECLARED
67200035Sedtypedef	__uid_t		uid_t;
68200035Sed#define	_UID_T_DECLARED
69200035Sed#endif
70200035Sed
71230233Sghelmer#define	PROPERTY_MAX_NAME	64
72230233Sghelmer#define	PROPERTY_MAX_VALUE	512
7368488Smurray
74230600Sghelmer/* For properties.c. */
7540040Sjkhtypedef struct _property {
7640040Sjkh	struct _property *next;
77230011Sghelmer	char	*name;
78230011Sghelmer	char	*value;
7940040Sjkh} *properties;
8040040Sjkh
81230600Sghelmer/* Avoid pulling in all the include files for no need. */
8245392Sbrianstruct in_addr;
83230037Sghelmerstruct pidfh;
84229985Sghelmerstruct sockaddr;
85229985Sghelmerstruct termios;
86229985Sghelmerstruct winsize;
8713137Speter
8813137Speter__BEGIN_DECLS
89229986Sghelmerchar	*auth_getval(const char *_name);
90126299Skientzlevoid	clean_environment(const char * const *_white,
91126299Skientzle	    const char * const *_more_white);
92229985Sghelmerint	expand_number(const char *_buf, uint64_t *_num);
9392917Sobrienint	extattr_namespace_to_string(int _attrnamespace, char **_string);
9492941Sobrienint	extattr_string_to_namespace(const char *_string, int *_attrnamespace);
95169450Sdesint	flopen(const char *_path, int _flags, ...);
9692941Sobrienint	forkpty(int *_amaster, char *_name,
97229988Sghelmer	    struct termios *_termp, struct winsize *_winp);
98229986Sghelmervoid	hexdump(const void *_ptr, int _length, const char *_hdr, int _flags);
99129677Spjdint	humanize_number(char *_buf, size_t _len, int64_t _number,
100129677Spjd	    const char *_suffix, int _scale, int _flags);
101185548Speterstruct kinfo_file *
102185548Speter	kinfo_getfile(pid_t _pid, int *_cntp);
103185548Speterstruct kinfo_vmentry *
104185548Speter	kinfo_getvmmap(pid_t _pid, int *_cntp);
105221807Sstasstruct kinfo_proc *
106221807Sstas	kinfo_getallproc(int *_cntp);
107221807Sstasstruct kinfo_proc *
108221807Sstas	kinfo_getproc(pid_t _pid);
109229986Sghelmerint	kld_isloaded(const char *_name);
110229986Sghelmerint	kld_load(const char *_name);
111229985Sghelmerint	login_tty(int _fd);
112229985Sghelmerint	openpty(int *_amaster, int *_aslave, char *_name,
113229988Sghelmer	    struct termios *_termp, struct winsize *_winp);
114230233Sghelmerint	pidfile_close(struct pidfh *_pfh);
115230233Sghelmerint	pidfile_fileno(const struct pidfh *_pfh);
116230233Sghelmerstruct pidfh *
117230233Sghelmer	pidfile_open(const char *_path, mode_t _mode, pid_t *_pidptr);
118230233Sghelmerint	pidfile_remove(struct pidfh *_pfh);
119230233Sghelmerint	pidfile_write(struct pidfh *_pfh);
120229986Sghelmervoid	properties_free(properties _list);
121229986Sghelmerchar	*property_find(properties _list, const char *_name);
122229988Sghelmerproperties
123230011Sghelmer	properties_read(int _fd);
124229986Sghelmerint	realhostname(char *_host, size_t _hsize, const struct in_addr *_ip);
125229986Sghelmerint	realhostname_sa(char *_host, size_t _hsize, struct sockaddr *_addr,
126229988Sghelmer	    int _addrlen);
127229985Sghelmerint	_secure_path(const char *_path, uid_t _uid, gid_t _gid);
128229985Sghelmervoid	trimdomain(char *_fullhost, int _hostsize);
129229988Sghelmerconst char *
130229988Sghelmer	uu_lockerr(int _uu_lockresult);
131229985Sghelmerint	uu_lock(const char *_ttyname);
132229985Sghelmerint	uu_unlock(const char *_ttyname);
133229985Sghelmerint	uu_lock_txfr(const char *_ttyname, pid_t _pid);
134155804Sdes
135230600Sghelmer/*
136230600Sghelmer * Conditionally prototype the following functions if the include
137230600Sghelmer * files upon which they depend have been included.
138230600Sghelmer */
139230600Sghelmer#ifdef _STDIO_H_
140229988Sghelmerchar	*fparseln(FILE *_fp, size_t *_len, size_t *_lineno,
141229988Sghelmer	    const char _delim[3], int _flags);
14255227Speter#endif
14396199Sdes
14496199Sdes#ifdef _PWD_H_
145230011Sghelmerint	pw_copy(int _ffd, int _tfd, const struct passwd *_pw,
146230011Sghelmer	    struct passwd *_old_pw);
147230011Sghelmerstruct passwd
148230011Sghelmer	*pw_dup(const struct passwd *_pw);
14996199Sdesint	pw_edit(int _notsetuid);
150121193Smarkmint	pw_equal(const struct passwd *_pw1, const struct passwd *_pw2);
15196199Sdesvoid	pw_fini(void);
15296199Sdesint	pw_init(const char *_dir, const char *_master);
153121193Smarkmchar	*pw_make(const struct passwd *_pw);
154229572Sbaptchar	*pw_make_v7(const struct passwd *_pw);
15596199Sdesint	pw_mkdb(const char *_user);
15696199Sdesint	pw_lock(void);
157230601Sghelmerstruct passwd *
158230601Sghelmer	pw_scan(const char *_line, int _flags);
159230601Sghelmerconst char *
160230601Sghelmer	pw_tempname(void);
16196199Sdesint	pw_tmp(int _mfd);
16296199Sdes#endif
163149423Spjd
164178431Sscf#ifdef _GRP_H_
165230011Sghelmerint 	gr_copy(int __ffd, int _tfd, const struct group *_gr,
166230011Sghelmer	    struct group *_old_gr);
167230601Sghelmerstruct group *
168230601Sghelmer	gr_dup(const struct group *_gr);
169244736Sbaptstruct group *
170247919Sdb	gr_add(const struct group *_gr, const char *_newmember);
171229986Sghelmerint	gr_equal(const struct group *_gr1, const struct group *_gr2);
172228545Sbaptvoid	gr_fini(void);
173228545Sbaptint	gr_init(const char *_dir, const char *_master);
174228545Sbaptint	gr_lock(void);
175229986Sghelmerchar	*gr_make(const struct group *_gr);
176228545Sbaptint	gr_mkdb(void);
177230601Sghelmerstruct group *
178230601Sghelmer	gr_scan(const char *_line);
179228545Sbaptint	gr_tmp(int _mdf);
180178431Sscf#endif
181178431Sscf
182207736Smckusick#ifdef _UFS_UFS_QUOTA_H_
183229985Sghelmerstruct fstab;
184207736Smckusickstruct quotafile;
185229988Sghelmerint	quota_check_path(const struct quotafile *_qf, const char *_path);
186229988Sghelmervoid	quota_close(struct quotafile *_qf);
187229988Sghelmerint	quota_convert(struct quotafile *_qf, int _wordsize);
188229988Sghelmerconst char *
189229988Sghelmer	quota_fsname(const struct quotafile *_qf);
190229988Sghelmerint	quota_maxid(struct quotafile *_qf);
191229988Sghelmerint	quota_off(struct quotafile *_qf);
192229988Sghelmerint	quota_on(struct quotafile *_qf);
193229988Sghelmerstruct quotafile *
194229988Sghelmer	quota_open(struct fstab *_fs, int _quotatype, int _openflags);
195229988Sghelmerconst char *
196229988Sghelmer	quota_qfname(const struct quotafile *_qf);
197229988Sghelmerint	quota_read(struct quotafile *_qf, struct dqblk *_dqb, int _id);
198229988Sghelmerint	quota_write_limits(struct quotafile *_qf, struct dqblk *_dqb, int _id);
199229988Sghelmerint	quota_write_usage(struct quotafile *_qf, struct dqblk *_dqb, int _id);
200207736Smckusick#endif
201207736Smckusick
20213137Speter__END_DECLS
20313137Speter
20455227Speter/* fparseln(3) */
20555227Speter#define	FPARSELN_UNESCESC	0x01
20655227Speter#define	FPARSELN_UNESCCONT	0x02
20755227Speter#define	FPARSELN_UNESCCOMM	0x04
20855227Speter#define	FPARSELN_UNESCREST	0x08
20955227Speter#define	FPARSELN_UNESCALL	0x0f
21055227Speter
211230233Sghelmer/* Flags for hexdump(3). */
212180161Sjhb#define	HD_COLUMN_MASK		0xff
213180161Sjhb#define	HD_DELIM_MASK		0xff00
214180161Sjhb#define	HD_OMIT_COUNT		(1 << 16)
215180161Sjhb#define	HD_OMIT_HEX		(1 << 17)
216180161Sjhb#define	HD_OMIT_CHARS		(1 << 18)
217180161Sjhb
218230600Sghelmer/* Values for humanize_number(3)'s flags parameter. */
219230233Sghelmer#define	HN_DECIMAL		0x01
220230233Sghelmer#define	HN_NOSPACE		0x02
221230233Sghelmer#define	HN_B			0x04
222230233Sghelmer#define	HN_DIVISOR_1000		0x08
223230233Sghelmer#define	HN_IEC_PREFIXES		0x10
224230233Sghelmer
225230600Sghelmer/* Values for humanize_number(3)'s scale parameter. */
226230233Sghelmer#define	HN_GETSCALE		0x10
227230233Sghelmer#define	HN_AUTOSCALE		0x20
228230233Sghelmer
229230600Sghelmer/* Return values from realhostname(). */
230230233Sghelmer#define	HOSTNAME_FOUND		0
231230233Sghelmer#define	HOSTNAME_INCORRECTNAME	1
232230233Sghelmer#define	HOSTNAME_INVALIDADDR	2
233230233Sghelmer#define	HOSTNAME_INVALIDNAME	3
234230233Sghelmer
235230233Sghelmer/* Flags for pw_scan(). */
236230233Sghelmer#define	PWSCAN_MASTER		0x01
237230233Sghelmer#define	PWSCAN_WARN		0x02
238230233Sghelmer
239230233Sghelmer/* Return values from uu_lock(). */
240230233Sghelmer#define	UU_LOCK_INUSE		1
241230233Sghelmer#define	UU_LOCK_OK		0
242230599Sghelmer#define	UU_LOCK_OPEN_ERR	(-1)
243230599Sghelmer#define	UU_LOCK_READ_ERR	(-2)
244230599Sghelmer#define	UU_LOCK_CREAT_ERR	(-3)
245230599Sghelmer#define	UU_LOCK_WRITE_ERR	(-4)
246230599Sghelmer#define	UU_LOCK_LINK_ERR	(-5)
247230599Sghelmer#define	UU_LOCK_TRY_ERR		(-6)
248230599Sghelmer#define	UU_LOCK_OWNER_ERR	(-7)
249230233Sghelmer
25013137Speter#endif /* !_LIBUTIL_H_ */
251