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); 105288453Sjhbstruct kinfo_vmobject * 106288453Sjhb kinfo_getvmobject(int *_cntp); 107221807Sstasstruct kinfo_proc * 108221807Sstas kinfo_getallproc(int *_cntp); 109221807Sstasstruct kinfo_proc * 110221807Sstas kinfo_getproc(pid_t _pid); 111229986Sghelmerint kld_isloaded(const char *_name); 112229986Sghelmerint kld_load(const char *_name); 113229985Sghelmerint login_tty(int _fd); 114229985Sghelmerint openpty(int *_amaster, int *_aslave, char *_name, 115229988Sghelmer struct termios *_termp, struct winsize *_winp); 116230233Sghelmerint pidfile_close(struct pidfh *_pfh); 117230233Sghelmerint pidfile_fileno(const struct pidfh *_pfh); 118230233Sghelmerstruct pidfh * 119230233Sghelmer pidfile_open(const char *_path, mode_t _mode, pid_t *_pidptr); 120230233Sghelmerint pidfile_remove(struct pidfh *_pfh); 121230233Sghelmerint pidfile_write(struct pidfh *_pfh); 122229986Sghelmervoid properties_free(properties _list); 123229986Sghelmerchar *property_find(properties _list, const char *_name); 124229988Sghelmerproperties 125230011Sghelmer properties_read(int _fd); 126229986Sghelmerint realhostname(char *_host, size_t _hsize, const struct in_addr *_ip); 127229986Sghelmerint realhostname_sa(char *_host, size_t _hsize, struct sockaddr *_addr, 128229988Sghelmer int _addrlen); 129229985Sghelmerint _secure_path(const char *_path, uid_t _uid, gid_t _gid); 130229985Sghelmervoid trimdomain(char *_fullhost, int _hostsize); 131229988Sghelmerconst char * 132229988Sghelmer uu_lockerr(int _uu_lockresult); 133229985Sghelmerint uu_lock(const char *_ttyname); 134229985Sghelmerint uu_unlock(const char *_ttyname); 135229985Sghelmerint uu_lock_txfr(const char *_ttyname, pid_t _pid); 136155804Sdes 137230600Sghelmer/* 138230600Sghelmer * Conditionally prototype the following functions if the include 139230600Sghelmer * files upon which they depend have been included. 140230600Sghelmer */ 141230600Sghelmer#ifdef _STDIO_H_ 142229988Sghelmerchar *fparseln(FILE *_fp, size_t *_len, size_t *_lineno, 143229988Sghelmer const char _delim[3], int _flags); 14455227Speter#endif 14596199Sdes 14696199Sdes#ifdef _PWD_H_ 147230011Sghelmerint pw_copy(int _ffd, int _tfd, const struct passwd *_pw, 148230011Sghelmer struct passwd *_old_pw); 149230011Sghelmerstruct passwd 150230011Sghelmer *pw_dup(const struct passwd *_pw); 15196199Sdesint pw_edit(int _notsetuid); 152121193Smarkmint pw_equal(const struct passwd *_pw1, const struct passwd *_pw2); 15396199Sdesvoid pw_fini(void); 15496199Sdesint pw_init(const char *_dir, const char *_master); 155121193Smarkmchar *pw_make(const struct passwd *_pw); 156229572Sbaptchar *pw_make_v7(const struct passwd *_pw); 15796199Sdesint pw_mkdb(const char *_user); 15896199Sdesint pw_lock(void); 159230601Sghelmerstruct passwd * 160230601Sghelmer pw_scan(const char *_line, int _flags); 161230601Sghelmerconst char * 162230601Sghelmer pw_tempname(void); 16396199Sdesint pw_tmp(int _mfd); 16496199Sdes#endif 165149423Spjd 166178431Sscf#ifdef _GRP_H_ 167230011Sghelmerint gr_copy(int __ffd, int _tfd, const struct group *_gr, 168230011Sghelmer struct group *_old_gr); 169230601Sghelmerstruct group * 170230601Sghelmer gr_dup(const struct group *_gr); 171244736Sbaptstruct group * 172247919Sdb gr_add(const struct group *_gr, const char *_newmember); 173229986Sghelmerint gr_equal(const struct group *_gr1, const struct group *_gr2); 174228545Sbaptvoid gr_fini(void); 175228545Sbaptint gr_init(const char *_dir, const char *_master); 176228545Sbaptint gr_lock(void); 177229986Sghelmerchar *gr_make(const struct group *_gr); 178228545Sbaptint gr_mkdb(void); 179230601Sghelmerstruct group * 180230601Sghelmer gr_scan(const char *_line); 181228545Sbaptint gr_tmp(int _mdf); 182178431Sscf#endif 183178431Sscf 184207736Smckusick#ifdef _UFS_UFS_QUOTA_H_ 185229985Sghelmerstruct fstab; 186207736Smckusickstruct quotafile; 187229988Sghelmerint quota_check_path(const struct quotafile *_qf, const char *_path); 188229988Sghelmervoid quota_close(struct quotafile *_qf); 189229988Sghelmerint quota_convert(struct quotafile *_qf, int _wordsize); 190229988Sghelmerconst char * 191229988Sghelmer quota_fsname(const struct quotafile *_qf); 192229988Sghelmerint quota_maxid(struct quotafile *_qf); 193229988Sghelmerint quota_off(struct quotafile *_qf); 194229988Sghelmerint quota_on(struct quotafile *_qf); 195229988Sghelmerstruct quotafile * 196229988Sghelmer quota_open(struct fstab *_fs, int _quotatype, int _openflags); 197229988Sghelmerconst char * 198229988Sghelmer quota_qfname(const struct quotafile *_qf); 199229988Sghelmerint quota_read(struct quotafile *_qf, struct dqblk *_dqb, int _id); 200229988Sghelmerint quota_write_limits(struct quotafile *_qf, struct dqblk *_dqb, int _id); 201229988Sghelmerint quota_write_usage(struct quotafile *_qf, struct dqblk *_dqb, int _id); 202207736Smckusick#endif 203207736Smckusick 20413137Speter__END_DECLS 20513137Speter 20655227Speter/* fparseln(3) */ 20755227Speter#define FPARSELN_UNESCESC 0x01 20855227Speter#define FPARSELN_UNESCCONT 0x02 20955227Speter#define FPARSELN_UNESCCOMM 0x04 21055227Speter#define FPARSELN_UNESCREST 0x08 21155227Speter#define FPARSELN_UNESCALL 0x0f 21255227Speter 213230233Sghelmer/* Flags for hexdump(3). */ 214180161Sjhb#define HD_COLUMN_MASK 0xff 215180161Sjhb#define HD_DELIM_MASK 0xff00 216180161Sjhb#define HD_OMIT_COUNT (1 << 16) 217180161Sjhb#define HD_OMIT_HEX (1 << 17) 218180161Sjhb#define HD_OMIT_CHARS (1 << 18) 219180161Sjhb 220230600Sghelmer/* Values for humanize_number(3)'s flags parameter. */ 221230233Sghelmer#define HN_DECIMAL 0x01 222230233Sghelmer#define HN_NOSPACE 0x02 223230233Sghelmer#define HN_B 0x04 224230233Sghelmer#define HN_DIVISOR_1000 0x08 225230233Sghelmer#define HN_IEC_PREFIXES 0x10 226230233Sghelmer 227230600Sghelmer/* Values for humanize_number(3)'s scale parameter. */ 228230233Sghelmer#define HN_GETSCALE 0x10 229230233Sghelmer#define HN_AUTOSCALE 0x20 230230233Sghelmer 231230600Sghelmer/* Return values from realhostname(). */ 232230233Sghelmer#define HOSTNAME_FOUND 0 233230233Sghelmer#define HOSTNAME_INCORRECTNAME 1 234230233Sghelmer#define HOSTNAME_INVALIDADDR 2 235230233Sghelmer#define HOSTNAME_INVALIDNAME 3 236230233Sghelmer 237230233Sghelmer/* Flags for pw_scan(). */ 238230233Sghelmer#define PWSCAN_MASTER 0x01 239230233Sghelmer#define PWSCAN_WARN 0x02 240230233Sghelmer 241230233Sghelmer/* Return values from uu_lock(). */ 242230233Sghelmer#define UU_LOCK_INUSE 1 243230233Sghelmer#define UU_LOCK_OK 0 244230599Sghelmer#define UU_LOCK_OPEN_ERR (-1) 245230599Sghelmer#define UU_LOCK_READ_ERR (-2) 246230599Sghelmer#define UU_LOCK_CREAT_ERR (-3) 247230599Sghelmer#define UU_LOCK_WRITE_ERR (-4) 248230599Sghelmer#define UU_LOCK_LINK_ERR (-5) 249230599Sghelmer#define UU_LOCK_TRY_ERR (-6) 250230599Sghelmer#define UU_LOCK_OWNER_ERR (-7) 251230233Sghelmer 25213137Speter#endif /* !_LIBUTIL_H_ */ 253