1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*
* Amanda, The Advanced Maryland Automatic Network Disk Archiver
* Copyright (c) 1997-1998 University of Maryland at College Park
* Copyright (c) 2007-2012 Zmanda, Inc All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of U.M. not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. U.M. makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: AMANDA core development group.
*/
#ifndef __AM_FILE_H__
#define __AM_FILE_H__
extern int mkpdir(char *file, mode_t mode, uid_t uid, gid_t gid);
extern int rmpdir(char *file, char *topdir);
/* Given a pathname, convert it to "canonical form" for this system. Currently,
* this means nothing on POSIX, but means substituting /cygdrive, etc. on Cygwin.
*
* @param pathname: the pathname to canonicalize
* @param result_buf (output): the canonicalize pathname; this should be a buffer of
* at least PATH_MAX bytes.
*/
void canonicalize_pathname(char *pathname, char *result_buf);
extern char *sanitise_filename(char *inp);
char *old_sanitise_filename(char *inp);
void safe_fd(int fd_start, int fd_count);
void safe_fd2(int fd_start, int fd_count, int fd1);
void safe_fd3(int fd_start, int fd_count, int fd1, int fd2);
void safe_cd(void);
void save_core(void);
/* Get the uid of CLIENT_LOGIN, or -1 if it doesn't exist. Note that, if
* only running a server, CLIENT_LOGIN may legitimately not exist.
*
* @returns: userid, or -1 if invalid
*/
uid_t get_client_uid(void);
/* Get the gid of CLIENT_LOGIN, or -1 if it doesn't exist. Note that, if
* only running a server, CLIENT_LOGIN may legitimately not exist.
*
* @returns: groupid, or -1 if invalid
*/
gid_t get_client_gid(void);
extern /*@only@*/ /*@null@*/ char *debug_agets(const char *c, int l, FILE *file);
extern /*@only@*/ /*@null@*/ char *debug_pgets(const char *c, int l, FILE *file);
extern /*@only@*/ /*@null@*/ char *debug_areads(const char *c, int l, int fd);
#define agets(f) debug_agets(__FILE__,__LINE__,(f))
#define pgets(f) debug_pgets(__FILE__,__LINE__,(f))
#define areads(f) debug_areads(__FILE__,__LINE__,(f))
ssize_t areads_dataready(int fd);
void areads_relbuf(int fd);
/*
* "Safe" close macros. Close the object then set it to a value that
* will cause an error if referenced.
*
* aclose(fd) -- close a file descriptor and set it to -1.
* afclose(f) -- close a stdio file and set it to NULL.
* apclose(p) -- close a stdio pipe file and set it to NULL.
*
* Note: be careful not to do the following:
*
* for(fd = low; fd < high; fd++) {
* aclose(fd);
* }
*
* Since aclose() sets the argument to -1, this will loop forever.
* Just copy fd to a temp variable and use that with aclose().
*
* Aclose() interacts with areads() to inform it to release any buffer
* it has outstanding on the file descriptor.
*/
#define aclose(fd) do { \
if((fd) >= 0) { \
close(fd); \
} \
(fd) = -1; \
} while(0)
#define aaclose(fd) do { \
if((fd) >= 0) { \
close(fd); \
areads_relbuf(fd); \
} \
(fd) = -1; \
} while(0)
#define afclose(f) do { \
if((f) != NULL) { \
fclose(f); \
} \
(f) = NULL; \
} while(0)
#define apclose(p) do { \
if((p) != NULL) { \
pclose(p); \
} \
(p) = NULL; \
} while(0)
/* Calls system open(), but takes care of interrupted system calls and
* clears the close-on-exec bit. In the failure case, errno is
* retained from the final call to open(). */
extern int robust_open(const char * pathname, int flags, mode_t mode);
/* Same idea but for close. */
extern int robust_close(int fd);
/* Get the original working directory, at application startup
*
* @returns: pointer to statically allocated string
*/
char *get_original_cwd(void);
/**
* Read up to "count" bytes from a file descriptor, optionally collecting the
* read operation status (0 on success, not 0 otherwise).
*
* This function exists to overcome the confusing behavior of full_read():
*
* - unlike read(2), full_read() does not return -1 on failure;
* - errno needs to be explicitly checked for each time the number of bytes
* actually read is less than the "count" argument.
*
* With this function, a full read becomes a one time process. Error collecting
* is optional.
*
* @param fd: the file descriptor to read from
* @param buf: the buffer to write data into
* @param count: the number of bytes to write into the buffer
* @param err (output): 0 if "count" bytes have been read; errno (as set by
* full_read()) otherwise
* @returns: the number of bytes read from the file descriptor
*/
gsize read_fully(int fd, void *buf, gsize count, int *err);
char *untaint_fgets(char *s, int size, FILE *stream);
#endif /* __AM_FILE_H__ */
|