/*++ /* NAME /* safe_open 3 /* SUMMARY /* safely open or create regular file /* SYNOPSIS /* #include <safe_open.h> /* /* VSTREAM *safe_open(path, flags, mode, st, user, group, why) /* const char *path; /* int flags; /* mode_t mode; /* struct stat *st; /* uid_t user; /* gid_t group; /* VSTRING *why; /* DESCRIPTION /* safe_open() carefully opens or creates a file in a directory /* that may be writable by untrusted users. If a file is created /* it is given the specified ownership and permission attributes. /* If an existing file is opened it must not be a symbolic link, /* it must not be a directory, and it must have only one hard link. /* /* Arguments: /* .IP "path, flags, mode" /* These arguments are the same as with open(2). The O_EXCL flag /* must appear either in combination with O_CREAT, or not at all. /* .sp /* No change is made to the permissions of an existing file. /* .IP st /* Null pointer, or pointer to storage for the attributes of the /* opened file. /* .IP "user, group" /* File ownership for a file created by safe_open(). Specify -1 /* in order to disable user and/or group ownership change. /* .sp /* No change is made to the ownership of an existing file. /* .IP why /* A VSTRING pointer for diagnostics. /* DIAGNOSTICS /* Panic: interface violations. /* /* A null result means there was a problem. The nature of the /* problem is returned via the \fIwhy\fR buffer; when an error /* cannot be reported via \fIerrno\fR, the generic value EPERM /* (operation not permitted) is used instead. /* HISTORY /* .fi /* .ad /* A safe open routine was discussed by Casper Dik in article /* <2rdb0s$568@mail.fwi.uva.nl>, posted to comp.security.unix /* (May 18, 1994). /* /* Olaf Kirch discusses how the lstat()/open()+fstat() test can /* be fooled by delaying the open() until the inode found with /* lstat() has been re-used for a sensitive file (article /* <20000103212443.A5807@monad.swb.de> posted to bugtraq on /* Jan 3, 2000). This can be a concern for a set-ugid process /* that runs under the control of a user and that can be /* manipulated with start/stop signals. /* LICENSE /* .ad /* .fi /* The Secure Mailer license must be distributed with this software. /* AUTHOR(S) /* Wietse Venema /* IBM T.J. Watson Research /* P.O. Box 704 /* Yorktown Heights, NY 10598, USA
/*--*/
static VSTREAM *safe_open_exist(constchar *path, int flags, struct stat * fstat_st, VSTRING *why)
{ struct stat local_statbuf; struct stat lstat_st; int saved_errno;
VSTREAM *fp;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.