2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1997-1998 University of Maryland at College Park
4 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that
10 * copyright notice and this permission notice appear in supporting
11 * documentation, and that the name of U.M. not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. U.M. makes no representations about the
14 * suitability of this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
17 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: AMANDA core development group.
27 extern int mkpdir(char *file, mode_t mode, uid_t uid, gid_t gid);
28 extern int rmpdir(char *file, char *topdir);
30 /* Given a pathname, convert it to "canonical form" for this system. Currently,
31 * this means nothing on POSIX, but means substituting /cygdrive, etc. on Cygwin.
33 * @param pathname: the pathname to canonicalize
34 * @param result_buf (output): the canonicalize pathname; this should be a buffer of
35 * at least PATH_MAX bytes.
37 void canonicalize_pathname(char *pathname, char *result_buf);
39 extern char *sanitise_filename(char *inp);
40 char *old_sanitise_filename(char *inp);
41 void safe_fd(int fd_start, int fd_count);
45 /* Get the uid of CLIENT_LOGIN, or -1 if it doesn't exist. Note that, if
46 * only running a server, CLIENT_LOGIN may legitimately not exist.
48 * @returns: userid, or -1 if invalid
50 uid_t get_client_uid(void);
52 /* Get the gid of CLIENT_LOGIN, or -1 if it doesn't exist. Note that, if
53 * only running a server, CLIENT_LOGIN may legitimately not exist.
55 * @returns: groupid, or -1 if invalid
57 gid_t get_client_gid(void);
59 extern /*@only@*/ /*@null@*/ char *debug_agets(const char *c, int l, FILE *file);
60 extern /*@only@*/ /*@null@*/ char *debug_areads(const char *c, int l, int fd);
61 #define agets(f) debug_agets(__FILE__,__LINE__,(f))
62 #define areads(f) debug_areads(__FILE__,__LINE__,(f))
64 ssize_t areads_dataready(int fd);
65 void areads_relbuf(int fd);
68 * "Safe" close macros. Close the object then set it to a value that
69 * will cause an error if referenced.
71 * aclose(fd) -- close a file descriptor and set it to -1.
72 * afclose(f) -- close a stdio file and set it to NULL.
73 * apclose(p) -- close a stdio pipe file and set it to NULL.
75 * Note: be careful not to do the following:
77 * for(fd = low; fd < high; fd++) {
81 * Since aclose() sets the argument to -1, this will loop forever.
82 * Just copy fd to a temp variable and use that with aclose().
84 * Aclose() interacts with areads() to inform it to release any buffer
85 * it has outstanding on the file descriptor.
88 #define aclose(fd) do { \
96 #define afclose(f) do { \
103 #define apclose(p) do { \
111 /* Calls system open(), but takes care of interrupted system calls and
112 * clears the close-on-exec bit. In the failure case, errno is
113 * retained from the final call to open(). */
114 extern int robust_open(const char * pathname, int flags, mode_t mode);
116 /* Same idea but for close. */
117 extern int robust_close(int fd);
119 /* Get the original working directory, at application startup
121 * @returns: pointer to statically allocated string
123 char *get_original_cwd(void);