-
Notifications
You must be signed in to change notification settings - Fork 7
/
sysstr.c
183 lines (161 loc) · 3.79 KB
/
sysstr.c
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* Part of Very Secure FTPd
* Licence: GPL v2
* Author: Chris Evans
* sysstr.c
*
* This file basically wraps system functions so that we can deal in our
* nice abstracted string buffer objects.
*/
#include "sysstr.h"
#include "str.h"
#include "secbuf.h"
#include "sysutil.h"
#include "defs.h"
#include "utility.h"
#include "tunables.h"
void
str_getcwd(struct mystr* p_str)
{
static char* p_getcwd_buf;
char* p_ret;
if (p_getcwd_buf == 0)
{
vsf_secbuf_alloc(&p_getcwd_buf, VSFTP_PATH_MAX);
}
/* In case getcwd() fails */
str_empty(p_str);
p_ret = vsf_sysutil_getcwd(p_getcwd_buf, VSFTP_PATH_MAX);
if (p_ret != 0)
{
str_alloc_text(p_str, p_getcwd_buf);
}
}
int
str_write_loop(const struct mystr* p_str, const int fd)
{
return vsf_sysutil_write_loop(fd, str_getbuf(p_str), str_getlen(p_str));
}
int
str_read_loop(struct mystr* p_str, const int fd)
{
return vsf_sysutil_read_loop(
fd, (char*) str_getbuf(p_str), str_getlen(p_str));
}
int
str_mkdir(const struct mystr* p_str, const unsigned int mode)
{
return vsf_sysutil_mkdir(str_getbuf(p_str), mode);
}
int
str_rmdir(const struct mystr* p_str)
{
return vsf_sysutil_rmdir(str_getbuf(p_str));
}
int
str_unlink(const struct mystr* p_str)
{
return vsf_sysutil_unlink(str_getbuf(p_str));
}
int
str_chdir(const struct mystr* p_str)
{
return vsf_sysutil_chdir(str_getbuf(p_str));
}
int
str_open(const struct mystr* p_str, const enum EVSFSysStrOpenMode mode)
{
enum EVSFSysUtilOpenMode open_mode = kVSFSysStrOpenUnknown;
switch (mode)
{
case kVSFSysStrOpenReadOnly:
open_mode = kVSFSysUtilOpenReadOnly;
break;
default:
bug("unknown mode value in str_open");
break;
}
return vsf_sysutil_open_file(str_getbuf(p_str), open_mode);
}
int
str_stat(const struct mystr* p_str, struct vsf_sysutil_statbuf** p_ptr)
{
return vsf_sysutil_stat(str_getbuf(p_str), p_ptr);
}
int
str_lstat(const struct mystr* p_str, struct vsf_sysutil_statbuf** p_ptr)
{
return vsf_sysutil_lstat(str_getbuf(p_str), p_ptr);
}
int
str_create(const struct mystr* p_str)
{
return vsf_sysutil_create_file(str_getbuf(p_str));
}
int
str_create_overwrite(const struct mystr* p_str)
{
return vsf_sysutil_create_overwrite_file(str_getbuf(p_str));
}
int
str_create_append(const struct mystr* p_str)
{
return vsf_sysutil_create_or_open_file(
str_getbuf(p_str), tunable_file_open_mode);
}
int
str_chmod(const struct mystr* p_str, unsigned int mode)
{
return vsf_sysutil_chmod(str_getbuf(p_str), mode);
}
int
str_rename(const struct mystr* p_from_str, const struct mystr* p_to_str)
{
return vsf_sysutil_rename(str_getbuf(p_from_str), str_getbuf(p_to_str));
}
struct vsf_sysutil_dir*
str_opendir(const struct mystr* p_str)
{
return vsf_sysutil_opendir(str_getbuf(p_str));
}
void
str_next_dirent(struct mystr* p_filename_str, struct vsf_sysutil_dir* p_dir)
{
const char* p_filename = vsf_sysutil_next_dirent(p_dir);
str_empty(p_filename_str);
if (p_filename != 0)
{
str_alloc_text(p_filename_str, p_filename);
}
}
int
str_readlink(struct mystr* p_str, const struct mystr* p_filename_str)
{
static char* p_readlink_buf;
int retval;
if (p_readlink_buf == 0)
{
vsf_secbuf_alloc(&p_readlink_buf, VSFTP_PATH_MAX);
}
/* In case readlink() fails */
str_empty(p_str);
/* Note: readlink(2) does not NULL terminate, but our wrapper does */
retval = vsf_sysutil_readlink(str_getbuf(p_filename_str), p_readlink_buf,
VSFTP_PATH_MAX);
if (vsf_sysutil_retval_is_error(retval))
{
return retval;
}
str_alloc_text(p_str, p_readlink_buf);
return 0;
}
struct vsf_sysutil_user*
str_getpwnam(const struct mystr* p_user_str)
{
return vsf_sysutil_getpwnam(str_getbuf(p_user_str));
}
void
str_syslog(const struct mystr* p_str, int severe)
{
vsf_sysutil_syslog(str_getbuf(p_str), severe);
}