2 * Part of Very Secure FTPd
7 * This file basically wraps system functions so that we can deal in our
8 * nice abstracted string buffer objects.
20 str_getcwd(struct mystr
* p_str
)
22 static char* p_getcwd_buf
;
24 if (p_getcwd_buf
== 0)
26 vsf_secbuf_alloc(&p_getcwd_buf
, VSFTP_PATH_MAX
);
28 /* In case getcwd() fails */
30 p_ret
= vsf_sysutil_getcwd(p_getcwd_buf
, VSFTP_PATH_MAX
);
33 str_alloc_text(p_str
, p_getcwd_buf
);
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
));
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
));
51 str_mkdir(const struct mystr
* p_str
, const unsigned int mode
)
53 return vsf_sysutil_mkdir(str_getbuf(p_str
), mode
);
57 str_rmdir(const struct mystr
* p_str
)
59 return vsf_sysutil_rmdir(str_getbuf(p_str
));
63 str_unlink(const struct mystr
* p_str
)
65 return vsf_sysutil_unlink(str_getbuf(p_str
));
69 str_chdir(const struct mystr
* p_str
)
71 return vsf_sysutil_chdir(str_getbuf(p_str
));
75 str_open(const struct mystr
* p_str
, const enum EVSFSysStrOpenMode mode
)
77 enum EVSFSysUtilOpenMode open_mode
= kVSFSysStrOpenUnknown
;
80 case kVSFSysStrOpenReadOnly
:
81 open_mode
= kVSFSysUtilOpenReadOnly
;
84 bug("unknown mode value in str_open");
87 return vsf_sysutil_open_file(str_getbuf(p_str
), open_mode
);
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
);
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
));
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
);
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
;
149 if (p_readlink_buf
== 0)
151 vsf_secbuf_alloc(&p_readlink_buf
, VSFTP_PATH_MAX
);
153 /* In case readlink() fails */
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
,
158 if (vsf_sysutil_retval_is_error(retval
))
162 str_alloc_text(p_str
, p_readlink_buf
);
166 struct vsf_sysutil_user
*
167 str_getpwnam(const struct mystr
* p_user_str
)
169 return vsf_sysutil_getpwnam(str_getbuf(p_user_str
));
173 str_syslog(const struct mystr
* p_str
, int severe
)
175 vsf_sysutil_syslog(str_getbuf(p_str
), severe
);