dnscrypto-proxy: Support files updated.
[tomato.git] / release / src / router / vsftpd / sysstr.c
blob42fd4b4118b042dc7d62d84efa7a0b06dfa804dc
1 /*
2 * Part of Very Secure FTPd
3 * Licence: GPL v2
4 * Author: Chris Evans
5 * sysstr.c
7 * This file basically wraps system functions so that we can deal in our
8 * nice abstracted string buffer objects.
9 */
11 #include "sysstr.h"
12 #include "str.h"
13 #include "secbuf.h"
14 #include "sysutil.h"
15 #include "defs.h"
16 #include "utility.h"
17 #include "tunables.h"
19 void
20 str_getcwd(struct mystr* p_str)
22 static char* p_getcwd_buf;
23 char* p_ret;
24 if (p_getcwd_buf == 0)
26 vsf_secbuf_alloc(&p_getcwd_buf, VSFTP_PATH_MAX);
28 /* In case getcwd() fails */
29 str_empty(p_str);
30 p_ret = vsf_sysutil_getcwd(p_getcwd_buf, VSFTP_PATH_MAX);
31 if (p_ret != 0)
33 str_alloc_text(p_str, p_getcwd_buf);
37 int
38 str_write_loop(const struct mystr* p_str, const int fd)
40 return vsf_sysutil_write_loop(fd, str_getbuf(p_str), str_getlen(p_str));
43 int
44 str_read_loop(struct mystr* p_str, const int fd)
46 return vsf_sysutil_read_loop(
47 fd, (char*) str_getbuf(p_str), str_getlen(p_str));
50 int
51 str_mkdir(const struct mystr* p_str, const unsigned int mode)
53 return vsf_sysutil_mkdir(str_getbuf(p_str), mode);
56 int
57 str_rmdir(const struct mystr* p_str)
59 return vsf_sysutil_rmdir(str_getbuf(p_str));
62 int
63 str_unlink(const struct mystr* p_str)
65 return vsf_sysutil_unlink(str_getbuf(p_str));
68 int
69 str_chdir(const struct mystr* p_str)
71 return vsf_sysutil_chdir(str_getbuf(p_str));
74 int
75 str_open(const struct mystr* p_str, const enum EVSFSysStrOpenMode mode)
77 enum EVSFSysUtilOpenMode open_mode = kVSFSysStrOpenUnknown;
78 switch (mode)
80 case kVSFSysStrOpenReadOnly:
81 open_mode = kVSFSysUtilOpenReadOnly;
82 break;
83 default:
84 bug("unknown mode value in str_open");
85 break;
87 return vsf_sysutil_open_file(str_getbuf(p_str), open_mode);
90 int
91 str_stat(const struct mystr* p_str, struct vsf_sysutil_statbuf** p_ptr)
93 return vsf_sysutil_stat(str_getbuf(p_str), p_ptr);
96 int
97 str_lstat(const struct mystr* p_str, struct vsf_sysutil_statbuf** p_ptr)
99 return vsf_sysutil_lstat(str_getbuf(p_str), p_ptr);
103 str_create_exclusive(const struct mystr* p_str)
105 return vsf_sysutil_create_file_exclusive(str_getbuf(p_str));
109 str_create(const struct mystr* p_str)
111 return vsf_sysutil_create_or_open_file(
112 str_getbuf(p_str), tunable_file_open_mode);
116 str_chmod(const struct mystr* p_str, unsigned int mode)
118 return vsf_sysutil_chmod(str_getbuf(p_str), mode);
122 str_rename(const struct mystr* p_from_str, const struct mystr* p_to_str)
124 return vsf_sysutil_rename(str_getbuf(p_from_str), str_getbuf(p_to_str));
127 struct vsf_sysutil_dir*
128 str_opendir(const struct mystr* p_str)
130 return vsf_sysutil_opendir(str_getbuf(p_str));
133 void
134 str_next_dirent(struct mystr* p_filename_str, struct vsf_sysutil_dir* p_dir)
136 const char* p_filename = vsf_sysutil_next_dirent(p_dir);
137 str_empty(p_filename_str);
138 if (p_filename != 0)
140 str_alloc_text(p_filename_str, p_filename);
145 str_readlink(struct mystr* p_str, const struct mystr* p_filename_str)
147 static char* p_readlink_buf;
148 int retval;
149 if (p_readlink_buf == 0)
151 vsf_secbuf_alloc(&p_readlink_buf, VSFTP_PATH_MAX);
153 /* In case readlink() fails */
154 str_empty(p_str);
155 /* Note: readlink(2) does not NULL terminate, but our wrapper does */
156 retval = vsf_sysutil_readlink(str_getbuf(p_filename_str), p_readlink_buf,
157 VSFTP_PATH_MAX);
158 if (vsf_sysutil_retval_is_error(retval))
160 return retval;
162 str_alloc_text(p_str, p_readlink_buf);
163 return 0;
166 struct vsf_sysutil_user*
167 str_getpwnam(const struct mystr* p_user_str)
169 return vsf_sysutil_getpwnam(str_getbuf(p_user_str));
172 void
173 str_syslog(const struct mystr* p_str, int severe)
175 vsf_sysutil_syslog(str_getbuf(p_str), severe);