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