libutil.h revision 126299
11556Srgrimes/*
21556Srgrimes * Copyright (c) 1996  Peter Wemm <peter@FreeBSD.org>.
31556Srgrimes * All rights reserved.
41556Srgrimes * Copyright (c) 2002 Networks Associates Technology, Inc.
51556Srgrimes * All rights reserved.
61556Srgrimes *
71556Srgrimes * Portions of this software were developed for the FreeBSD Project by
81556Srgrimes * ThinkSec AS and NAI Labs, the Security Research Division of Network
91556Srgrimes * Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
101556Srgrimes * ("CBOSS"), as part of the DARPA CHATS research program.
111556Srgrimes *
121556Srgrimes * Redistribution and use in source and binary forms, with or without
131556Srgrimes * modification, is permitted provided that the following conditions
141556Srgrimes * are met:
151556Srgrimes * 1. Redistributions of source code must retain the above copyright
161556Srgrimes *    notice, this list of conditions and the following disclaimer.
171556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
181556Srgrimes *    notice, this list of conditions and the following disclaimer in the
191556Srgrimes *    documentation and/or other materials provided with the distribution.
201556Srgrimes * 3. The name of the author may not be used to endorse or promote
211556Srgrimes *    products derived from this software without specific prior written
221556Srgrimes *    permission.
231556Srgrimes *
241556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
251556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
281556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3436150Scharnier * SUCH DAMAGE.
3536150Scharnier *
3636150Scharnier * $FreeBSD: head/lib/libutil/libutil.h 126299 2004-02-26 22:44:11Z kientzle $
371556Srgrimes */
3899110Sobrien
3999110Sobrien#ifndef _LIBUTIL_H_
401556Srgrimes#define	_LIBUTIL_H_
4117987Speter
4217987Speter#define PROPERTY_MAX_NAME	64
4317987Speter#define PROPERTY_MAX_VALUE	512
4420425Ssteve
4517987Speter/* for properties.c */
4617987Spetertypedef struct _property {
47100661Stjr	struct _property *next;
4817987Speter	char *name;
491556Srgrimes	char *value;
501556Srgrimes} *properties;
511556Srgrimes
521556Srgrimes/* Avoid pulling in all the include files for no need */
531556Srgrimesstruct termios;
541556Srgrimesstruct winsize;
551556Srgrimesstruct utmp;
561556Srgrimesstruct in_addr;
571556Srgrimes
581556Srgrimes__BEGIN_DECLS
591556Srgrimesvoid	clean_environment(const char * const *_white,
601556Srgrimes	    const char * const *_more_white);
6120425Ssteveint	extattr_namespace_to_string(int _attrnamespace, char **_string);
6217987Speterint	extattr_string_to_namespace(const char *_string, int *_attrnamespace);
631556Srgrimesvoid	login(struct utmp *_ut);
6417987Speterint	login_tty(int _fd);
6520425Ssteveint	logout(const char *_line);
66223060Sjillesvoid	logwtmp(const char *_line, const char *_name, const char *_host);
671556Srgrimesvoid	trimdomain(char *_fullhost, int _hostsize);
68213811Sobrienint	openpty(int *_amaster, int *_aslave, char *_name,
69213811Sobrien		     struct termios *_termp, struct winsize *_winp);
70213811Sobrienint	forkpty(int *_amaster, char *_name,
71213811Sobrien		     struct termios *_termp, struct winsize *_winp);
72213811Sobrienconst char *uu_lockerr(int _uu_lockresult);
73213811Sobrienint	uu_lock(const char *_ttyname);
74213811Sobrienint	uu_unlock(const char *_ttyname);
75213811Sobrienint	uu_lock_txfr(const char *_ttyname, pid_t _pid);
761556Srgrimesint	_secure_path(const char *_path, uid_t _uid, gid_t _gid);
77213760Sobrienproperties properties_read(int fd);
78213760Sobrienvoid	properties_free(properties list);
79213760Sobrienchar	*property_find(properties list, const char *name);
801556Srgrimeschar	*auth_getval(const char *name);
811556Srgrimesint	realhostname(char *host, size_t hsize, const struct in_addr *ip);
82240541Sjillesstruct sockaddr;
8317987Speterint	realhostname_sa(char *host, size_t hsize, struct sockaddr *addr,
84201053Sjilles			     int addrlen);
85200956Sjilles#ifdef _STDIO_H_	/* avoid adding new includes */
861556Srgrimeschar   *fparseln(FILE *, size_t *, size_t *, const char[3], int);
871556Srgrimes#endif
88222154Sjilles
89222154Sjilles#ifdef _PWD_H_
90222292Sjillesint	pw_copy(int _ffd, int _tfd, const struct passwd *_pw, struct passwd *_old_pw);
911556Srgrimesstruct passwd *pw_dup(const struct passwd *_pw);
92100664Stjrint	pw_edit(int _notsetuid);
93240541Sjillesint	pw_equal(const struct passwd *_pw1, const struct passwd *_pw2);
9497092Stjrvoid	pw_fini(void);
95222154Sjillesint	pw_init(const char *_dir, const char *_master);
96222154Sjilleschar	*pw_make(const struct passwd *_pw);
97222154Sjillesint	pw_mkdb(const char *_user);
9897092Stjrint	pw_lock(void);
9997092Stjrstruct passwd *pw_scan(const char *_line, int _flags);
10097092Stjrconst char *pw_tempname(void);
10197092Stjrint	pw_tmp(int _mfd);
10297092Stjr#endif
10397092Stjr__END_DECLS
10497092Stjr
10597092Stjr#define UU_LOCK_INUSE (1)
10697092Stjr#define UU_LOCK_OK (0)
107240541Sjilles#define UU_LOCK_OPEN_ERR (-1)
10897092Stjr#define UU_LOCK_READ_ERR (-2)
10997092Stjr#define UU_LOCK_CREAT_ERR (-3)
110240541Sjilles#define UU_LOCK_WRITE_ERR (-4)
1111556Srgrimes#define UU_LOCK_LINK_ERR (-5)
1125234Sbde#define UU_LOCK_TRY_ERR (-6)
1135234Sbde#define UU_LOCK_OWNER_ERR (-7)
1141556Srgrimes
1151556Srgrimes/* return values from realhostname() */
11612273Speter#define HOSTNAME_FOUND		(0)
11712273Speter#define HOSTNAME_INCORRECTNAME	(1)
11812273Speter#define HOSTNAME_INVALIDADDR	(2)
11912273Speter#define HOSTNAME_INVALIDNAME	(3)
1201556Srgrimes
121222381Sjilles/* fparseln(3) */
122222381Sjilles#define	FPARSELN_UNESCESC	0x01
123222381Sjilles#define	FPARSELN_UNESCCONT	0x02
124222381Sjilles#define	FPARSELN_UNESCCOMM	0x04
1251556Srgrimes#define	FPARSELN_UNESCREST	0x08
1261556Srgrimes#define	FPARSELN_UNESCALL	0x0f
127230095Sjilles
128230095Sjilles/* pw_scan() */
129230095Sjilles#define PWSCAN_MASTER		0x01
130230095Sjilles#define PWSCAN_WARN		0x02
131230095Sjilles
132230095Sjilles#endif /* !_LIBUTIL_H_ */
1331556Srgrimes