Merge lp:~stefanor/ubuntu/lucid/samba/ntlm-auth-623342 into lp:ubuntu/lucid-proposed/samba
- Lucid (10.04)
- ntlm-auth-623342
- Merge into lucid-proposed
Proposed by
Stefano Rivera
Status: | Merged |
---|---|
Merge reported by: | Benjamin Drung |
Merged at revision: | not available |
Proposed branch: | lp:~stefanor/ubuntu/lucid/samba/ntlm-auth-623342 |
Merge into: | lp:ubuntu/lucid-proposed/samba |
Diff against target: |
19843 lines (+18478/-101) 96 files modified
.pc/applied-patches (+2/-0) .pc/security-CVE-2011-0719.patch/lib/tevent/tevent_select.c (+247/-0) .pc/security-CVE-2011-0719.patch/lib/tevent/tevent_standard.c (+569/-0) .pc/security-CVE-2011-0719.patch/nsswitch/wb_common.c (+690/-0) .pc/security-CVE-2011-0719.patch/source3/client/client.c (+5022/-0) .pc/security-CVE-2011-0719.patch/source3/client/dnsbrowse.c (+237/-0) .pc/security-CVE-2011-0719.patch/source3/lib/events.c (+304/-0) .pc/security-CVE-2011-0719.patch/source3/lib/packet.c (+267/-0) .pc/security-CVE-2011-0719.patch/source3/lib/readline.c (+201/-0) .pc/security-CVE-2011-0719.patch/source3/lib/select.c (+206/-0) .pc/security-CVE-2011-0719.patch/source3/lib/util_sock.c (+1989/-0) .pc/security-CVE-2011-0719.patch/source3/lib/wbclient.c (+715/-0) .pc/security-CVE-2011-0719.patch/source3/libaddns/dnssock.c (+377/-0) .pc/security-CVE-2011-0719.patch/source3/libads/cldap.c (+308/-0) .pc/security-CVE-2011-0719.patch/source3/libsmb/nmblib.c (+1399/-0) .pc/security-CVE-2011-0719.patch/source3/nmbd/nmbd_packets.c (+1967/-0) .pc/security-CVE-2011-0719.patch/source3/utils/smbfilter.c (+295/-0) .pc/security-CVE-2011-0719.patch/source3/winbindd/winbindd.c (+1440/-0) .pc/security-CVE-2011-0719.patch/source3/winbindd/winbindd_dual.c (+1477/-0) debian/changelog (+18/-0) debian/control (+1/-1) debian/patches/ntlm-auth-lp623342.patch (+63/-0) debian/patches/security-CVE-2011-0719.patch (+438/-0) debian/patches/series (+2/-1) debian/po/ar.po (+1/-1) debian/po/ast.po (+1/-1) debian/po/be.po (+1/-1) debian/po/bg.po (+1/-1) debian/po/bn.po (+1/-1) debian/po/bs.po (+1/-1) debian/po/ca.po (+3/-3) debian/po/cs.po (+1/-1) debian/po/da.po (+1/-1) debian/po/de.po (+1/-1) debian/po/dz.po (+1/-1) debian/po/el.po (+1/-1) debian/po/eo.po (+1/-1) debian/po/es.po (+2/-3) debian/po/et.po (+1/-1) debian/po/eu.po (+1/-1) debian/po/fi.po (+1/-1) debian/po/fr.po (+1/-1) debian/po/gl.po (+1/-1) debian/po/gu.po (+1/-1) debian/po/he.po (+1/-1) debian/po/hu.po (+1/-1) debian/po/id.po (+1/-1) debian/po/it.po (+1/-1) debian/po/ja.po (+1/-1) debian/po/ka.po (+1/-1) debian/po/km.po (+1/-1) debian/po/ko.po (+1/-1) debian/po/ku.po (+1/-1) debian/po/lt.po (+3/-3) debian/po/ml.po (+1/-1) debian/po/mr.po (+4/-4) debian/po/nb.po (+6/-6) debian/po/ne.po (+1/-1) debian/po/nl.po (+1/-1) debian/po/nn.po (+5/-5) debian/po/pl.po (+1/-1) debian/po/pt.po (+1/-1) debian/po/pt_BR.po (+1/-1) debian/po/ro.po (+1/-1) debian/po/ru.po (+3/-3) debian/po/sk.po (+1/-1) debian/po/sl.po (+1/-1) debian/po/sq.po (+1/-1) debian/po/sv.po (+1/-1) debian/po/ta.po (+1/-1) debian/po/th.po (+1/-1) debian/po/tl.po (+1/-1) debian/po/tr.po (+1/-1) debian/po/vi.po (+11/-12) debian/po/wo.po (+1/-1) debian/po/zh_CN.po (+1/-1) debian/po/zh_TW.po (+1/-1) lib/tevent/tevent_select.c (+10/-0) lib/tevent/tevent_standard.c (+5/-0) nsswitch/wb_common.c (+17/-0) source3/client/client.c (+3/-1) source3/client/dnsbrowse.c (+11/-0) source3/lib/events.c (+8/-0) source3/lib/packet.c (+5/-0) source3/lib/readline.c (+5/-0) source3/lib/select.c (+12/-0) source3/lib/util_sock.c (+9/-2) source3/lib/wbclient.c (+8/-1) source3/libaddns/dnssock.c (+5/-0) source3/libads/cldap.c (+5/-0) source3/libsmb/nmblib.c (+5/-0) source3/nmbd/nmbd_packets.c (+22/-2) source3/utils/smbfilter.c (+6/-2) source3/winbindd/winbindd.c (+6/-0) source3/winbindd/winbindd_cm.c (+13/-7) source3/winbindd/winbindd_dual.c (+7/-0) |
To merge this branch: | bzr merge lp:~stefanor/ubuntu/lucid/samba/ntlm-auth-623342 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Development Team | Pending | ||
Review via email: mp+51560@code.launchpad.net |
Commit message
Description of the change
There's a build in https:/
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.pc/applied-patches' | |||
2 | --- .pc/applied-patches 2010-01-16 07:52:30 +0000 | |||
3 | +++ .pc/applied-patches 2011-03-02 20:47:51 +0000 | |||
4 | @@ -17,3 +17,5 @@ | |||
5 | 17 | ubuntu-gecos-fix.patch | 17 | ubuntu-gecos-fix.patch |
6 | 18 | security-CVE-2010-3069.patch | 18 | security-CVE-2010-3069.patch |
7 | 19 | spnego-auth-win7.patch | 19 | spnego-auth-win7.patch |
8 | 20 | security-CVE-2011-0719.patch | ||
9 | 21 | ntlm-auth-lp623342.patch | ||
10 | 20 | 22 | ||
11 | === added directory '.pc/security-CVE-2011-0719.patch' | |||
12 | === added directory '.pc/security-CVE-2011-0719.patch/lib' | |||
13 | === added directory '.pc/security-CVE-2011-0719.patch/lib/tevent' | |||
14 | === added file '.pc/security-CVE-2011-0719.patch/lib/tevent/tevent_select.c' | |||
15 | --- .pc/security-CVE-2011-0719.patch/lib/tevent/tevent_select.c 1970-01-01 00:00:00 +0000 | |||
16 | +++ .pc/security-CVE-2011-0719.patch/lib/tevent/tevent_select.c 2011-03-02 20:47:51 +0000 | |||
17 | @@ -0,0 +1,247 @@ | |||
18 | 1 | /* | ||
19 | 2 | Unix SMB/CIFS implementation. | ||
20 | 3 | main select loop and event handling | ||
21 | 4 | Copyright (C) Andrew Tridgell 2003-2005 | ||
22 | 5 | Copyright (C) Stefan Metzmacher 2005-2009 | ||
23 | 6 | |||
24 | 7 | ** NOTE! The following LGPL license applies to the tevent | ||
25 | 8 | ** library. This does NOT imply that all of Samba is released | ||
26 | 9 | ** under the LGPL | ||
27 | 10 | |||
28 | 11 | This library is free software; you can redistribute it and/or | ||
29 | 12 | modify it under the terms of the GNU Lesser General Public | ||
30 | 13 | License as published by the Free Software Foundation; either | ||
31 | 14 | version 3 of the License, or (at your option) any later version. | ||
32 | 15 | |||
33 | 16 | This library is distributed in the hope that it will be useful, | ||
34 | 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
35 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
36 | 19 | Lesser General Public License for more details. | ||
37 | 20 | |||
38 | 21 | You should have received a copy of the GNU Lesser General Public | ||
39 | 22 | License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
40 | 23 | */ | ||
41 | 24 | |||
42 | 25 | #include "replace.h" | ||
43 | 26 | #include "system/filesys.h" | ||
44 | 27 | #include "system/select.h" | ||
45 | 28 | #include "tevent.h" | ||
46 | 29 | #include "tevent_util.h" | ||
47 | 30 | #include "tevent_internal.h" | ||
48 | 31 | |||
49 | 32 | struct select_event_context { | ||
50 | 33 | /* a pointer back to the generic event_context */ | ||
51 | 34 | struct tevent_context *ev; | ||
52 | 35 | |||
53 | 36 | /* the maximum file descriptor number in fd_events */ | ||
54 | 37 | int maxfd; | ||
55 | 38 | |||
56 | 39 | /* information for exiting from the event loop */ | ||
57 | 40 | int exit_code; | ||
58 | 41 | }; | ||
59 | 42 | |||
60 | 43 | /* | ||
61 | 44 | create a select_event_context structure. | ||
62 | 45 | */ | ||
63 | 46 | static int select_event_context_init(struct tevent_context *ev) | ||
64 | 47 | { | ||
65 | 48 | struct select_event_context *select_ev; | ||
66 | 49 | |||
67 | 50 | select_ev = talloc_zero(ev, struct select_event_context); | ||
68 | 51 | if (!select_ev) return -1; | ||
69 | 52 | select_ev->ev = ev; | ||
70 | 53 | |||
71 | 54 | ev->additional_data = select_ev; | ||
72 | 55 | return 0; | ||
73 | 56 | } | ||
74 | 57 | |||
75 | 58 | /* | ||
76 | 59 | recalculate the maxfd | ||
77 | 60 | */ | ||
78 | 61 | static void calc_maxfd(struct select_event_context *select_ev) | ||
79 | 62 | { | ||
80 | 63 | struct tevent_fd *fde; | ||
81 | 64 | |||
82 | 65 | select_ev->maxfd = 0; | ||
83 | 66 | for (fde = select_ev->ev->fd_events; fde; fde = fde->next) { | ||
84 | 67 | if (fde->fd > select_ev->maxfd) { | ||
85 | 68 | select_ev->maxfd = fde->fd; | ||
86 | 69 | } | ||
87 | 70 | } | ||
88 | 71 | } | ||
89 | 72 | |||
90 | 73 | |||
91 | 74 | /* to mark the ev->maxfd invalid | ||
92 | 75 | * this means we need to recalculate it | ||
93 | 76 | */ | ||
94 | 77 | #define EVENT_INVALID_MAXFD (-1) | ||
95 | 78 | |||
96 | 79 | /* | ||
97 | 80 | destroy an fd_event | ||
98 | 81 | */ | ||
99 | 82 | static int select_event_fd_destructor(struct tevent_fd *fde) | ||
100 | 83 | { | ||
101 | 84 | struct tevent_context *ev = fde->event_ctx; | ||
102 | 85 | struct select_event_context *select_ev = NULL; | ||
103 | 86 | |||
104 | 87 | if (ev) { | ||
105 | 88 | select_ev = talloc_get_type(ev->additional_data, | ||
106 | 89 | struct select_event_context); | ||
107 | 90 | |||
108 | 91 | if (select_ev->maxfd == fde->fd) { | ||
109 | 92 | select_ev->maxfd = EVENT_INVALID_MAXFD; | ||
110 | 93 | } | ||
111 | 94 | } | ||
112 | 95 | |||
113 | 96 | return tevent_common_fd_destructor(fde); | ||
114 | 97 | } | ||
115 | 98 | |||
116 | 99 | /* | ||
117 | 100 | add a fd based event | ||
118 | 101 | return NULL on failure (memory allocation error) | ||
119 | 102 | */ | ||
120 | 103 | static struct tevent_fd *select_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, | ||
121 | 104 | int fd, uint16_t flags, | ||
122 | 105 | tevent_fd_handler_t handler, | ||
123 | 106 | void *private_data, | ||
124 | 107 | const char *handler_name, | ||
125 | 108 | const char *location) | ||
126 | 109 | { | ||
127 | 110 | struct select_event_context *select_ev = talloc_get_type(ev->additional_data, | ||
128 | 111 | struct select_event_context); | ||
129 | 112 | struct tevent_fd *fde; | ||
130 | 113 | |||
131 | 114 | fde = tevent_common_add_fd(ev, mem_ctx, fd, flags, | ||
132 | 115 | handler, private_data, | ||
133 | 116 | handler_name, location); | ||
134 | 117 | if (!fde) return NULL; | ||
135 | 118 | |||
136 | 119 | if (fde->fd > select_ev->maxfd) { | ||
137 | 120 | select_ev->maxfd = fde->fd; | ||
138 | 121 | } | ||
139 | 122 | talloc_set_destructor(fde, select_event_fd_destructor); | ||
140 | 123 | |||
141 | 124 | return fde; | ||
142 | 125 | } | ||
143 | 126 | |||
144 | 127 | /* | ||
145 | 128 | event loop handling using select() | ||
146 | 129 | */ | ||
147 | 130 | static int select_event_loop_select(struct select_event_context *select_ev, struct timeval *tvalp) | ||
148 | 131 | { | ||
149 | 132 | fd_set r_fds, w_fds; | ||
150 | 133 | struct tevent_fd *fde; | ||
151 | 134 | int selrtn; | ||
152 | 135 | |||
153 | 136 | /* we maybe need to recalculate the maxfd */ | ||
154 | 137 | if (select_ev->maxfd == EVENT_INVALID_MAXFD) { | ||
155 | 138 | calc_maxfd(select_ev); | ||
156 | 139 | } | ||
157 | 140 | |||
158 | 141 | FD_ZERO(&r_fds); | ||
159 | 142 | FD_ZERO(&w_fds); | ||
160 | 143 | |||
161 | 144 | /* setup any fd events */ | ||
162 | 145 | for (fde = select_ev->ev->fd_events; fde; fde = fde->next) { | ||
163 | 146 | if (fde->flags & TEVENT_FD_READ) { | ||
164 | 147 | FD_SET(fde->fd, &r_fds); | ||
165 | 148 | } | ||
166 | 149 | if (fde->flags & TEVENT_FD_WRITE) { | ||
167 | 150 | FD_SET(fde->fd, &w_fds); | ||
168 | 151 | } | ||
169 | 152 | } | ||
170 | 153 | |||
171 | 154 | if (select_ev->ev->signal_events && | ||
172 | 155 | tevent_common_check_signal(select_ev->ev)) { | ||
173 | 156 | return 0; | ||
174 | 157 | } | ||
175 | 158 | |||
176 | 159 | selrtn = select(select_ev->maxfd+1, &r_fds, &w_fds, NULL, tvalp); | ||
177 | 160 | |||
178 | 161 | if (selrtn == -1 && errno == EINTR && | ||
179 | 162 | select_ev->ev->signal_events) { | ||
180 | 163 | tevent_common_check_signal(select_ev->ev); | ||
181 | 164 | return 0; | ||
182 | 165 | } | ||
183 | 166 | |||
184 | 167 | if (selrtn == -1 && errno == EBADF) { | ||
185 | 168 | /* the socket is dead! this should never | ||
186 | 169 | happen as the socket should have first been | ||
187 | 170 | made readable and that should have removed | ||
188 | 171 | the event, so this must be a bug. This is a | ||
189 | 172 | fatal error. */ | ||
190 | 173 | tevent_debug(select_ev->ev, TEVENT_DEBUG_FATAL, | ||
191 | 174 | "ERROR: EBADF on select_event_loop_once\n"); | ||
192 | 175 | select_ev->exit_code = EBADF; | ||
193 | 176 | return -1; | ||
194 | 177 | } | ||
195 | 178 | |||
196 | 179 | if (selrtn == 0 && tvalp) { | ||
197 | 180 | /* we don't care about a possible delay here */ | ||
198 | 181 | tevent_common_loop_timer_delay(select_ev->ev); | ||
199 | 182 | return 0; | ||
200 | 183 | } | ||
201 | 184 | |||
202 | 185 | if (selrtn > 0) { | ||
203 | 186 | /* at least one file descriptor is ready - check | ||
204 | 187 | which ones and call the handler, being careful to allow | ||
205 | 188 | the handler to remove itself when called */ | ||
206 | 189 | for (fde = select_ev->ev->fd_events; fde; fde = fde->next) { | ||
207 | 190 | uint16_t flags = 0; | ||
208 | 191 | |||
209 | 192 | if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ; | ||
210 | 193 | if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE; | ||
211 | 194 | if (flags) { | ||
212 | 195 | fde->handler(select_ev->ev, fde, flags, fde->private_data); | ||
213 | 196 | break; | ||
214 | 197 | } | ||
215 | 198 | } | ||
216 | 199 | } | ||
217 | 200 | |||
218 | 201 | return 0; | ||
219 | 202 | } | ||
220 | 203 | |||
221 | 204 | /* | ||
222 | 205 | do a single event loop using the events defined in ev | ||
223 | 206 | */ | ||
224 | 207 | static int select_event_loop_once(struct tevent_context *ev, const char *location) | ||
225 | 208 | { | ||
226 | 209 | struct select_event_context *select_ev = talloc_get_type(ev->additional_data, | ||
227 | 210 | struct select_event_context); | ||
228 | 211 | struct timeval tval; | ||
229 | 212 | |||
230 | 213 | if (ev->signal_events && | ||
231 | 214 | tevent_common_check_signal(ev)) { | ||
232 | 215 | return 0; | ||
233 | 216 | } | ||
234 | 217 | |||
235 | 218 | if (ev->immediate_events && | ||
236 | 219 | tevent_common_loop_immediate(ev)) { | ||
237 | 220 | return 0; | ||
238 | 221 | } | ||
239 | 222 | |||
240 | 223 | tval = tevent_common_loop_timer_delay(ev); | ||
241 | 224 | if (tevent_timeval_is_zero(&tval)) { | ||
242 | 225 | return 0; | ||
243 | 226 | } | ||
244 | 227 | |||
245 | 228 | return select_event_loop_select(select_ev, &tval); | ||
246 | 229 | } | ||
247 | 230 | |||
248 | 231 | static const struct tevent_ops select_event_ops = { | ||
249 | 232 | .context_init = select_event_context_init, | ||
250 | 233 | .add_fd = select_event_add_fd, | ||
251 | 234 | .set_fd_close_fn = tevent_common_fd_set_close_fn, | ||
252 | 235 | .get_fd_flags = tevent_common_fd_get_flags, | ||
253 | 236 | .set_fd_flags = tevent_common_fd_set_flags, | ||
254 | 237 | .add_timer = tevent_common_add_timer, | ||
255 | 238 | .schedule_immediate = tevent_common_schedule_immediate, | ||
256 | 239 | .add_signal = tevent_common_add_signal, | ||
257 | 240 | .loop_once = select_event_loop_once, | ||
258 | 241 | .loop_wait = tevent_common_loop_wait, | ||
259 | 242 | }; | ||
260 | 243 | |||
261 | 244 | bool tevent_select_init(void) | ||
262 | 245 | { | ||
263 | 246 | return tevent_register_backend("select", &select_event_ops); | ||
264 | 247 | } | ||
265 | 0 | 248 | ||
266 | === added file '.pc/security-CVE-2011-0719.patch/lib/tevent/tevent_standard.c' | |||
267 | --- .pc/security-CVE-2011-0719.patch/lib/tevent/tevent_standard.c 1970-01-01 00:00:00 +0000 | |||
268 | +++ .pc/security-CVE-2011-0719.patch/lib/tevent/tevent_standard.c 2011-03-02 20:47:51 +0000 | |||
269 | @@ -0,0 +1,569 @@ | |||
270 | 1 | /* | ||
271 | 2 | Unix SMB/CIFS implementation. | ||
272 | 3 | main select loop and event handling | ||
273 | 4 | Copyright (C) Andrew Tridgell 2003-2005 | ||
274 | 5 | Copyright (C) Stefan Metzmacher 2005-2009 | ||
275 | 6 | |||
276 | 7 | ** NOTE! The following LGPL license applies to the tevent | ||
277 | 8 | ** library. This does NOT imply that all of Samba is released | ||
278 | 9 | ** under the LGPL | ||
279 | 10 | |||
280 | 11 | This library is free software; you can redistribute it and/or | ||
281 | 12 | modify it under the terms of the GNU Lesser General Public | ||
282 | 13 | License as published by the Free Software Foundation; either | ||
283 | 14 | version 3 of the License, or (at your option) any later version. | ||
284 | 15 | |||
285 | 16 | This library is distributed in the hope that it will be useful, | ||
286 | 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
287 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
288 | 19 | Lesser General Public License for more details. | ||
289 | 20 | |||
290 | 21 | You should have received a copy of the GNU Lesser General Public | ||
291 | 22 | License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
292 | 23 | */ | ||
293 | 24 | |||
294 | 25 | /* | ||
295 | 26 | This is SAMBA's default event loop code | ||
296 | 27 | |||
297 | 28 | - we try to use epoll if configure detected support for it | ||
298 | 29 | otherwise we use select() | ||
299 | 30 | - if epoll is broken on the system or the kernel doesn't support it | ||
300 | 31 | at runtime we fallback to select() | ||
301 | 32 | */ | ||
302 | 33 | |||
303 | 34 | #include "replace.h" | ||
304 | 35 | #include "system/filesys.h" | ||
305 | 36 | #include "system/select.h" | ||
306 | 37 | #include "tevent.h" | ||
307 | 38 | #include "tevent_util.h" | ||
308 | 39 | #include "tevent_internal.h" | ||
309 | 40 | |||
310 | 41 | struct std_event_context { | ||
311 | 42 | /* a pointer back to the generic event_context */ | ||
312 | 43 | struct tevent_context *ev; | ||
313 | 44 | |||
314 | 45 | /* the maximum file descriptor number in fd_events */ | ||
315 | 46 | int maxfd; | ||
316 | 47 | |||
317 | 48 | /* information for exiting from the event loop */ | ||
318 | 49 | int exit_code; | ||
319 | 50 | |||
320 | 51 | /* when using epoll this is the handle from epoll_create */ | ||
321 | 52 | int epoll_fd; | ||
322 | 53 | |||
323 | 54 | /* our pid at the time the epoll_fd was created */ | ||
324 | 55 | pid_t pid; | ||
325 | 56 | }; | ||
326 | 57 | |||
327 | 58 | /* use epoll if it is available */ | ||
328 | 59 | #if HAVE_EPOLL | ||
329 | 60 | /* | ||
330 | 61 | called when a epoll call fails, and we should fallback | ||
331 | 62 | to using select | ||
332 | 63 | */ | ||
333 | 64 | static void epoll_fallback_to_select(struct std_event_context *std_ev, const char *reason) | ||
334 | 65 | { | ||
335 | 66 | tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL, | ||
336 | 67 | "%s (%s) - falling back to select()\n", | ||
337 | 68 | reason, strerror(errno)); | ||
338 | 69 | close(std_ev->epoll_fd); | ||
339 | 70 | std_ev->epoll_fd = -1; | ||
340 | 71 | talloc_set_destructor(std_ev, NULL); | ||
341 | 72 | } | ||
342 | 73 | |||
343 | 74 | /* | ||
344 | 75 | map from TEVENT_FD_* to EPOLLIN/EPOLLOUT | ||
345 | 76 | */ | ||
346 | 77 | static uint32_t epoll_map_flags(uint16_t flags) | ||
347 | 78 | { | ||
348 | 79 | uint32_t ret = 0; | ||
349 | 80 | if (flags & TEVENT_FD_READ) ret |= (EPOLLIN | EPOLLERR | EPOLLHUP); | ||
350 | 81 | if (flags & TEVENT_FD_WRITE) ret |= (EPOLLOUT | EPOLLERR | EPOLLHUP); | ||
351 | 82 | return ret; | ||
352 | 83 | } | ||
353 | 84 | |||
354 | 85 | /* | ||
355 | 86 | free the epoll fd | ||
356 | 87 | */ | ||
357 | 88 | static int epoll_ctx_destructor(struct std_event_context *std_ev) | ||
358 | 89 | { | ||
359 | 90 | if (std_ev->epoll_fd != -1) { | ||
360 | 91 | close(std_ev->epoll_fd); | ||
361 | 92 | } | ||
362 | 93 | std_ev->epoll_fd = -1; | ||
363 | 94 | return 0; | ||
364 | 95 | } | ||
365 | 96 | |||
366 | 97 | /* | ||
367 | 98 | init the epoll fd | ||
368 | 99 | */ | ||
369 | 100 | static void epoll_init_ctx(struct std_event_context *std_ev) | ||
370 | 101 | { | ||
371 | 102 | std_ev->epoll_fd = epoll_create(64); | ||
372 | 103 | std_ev->pid = getpid(); | ||
373 | 104 | talloc_set_destructor(std_ev, epoll_ctx_destructor); | ||
374 | 105 | } | ||
375 | 106 | |||
376 | 107 | static void epoll_add_event(struct std_event_context *std_ev, struct tevent_fd *fde); | ||
377 | 108 | |||
378 | 109 | /* | ||
379 | 110 | reopen the epoll handle when our pid changes | ||
380 | 111 | see http://junkcode.samba.org/ftp/unpacked/junkcode/epoll_fork.c for an | ||
381 | 112 | demonstration of why this is needed | ||
382 | 113 | */ | ||
383 | 114 | static void epoll_check_reopen(struct std_event_context *std_ev) | ||
384 | 115 | { | ||
385 | 116 | struct tevent_fd *fde; | ||
386 | 117 | |||
387 | 118 | if (std_ev->pid == getpid()) { | ||
388 | 119 | return; | ||
389 | 120 | } | ||
390 | 121 | |||
391 | 122 | close(std_ev->epoll_fd); | ||
392 | 123 | std_ev->epoll_fd = epoll_create(64); | ||
393 | 124 | if (std_ev->epoll_fd == -1) { | ||
394 | 125 | tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL, | ||
395 | 126 | "Failed to recreate epoll handle after fork\n"); | ||
396 | 127 | return; | ||
397 | 128 | } | ||
398 | 129 | std_ev->pid = getpid(); | ||
399 | 130 | for (fde=std_ev->ev->fd_events;fde;fde=fde->next) { | ||
400 | 131 | epoll_add_event(std_ev, fde); | ||
401 | 132 | } | ||
402 | 133 | } | ||
403 | 134 | |||
404 | 135 | #define EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT (1<<0) | ||
405 | 136 | #define EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR (1<<1) | ||
406 | 137 | #define EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR (1<<2) | ||
407 | 138 | |||
408 | 139 | /* | ||
409 | 140 | add the epoll event to the given fd_event | ||
410 | 141 | */ | ||
411 | 142 | static void epoll_add_event(struct std_event_context *std_ev, struct tevent_fd *fde) | ||
412 | 143 | { | ||
413 | 144 | struct epoll_event event; | ||
414 | 145 | if (std_ev->epoll_fd == -1) return; | ||
415 | 146 | |||
416 | 147 | fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; | ||
417 | 148 | |||
418 | 149 | /* if we don't want events yet, don't add an epoll_event */ | ||
419 | 150 | if (fde->flags == 0) return; | ||
420 | 151 | |||
421 | 152 | ZERO_STRUCT(event); | ||
422 | 153 | event.events = epoll_map_flags(fde->flags); | ||
423 | 154 | event.data.ptr = fde; | ||
424 | 155 | if (epoll_ctl(std_ev->epoll_fd, EPOLL_CTL_ADD, fde->fd, &event) != 0) { | ||
425 | 156 | epoll_fallback_to_select(std_ev, "EPOLL_CTL_ADD failed"); | ||
426 | 157 | } | ||
427 | 158 | fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT; | ||
428 | 159 | |||
429 | 160 | /* only if we want to read we want to tell the event handler about errors */ | ||
430 | 161 | if (fde->flags & TEVENT_FD_READ) { | ||
431 | 162 | fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; | ||
432 | 163 | } | ||
433 | 164 | } | ||
434 | 165 | |||
435 | 166 | /* | ||
436 | 167 | delete the epoll event for given fd_event | ||
437 | 168 | */ | ||
438 | 169 | static void epoll_del_event(struct std_event_context *std_ev, struct tevent_fd *fde) | ||
439 | 170 | { | ||
440 | 171 | struct epoll_event event; | ||
441 | 172 | if (std_ev->epoll_fd == -1) return; | ||
442 | 173 | |||
443 | 174 | fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; | ||
444 | 175 | |||
445 | 176 | /* if there's no epoll_event, we don't need to delete it */ | ||
446 | 177 | if (!(fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT)) return; | ||
447 | 178 | |||
448 | 179 | ZERO_STRUCT(event); | ||
449 | 180 | event.events = epoll_map_flags(fde->flags); | ||
450 | 181 | event.data.ptr = fde; | ||
451 | 182 | epoll_ctl(std_ev->epoll_fd, EPOLL_CTL_DEL, fde->fd, &event); | ||
452 | 183 | fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT; | ||
453 | 184 | } | ||
454 | 185 | |||
455 | 186 | /* | ||
456 | 187 | change the epoll event to the given fd_event | ||
457 | 188 | */ | ||
458 | 189 | static void epoll_mod_event(struct std_event_context *std_ev, struct tevent_fd *fde) | ||
459 | 190 | { | ||
460 | 191 | struct epoll_event event; | ||
461 | 192 | if (std_ev->epoll_fd == -1) return; | ||
462 | 193 | |||
463 | 194 | fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; | ||
464 | 195 | |||
465 | 196 | ZERO_STRUCT(event); | ||
466 | 197 | event.events = epoll_map_flags(fde->flags); | ||
467 | 198 | event.data.ptr = fde; | ||
468 | 199 | if (epoll_ctl(std_ev->epoll_fd, EPOLL_CTL_MOD, fde->fd, &event) != 0) { | ||
469 | 200 | epoll_fallback_to_select(std_ev, "EPOLL_CTL_MOD failed"); | ||
470 | 201 | } | ||
471 | 202 | |||
472 | 203 | /* only if we want to read we want to tell the event handler about errors */ | ||
473 | 204 | if (fde->flags & TEVENT_FD_READ) { | ||
474 | 205 | fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; | ||
475 | 206 | } | ||
476 | 207 | } | ||
477 | 208 | |||
478 | 209 | static void epoll_change_event(struct std_event_context *std_ev, struct tevent_fd *fde) | ||
479 | 210 | { | ||
480 | 211 | bool got_error = (fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR); | ||
481 | 212 | bool want_read = (fde->flags & TEVENT_FD_READ); | ||
482 | 213 | bool want_write= (fde->flags & TEVENT_FD_WRITE); | ||
483 | 214 | |||
484 | 215 | if (std_ev->epoll_fd == -1) return; | ||
485 | 216 | |||
486 | 217 | fde->additional_flags &= ~EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR; | ||
487 | 218 | |||
488 | 219 | /* there's already an event */ | ||
489 | 220 | if (fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_HAS_EVENT) { | ||
490 | 221 | if (want_read || (want_write && !got_error)) { | ||
491 | 222 | epoll_mod_event(std_ev, fde); | ||
492 | 223 | return; | ||
493 | 224 | } | ||
494 | 225 | /* | ||
495 | 226 | * if we want to match the select behavior, we need to remove the epoll_event | ||
496 | 227 | * when the caller isn't interested in events. | ||
497 | 228 | * | ||
498 | 229 | * this is because epoll reports EPOLLERR and EPOLLHUP, even without asking for them | ||
499 | 230 | */ | ||
500 | 231 | epoll_del_event(std_ev, fde); | ||
501 | 232 | return; | ||
502 | 233 | } | ||
503 | 234 | |||
504 | 235 | /* there's no epoll_event attached to the fde */ | ||
505 | 236 | if (want_read || (want_write && !got_error)) { | ||
506 | 237 | epoll_add_event(std_ev, fde); | ||
507 | 238 | return; | ||
508 | 239 | } | ||
509 | 240 | } | ||
510 | 241 | |||
511 | 242 | /* | ||
512 | 243 | event loop handling using epoll | ||
513 | 244 | */ | ||
514 | 245 | static int epoll_event_loop(struct std_event_context *std_ev, struct timeval *tvalp) | ||
515 | 246 | { | ||
516 | 247 | int ret, i; | ||
517 | 248 | #define MAXEVENTS 1 | ||
518 | 249 | struct epoll_event events[MAXEVENTS]; | ||
519 | 250 | int timeout = -1; | ||
520 | 251 | |||
521 | 252 | if (std_ev->epoll_fd == -1) return -1; | ||
522 | 253 | |||
523 | 254 | if (tvalp) { | ||
524 | 255 | /* it's better to trigger timed events a bit later than to early */ | ||
525 | 256 | timeout = ((tvalp->tv_usec+999) / 1000) + (tvalp->tv_sec*1000); | ||
526 | 257 | } | ||
527 | 258 | |||
528 | 259 | if (std_ev->ev->signal_events && | ||
529 | 260 | tevent_common_check_signal(std_ev->ev)) { | ||
530 | 261 | return 0; | ||
531 | 262 | } | ||
532 | 263 | |||
533 | 264 | ret = epoll_wait(std_ev->epoll_fd, events, MAXEVENTS, timeout); | ||
534 | 265 | |||
535 | 266 | if (ret == -1 && errno == EINTR && std_ev->ev->signal_events) { | ||
536 | 267 | if (tevent_common_check_signal(std_ev->ev)) { | ||
537 | 268 | return 0; | ||
538 | 269 | } | ||
539 | 270 | } | ||
540 | 271 | |||
541 | 272 | if (ret == -1 && errno != EINTR) { | ||
542 | 273 | epoll_fallback_to_select(std_ev, "epoll_wait() failed"); | ||
543 | 274 | return -1; | ||
544 | 275 | } | ||
545 | 276 | |||
546 | 277 | if (ret == 0 && tvalp) { | ||
547 | 278 | /* we don't care about a possible delay here */ | ||
548 | 279 | tevent_common_loop_timer_delay(std_ev->ev); | ||
549 | 280 | return 0; | ||
550 | 281 | } | ||
551 | 282 | |||
552 | 283 | for (i=0;i<ret;i++) { | ||
553 | 284 | struct tevent_fd *fde = talloc_get_type(events[i].data.ptr, | ||
554 | 285 | struct tevent_fd); | ||
555 | 286 | uint16_t flags = 0; | ||
556 | 287 | |||
557 | 288 | if (fde == NULL) { | ||
558 | 289 | epoll_fallback_to_select(std_ev, "epoll_wait() gave bad data"); | ||
559 | 290 | return -1; | ||
560 | 291 | } | ||
561 | 292 | if (events[i].events & (EPOLLHUP|EPOLLERR)) { | ||
562 | 293 | fde->additional_flags |= EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR; | ||
563 | 294 | /* | ||
564 | 295 | * if we only wait for TEVENT_FD_WRITE, we should not tell the | ||
565 | 296 | * event handler about it, and remove the epoll_event, | ||
566 | 297 | * as we only report errors when waiting for read events, | ||
567 | 298 | * to match the select() behavior | ||
568 | 299 | */ | ||
569 | 300 | if (!(fde->additional_flags & EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR)) { | ||
570 | 301 | epoll_del_event(std_ev, fde); | ||
571 | 302 | continue; | ||
572 | 303 | } | ||
573 | 304 | flags |= TEVENT_FD_READ; | ||
574 | 305 | } | ||
575 | 306 | if (events[i].events & EPOLLIN) flags |= TEVENT_FD_READ; | ||
576 | 307 | if (events[i].events & EPOLLOUT) flags |= TEVENT_FD_WRITE; | ||
577 | 308 | if (flags) { | ||
578 | 309 | fde->handler(std_ev->ev, fde, flags, fde->private_data); | ||
579 | 310 | break; | ||
580 | 311 | } | ||
581 | 312 | } | ||
582 | 313 | |||
583 | 314 | return 0; | ||
584 | 315 | } | ||
585 | 316 | #else | ||
586 | 317 | #define epoll_init_ctx(std_ev) | ||
587 | 318 | #define epoll_add_event(std_ev,fde) | ||
588 | 319 | #define epoll_del_event(std_ev,fde) | ||
589 | 320 | #define epoll_change_event(std_ev,fde) | ||
590 | 321 | #define epoll_event_loop(std_ev,tvalp) (-1) | ||
591 | 322 | #define epoll_check_reopen(std_ev) | ||
592 | 323 | #endif | ||
593 | 324 | |||
594 | 325 | /* | ||
595 | 326 | create a std_event_context structure. | ||
596 | 327 | */ | ||
597 | 328 | static int std_event_context_init(struct tevent_context *ev) | ||
598 | 329 | { | ||
599 | 330 | struct std_event_context *std_ev; | ||
600 | 331 | |||
601 | 332 | std_ev = talloc_zero(ev, struct std_event_context); | ||
602 | 333 | if (!std_ev) return -1; | ||
603 | 334 | std_ev->ev = ev; | ||
604 | 335 | std_ev->epoll_fd = -1; | ||
605 | 336 | |||
606 | 337 | epoll_init_ctx(std_ev); | ||
607 | 338 | |||
608 | 339 | ev->additional_data = std_ev; | ||
609 | 340 | return 0; | ||
610 | 341 | } | ||
611 | 342 | |||
612 | 343 | /* | ||
613 | 344 | recalculate the maxfd | ||
614 | 345 | */ | ||
615 | 346 | static void calc_maxfd(struct std_event_context *std_ev) | ||
616 | 347 | { | ||
617 | 348 | struct tevent_fd *fde; | ||
618 | 349 | |||
619 | 350 | std_ev->maxfd = 0; | ||
620 | 351 | for (fde = std_ev->ev->fd_events; fde; fde = fde->next) { | ||
621 | 352 | if (fde->fd > std_ev->maxfd) { | ||
622 | 353 | std_ev->maxfd = fde->fd; | ||
623 | 354 | } | ||
624 | 355 | } | ||
625 | 356 | } | ||
626 | 357 | |||
627 | 358 | |||
628 | 359 | /* to mark the ev->maxfd invalid | ||
629 | 360 | * this means we need to recalculate it | ||
630 | 361 | */ | ||
631 | 362 | #define EVENT_INVALID_MAXFD (-1) | ||
632 | 363 | |||
633 | 364 | /* | ||
634 | 365 | destroy an fd_event | ||
635 | 366 | */ | ||
636 | 367 | static int std_event_fd_destructor(struct tevent_fd *fde) | ||
637 | 368 | { | ||
638 | 369 | struct tevent_context *ev = fde->event_ctx; | ||
639 | 370 | struct std_event_context *std_ev = NULL; | ||
640 | 371 | |||
641 | 372 | if (ev) { | ||
642 | 373 | std_ev = talloc_get_type(ev->additional_data, | ||
643 | 374 | struct std_event_context); | ||
644 | 375 | |||
645 | 376 | epoll_check_reopen(std_ev); | ||
646 | 377 | |||
647 | 378 | if (std_ev->maxfd == fde->fd) { | ||
648 | 379 | std_ev->maxfd = EVENT_INVALID_MAXFD; | ||
649 | 380 | } | ||
650 | 381 | |||
651 | 382 | epoll_del_event(std_ev, fde); | ||
652 | 383 | } | ||
653 | 384 | |||
654 | 385 | return tevent_common_fd_destructor(fde); | ||
655 | 386 | } | ||
656 | 387 | |||
657 | 388 | /* | ||
658 | 389 | add a fd based event | ||
659 | 390 | return NULL on failure (memory allocation error) | ||
660 | 391 | */ | ||
661 | 392 | static struct tevent_fd *std_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx, | ||
662 | 393 | int fd, uint16_t flags, | ||
663 | 394 | tevent_fd_handler_t handler, | ||
664 | 395 | void *private_data, | ||
665 | 396 | const char *handler_name, | ||
666 | 397 | const char *location) | ||
667 | 398 | { | ||
668 | 399 | struct std_event_context *std_ev = talloc_get_type(ev->additional_data, | ||
669 | 400 | struct std_event_context); | ||
670 | 401 | struct tevent_fd *fde; | ||
671 | 402 | |||
672 | 403 | epoll_check_reopen(std_ev); | ||
673 | 404 | |||
674 | 405 | fde = tevent_common_add_fd(ev, mem_ctx, fd, flags, | ||
675 | 406 | handler, private_data, | ||
676 | 407 | handler_name, location); | ||
677 | 408 | if (!fde) return NULL; | ||
678 | 409 | |||
679 | 410 | if ((std_ev->maxfd != EVENT_INVALID_MAXFD) | ||
680 | 411 | && (fde->fd > std_ev->maxfd)) { | ||
681 | 412 | std_ev->maxfd = fde->fd; | ||
682 | 413 | } | ||
683 | 414 | talloc_set_destructor(fde, std_event_fd_destructor); | ||
684 | 415 | |||
685 | 416 | epoll_add_event(std_ev, fde); | ||
686 | 417 | |||
687 | 418 | return fde; | ||
688 | 419 | } | ||
689 | 420 | |||
690 | 421 | /* | ||
691 | 422 | set the fd event flags | ||
692 | 423 | */ | ||
693 | 424 | static void std_event_set_fd_flags(struct tevent_fd *fde, uint16_t flags) | ||
694 | 425 | { | ||
695 | 426 | struct tevent_context *ev; | ||
696 | 427 | struct std_event_context *std_ev; | ||
697 | 428 | |||
698 | 429 | if (fde->flags == flags) return; | ||
699 | 430 | |||
700 | 431 | ev = fde->event_ctx; | ||
701 | 432 | std_ev = talloc_get_type(ev->additional_data, struct std_event_context); | ||
702 | 433 | |||
703 | 434 | fde->flags = flags; | ||
704 | 435 | |||
705 | 436 | epoll_check_reopen(std_ev); | ||
706 | 437 | |||
707 | 438 | epoll_change_event(std_ev, fde); | ||
708 | 439 | } | ||
709 | 440 | |||
710 | 441 | /* | ||
711 | 442 | event loop handling using select() | ||
712 | 443 | */ | ||
713 | 444 | static int std_event_loop_select(struct std_event_context *std_ev, struct timeval *tvalp) | ||
714 | 445 | { | ||
715 | 446 | fd_set r_fds, w_fds; | ||
716 | 447 | struct tevent_fd *fde; | ||
717 | 448 | int selrtn; | ||
718 | 449 | |||
719 | 450 | /* we maybe need to recalculate the maxfd */ | ||
720 | 451 | if (std_ev->maxfd == EVENT_INVALID_MAXFD) { | ||
721 | 452 | calc_maxfd(std_ev); | ||
722 | 453 | } | ||
723 | 454 | |||
724 | 455 | FD_ZERO(&r_fds); | ||
725 | 456 | FD_ZERO(&w_fds); | ||
726 | 457 | |||
727 | 458 | /* setup any fd events */ | ||
728 | 459 | for (fde = std_ev->ev->fd_events; fde; fde = fde->next) { | ||
729 | 460 | if (fde->flags & TEVENT_FD_READ) { | ||
730 | 461 | FD_SET(fde->fd, &r_fds); | ||
731 | 462 | } | ||
732 | 463 | if (fde->flags & TEVENT_FD_WRITE) { | ||
733 | 464 | FD_SET(fde->fd, &w_fds); | ||
734 | 465 | } | ||
735 | 466 | } | ||
736 | 467 | |||
737 | 468 | if (std_ev->ev->signal_events && | ||
738 | 469 | tevent_common_check_signal(std_ev->ev)) { | ||
739 | 470 | return 0; | ||
740 | 471 | } | ||
741 | 472 | |||
742 | 473 | selrtn = select(std_ev->maxfd+1, &r_fds, &w_fds, NULL, tvalp); | ||
743 | 474 | |||
744 | 475 | if (selrtn == -1 && errno == EINTR && | ||
745 | 476 | std_ev->ev->signal_events) { | ||
746 | 477 | tevent_common_check_signal(std_ev->ev); | ||
747 | 478 | return 0; | ||
748 | 479 | } | ||
749 | 480 | |||
750 | 481 | if (selrtn == -1 && errno == EBADF) { | ||
751 | 482 | /* the socket is dead! this should never | ||
752 | 483 | happen as the socket should have first been | ||
753 | 484 | made readable and that should have removed | ||
754 | 485 | the event, so this must be a bug. This is a | ||
755 | 486 | fatal error. */ | ||
756 | 487 | tevent_debug(std_ev->ev, TEVENT_DEBUG_FATAL, | ||
757 | 488 | "ERROR: EBADF on std_event_loop_once\n"); | ||
758 | 489 | std_ev->exit_code = EBADF; | ||
759 | 490 | return -1; | ||
760 | 491 | } | ||
761 | 492 | |||
762 | 493 | if (selrtn == 0 && tvalp) { | ||
763 | 494 | /* we don't care about a possible delay here */ | ||
764 | 495 | tevent_common_loop_timer_delay(std_ev->ev); | ||
765 | 496 | return 0; | ||
766 | 497 | } | ||
767 | 498 | |||
768 | 499 | if (selrtn > 0) { | ||
769 | 500 | /* at least one file descriptor is ready - check | ||
770 | 501 | which ones and call the handler, being careful to allow | ||
771 | 502 | the handler to remove itself when called */ | ||
772 | 503 | for (fde = std_ev->ev->fd_events; fde; fde = fde->next) { | ||
773 | 504 | uint16_t flags = 0; | ||
774 | 505 | |||
775 | 506 | if (FD_ISSET(fde->fd, &r_fds)) flags |= TEVENT_FD_READ; | ||
776 | 507 | if (FD_ISSET(fde->fd, &w_fds)) flags |= TEVENT_FD_WRITE; | ||
777 | 508 | if (flags) { | ||
778 | 509 | fde->handler(std_ev->ev, fde, flags, fde->private_data); | ||
779 | 510 | break; | ||
780 | 511 | } | ||
781 | 512 | } | ||
782 | 513 | } | ||
783 | 514 | |||
784 | 515 | return 0; | ||
785 | 516 | } | ||
786 | 517 | |||
787 | 518 | /* | ||
788 | 519 | do a single event loop using the events defined in ev | ||
789 | 520 | */ | ||
790 | 521 | static int std_event_loop_once(struct tevent_context *ev, const char *location) | ||
791 | 522 | { | ||
792 | 523 | struct std_event_context *std_ev = talloc_get_type(ev->additional_data, | ||
793 | 524 | struct std_event_context); | ||
794 | 525 | struct timeval tval; | ||
795 | 526 | |||
796 | 527 | if (ev->signal_events && | ||
797 | 528 | tevent_common_check_signal(ev)) { | ||
798 | 529 | return 0; | ||
799 | 530 | } | ||
800 | 531 | |||
801 | 532 | if (ev->immediate_events && | ||
802 | 533 | tevent_common_loop_immediate(ev)) { | ||
803 | 534 | return 0; | ||
804 | 535 | } | ||
805 | 536 | |||
806 | 537 | tval = tevent_common_loop_timer_delay(ev); | ||
807 | 538 | if (tevent_timeval_is_zero(&tval)) { | ||
808 | 539 | return 0; | ||
809 | 540 | } | ||
810 | 541 | |||
811 | 542 | epoll_check_reopen(std_ev); | ||
812 | 543 | |||
813 | 544 | if (epoll_event_loop(std_ev, &tval) == 0) { | ||
814 | 545 | return 0; | ||
815 | 546 | } | ||
816 | 547 | |||
817 | 548 | return std_event_loop_select(std_ev, &tval); | ||
818 | 549 | } | ||
819 | 550 | |||
820 | 551 | static const struct tevent_ops std_event_ops = { | ||
821 | 552 | .context_init = std_event_context_init, | ||
822 | 553 | .add_fd = std_event_add_fd, | ||
823 | 554 | .set_fd_close_fn = tevent_common_fd_set_close_fn, | ||
824 | 555 | .get_fd_flags = tevent_common_fd_get_flags, | ||
825 | 556 | .set_fd_flags = std_event_set_fd_flags, | ||
826 | 557 | .add_timer = tevent_common_add_timer, | ||
827 | 558 | .schedule_immediate = tevent_common_schedule_immediate, | ||
828 | 559 | .add_signal = tevent_common_add_signal, | ||
829 | 560 | .loop_once = std_event_loop_once, | ||
830 | 561 | .loop_wait = tevent_common_loop_wait, | ||
831 | 562 | }; | ||
832 | 563 | |||
833 | 564 | |||
834 | 565 | bool tevent_standard_init(void) | ||
835 | 566 | { | ||
836 | 567 | return tevent_register_backend("standard", &std_event_ops); | ||
837 | 568 | } | ||
838 | 569 | |||
839 | 0 | 570 | ||
840 | === added directory '.pc/security-CVE-2011-0719.patch/nsswitch' | |||
841 | === added file '.pc/security-CVE-2011-0719.patch/nsswitch/wb_common.c' | |||
842 | --- .pc/security-CVE-2011-0719.patch/nsswitch/wb_common.c 1970-01-01 00:00:00 +0000 | |||
843 | +++ .pc/security-CVE-2011-0719.patch/nsswitch/wb_common.c 2011-03-02 20:47:51 +0000 | |||
844 | @@ -0,0 +1,690 @@ | |||
845 | 1 | /* | ||
846 | 2 | Unix SMB/CIFS implementation. | ||
847 | 3 | |||
848 | 4 | winbind client common code | ||
849 | 5 | |||
850 | 6 | Copyright (C) Tim Potter 2000 | ||
851 | 7 | Copyright (C) Andrew Tridgell 2000 | ||
852 | 8 | Copyright (C) Andrew Bartlett 2002 | ||
853 | 9 | |||
854 | 10 | |||
855 | 11 | This library is free software; you can redistribute it and/or | ||
856 | 12 | modify it under the terms of the GNU Lesser General Public | ||
857 | 13 | License as published by the Free Software Foundation; either | ||
858 | 14 | version 3 of the License, or (at your option) any later version. | ||
859 | 15 | |||
860 | 16 | This library is distributed in the hope that it will be useful, | ||
861 | 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
862 | 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
863 | 19 | Library General Public License for more details. | ||
864 | 20 | |||
865 | 21 | You should have received a copy of the GNU Lesser General Public License | ||
866 | 22 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
867 | 23 | */ | ||
868 | 24 | |||
869 | 25 | #include "winbind_client.h" | ||
870 | 26 | |||
871 | 27 | /* Global variables. These are effectively the client state information */ | ||
872 | 28 | |||
873 | 29 | int winbindd_fd = -1; /* fd for winbindd socket */ | ||
874 | 30 | static int is_privileged = 0; | ||
875 | 31 | |||
876 | 32 | /* Free a response structure */ | ||
877 | 33 | |||
878 | 34 | void winbindd_free_response(struct winbindd_response *response) | ||
879 | 35 | { | ||
880 | 36 | /* Free any allocated extra_data */ | ||
881 | 37 | |||
882 | 38 | if (response) | ||
883 | 39 | SAFE_FREE(response->extra_data.data); | ||
884 | 40 | } | ||
885 | 41 | |||
886 | 42 | /* Initialise a request structure */ | ||
887 | 43 | |||
888 | 44 | void winbindd_init_request(struct winbindd_request *request, int request_type) | ||
889 | 45 | { | ||
890 | 46 | request->length = sizeof(struct winbindd_request); | ||
891 | 47 | |||
892 | 48 | request->cmd = (enum winbindd_cmd)request_type; | ||
893 | 49 | request->pid = getpid(); | ||
894 | 50 | |||
895 | 51 | } | ||
896 | 52 | |||
897 | 53 | /* Initialise a response structure */ | ||
898 | 54 | |||
899 | 55 | static void init_response(struct winbindd_response *response) | ||
900 | 56 | { | ||
901 | 57 | /* Initialise return value */ | ||
902 | 58 | |||
903 | 59 | response->result = WINBINDD_ERROR; | ||
904 | 60 | } | ||
905 | 61 | |||
906 | 62 | /* Close established socket */ | ||
907 | 63 | |||
908 | 64 | void winbind_close_sock(void) | ||
909 | 65 | { | ||
910 | 66 | if (winbindd_fd != -1) { | ||
911 | 67 | close(winbindd_fd); | ||
912 | 68 | winbindd_fd = -1; | ||
913 | 69 | } | ||
914 | 70 | } | ||
915 | 71 | |||
916 | 72 | #define CONNECT_TIMEOUT 30 | ||
917 | 73 | |||
918 | 74 | /* Make sure socket handle isn't stdin, stdout or stderr */ | ||
919 | 75 | #define RECURSION_LIMIT 3 | ||
920 | 76 | |||
921 | 77 | static int make_nonstd_fd_internals(int fd, int limit /* Recursion limiter */) | ||
922 | 78 | { | ||
923 | 79 | int new_fd; | ||
924 | 80 | if (fd >= 0 && fd <= 2) { | ||
925 | 81 | #ifdef F_DUPFD | ||
926 | 82 | if ((new_fd = fcntl(fd, F_DUPFD, 3)) == -1) { | ||
927 | 83 | return -1; | ||
928 | 84 | } | ||
929 | 85 | /* Paranoia */ | ||
930 | 86 | if (new_fd < 3) { | ||
931 | 87 | close(new_fd); | ||
932 | 88 | return -1; | ||
933 | 89 | } | ||
934 | 90 | close(fd); | ||
935 | 91 | return new_fd; | ||
936 | 92 | #else | ||
937 | 93 | if (limit <= 0) | ||
938 | 94 | return -1; | ||
939 | 95 | |||
940 | 96 | new_fd = dup(fd); | ||
941 | 97 | if (new_fd == -1) | ||
942 | 98 | return -1; | ||
943 | 99 | |||
944 | 100 | /* use the program stack to hold our list of FDs to close */ | ||
945 | 101 | new_fd = make_nonstd_fd_internals(new_fd, limit - 1); | ||
946 | 102 | close(fd); | ||
947 | 103 | return new_fd; | ||
948 | 104 | #endif | ||
949 | 105 | } | ||
950 | 106 | return fd; | ||
951 | 107 | } | ||
952 | 108 | |||
953 | 109 | /**************************************************************************** | ||
954 | 110 | Set a fd into blocking/nonblocking mode. Uses POSIX O_NONBLOCK if available, | ||
955 | 111 | else | ||
956 | 112 | if SYSV use O_NDELAY | ||
957 | 113 | if BSD use FNDELAY | ||
958 | 114 | Set close on exec also. | ||
959 | 115 | ****************************************************************************/ | ||
960 | 116 | |||
961 | 117 | static int make_safe_fd(int fd) | ||
962 | 118 | { | ||
963 | 119 | int result, flags; | ||
964 | 120 | int new_fd = make_nonstd_fd_internals(fd, RECURSION_LIMIT); | ||
965 | 121 | if (new_fd == -1) { | ||
966 | 122 | close(fd); | ||
967 | 123 | return -1; | ||
968 | 124 | } | ||
969 | 125 | |||
970 | 126 | /* Socket should be nonblocking. */ | ||
971 | 127 | #ifdef O_NONBLOCK | ||
972 | 128 | #define FLAG_TO_SET O_NONBLOCK | ||
973 | 129 | #else | ||
974 | 130 | #ifdef SYSV | ||
975 | 131 | #define FLAG_TO_SET O_NDELAY | ||
976 | 132 | #else /* BSD */ | ||
977 | 133 | #define FLAG_TO_SET FNDELAY | ||
978 | 134 | #endif | ||
979 | 135 | #endif | ||
980 | 136 | |||
981 | 137 | if ((flags = fcntl(new_fd, F_GETFL)) == -1) { | ||
982 | 138 | close(new_fd); | ||
983 | 139 | return -1; | ||
984 | 140 | } | ||
985 | 141 | |||
986 | 142 | flags |= FLAG_TO_SET; | ||
987 | 143 | if (fcntl(new_fd, F_SETFL, flags) == -1) { | ||
988 | 144 | close(new_fd); | ||
989 | 145 | return -1; | ||
990 | 146 | } | ||
991 | 147 | |||
992 | 148 | #undef FLAG_TO_SET | ||
993 | 149 | |||
994 | 150 | /* Socket should be closed on exec() */ | ||
995 | 151 | #ifdef FD_CLOEXEC | ||
996 | 152 | result = flags = fcntl(new_fd, F_GETFD, 0); | ||
997 | 153 | if (flags >= 0) { | ||
998 | 154 | flags |= FD_CLOEXEC; | ||
999 | 155 | result = fcntl( new_fd, F_SETFD, flags ); | ||
1000 | 156 | } | ||
1001 | 157 | if (result < 0) { | ||
1002 | 158 | close(new_fd); | ||
1003 | 159 | return -1; | ||
1004 | 160 | } | ||
1005 | 161 | #endif | ||
1006 | 162 | return new_fd; | ||
1007 | 163 | } | ||
1008 | 164 | |||
1009 | 165 | /* Connect to winbindd socket */ | ||
1010 | 166 | |||
1011 | 167 | static int winbind_named_pipe_sock(const char *dir) | ||
1012 | 168 | { | ||
1013 | 169 | struct sockaddr_un sunaddr; | ||
1014 | 170 | struct stat st; | ||
1015 | 171 | char *path = NULL; | ||
1016 | 172 | int fd; | ||
1017 | 173 | int wait_time; | ||
1018 | 174 | int slept; | ||
1019 | 175 | |||
1020 | 176 | /* Check permissions on unix socket directory */ | ||
1021 | 177 | |||
1022 | 178 | if (lstat(dir, &st) == -1) { | ||
1023 | 179 | errno = ENOENT; | ||
1024 | 180 | return -1; | ||
1025 | 181 | } | ||
1026 | 182 | |||
1027 | 183 | if (!S_ISDIR(st.st_mode) || | ||
1028 | 184 | (st.st_uid != 0 && st.st_uid != geteuid())) { | ||
1029 | 185 | errno = ENOENT; | ||
1030 | 186 | return -1; | ||
1031 | 187 | } | ||
1032 | 188 | |||
1033 | 189 | /* Connect to socket */ | ||
1034 | 190 | |||
1035 | 191 | if (asprintf(&path, "%s/%s", dir, WINBINDD_SOCKET_NAME) < 0) { | ||
1036 | 192 | return -1; | ||
1037 | 193 | } | ||
1038 | 194 | |||
1039 | 195 | ZERO_STRUCT(sunaddr); | ||
1040 | 196 | sunaddr.sun_family = AF_UNIX; | ||
1041 | 197 | strncpy(sunaddr.sun_path, path, sizeof(sunaddr.sun_path) - 1); | ||
1042 | 198 | |||
1043 | 199 | /* If socket file doesn't exist, don't bother trying to connect | ||
1044 | 200 | with retry. This is an attempt to make the system usable when | ||
1045 | 201 | the winbindd daemon is not running. */ | ||
1046 | 202 | |||
1047 | 203 | if (lstat(path, &st) == -1) { | ||
1048 | 204 | errno = ENOENT; | ||
1049 | 205 | SAFE_FREE(path); | ||
1050 | 206 | return -1; | ||
1051 | 207 | } | ||
1052 | 208 | |||
1053 | 209 | SAFE_FREE(path); | ||
1054 | 210 | /* Check permissions on unix socket file */ | ||
1055 | 211 | |||
1056 | 212 | if (!S_ISSOCK(st.st_mode) || | ||
1057 | 213 | (st.st_uid != 0 && st.st_uid != geteuid())) { | ||
1058 | 214 | errno = ENOENT; | ||
1059 | 215 | return -1; | ||
1060 | 216 | } | ||
1061 | 217 | |||
1062 | 218 | /* Connect to socket */ | ||
1063 | 219 | |||
1064 | 220 | if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { | ||
1065 | 221 | return -1; | ||
1066 | 222 | } | ||
1067 | 223 | |||
1068 | 224 | /* Set socket non-blocking and close on exec. */ | ||
1069 | 225 | |||
1070 | 226 | if ((fd = make_safe_fd( fd)) == -1) { | ||
1071 | 227 | return fd; | ||
1072 | 228 | } | ||
1073 | 229 | |||
1074 | 230 | for (wait_time = 0; connect(fd, (struct sockaddr *)&sunaddr, sizeof(sunaddr)) == -1; | ||
1075 | 231 | wait_time += slept) { | ||
1076 | 232 | struct timeval tv; | ||
1077 | 233 | fd_set w_fds; | ||
1078 | 234 | int ret; | ||
1079 | 235 | int connect_errno = 0; | ||
1080 | 236 | socklen_t errnosize; | ||
1081 | 237 | |||
1082 | 238 | if (wait_time >= CONNECT_TIMEOUT) | ||
1083 | 239 | goto error_out; | ||
1084 | 240 | |||
1085 | 241 | switch (errno) { | ||
1086 | 242 | case EINPROGRESS: | ||
1087 | 243 | FD_ZERO(&w_fds); | ||
1088 | 244 | FD_SET(fd, &w_fds); | ||
1089 | 245 | tv.tv_sec = CONNECT_TIMEOUT - wait_time; | ||
1090 | 246 | tv.tv_usec = 0; | ||
1091 | 247 | |||
1092 | 248 | ret = select(fd + 1, NULL, &w_fds, NULL, &tv); | ||
1093 | 249 | |||
1094 | 250 | if (ret > 0) { | ||
1095 | 251 | errnosize = sizeof(connect_errno); | ||
1096 | 252 | |||
1097 | 253 | ret = getsockopt(fd, SOL_SOCKET, | ||
1098 | 254 | SO_ERROR, &connect_errno, &errnosize); | ||
1099 | 255 | |||
1100 | 256 | if (ret >= 0 && connect_errno == 0) { | ||
1101 | 257 | /* Connect succeed */ | ||
1102 | 258 | goto out; | ||
1103 | 259 | } | ||
1104 | 260 | } | ||
1105 | 261 | |||
1106 | 262 | slept = CONNECT_TIMEOUT; | ||
1107 | 263 | break; | ||
1108 | 264 | case EAGAIN: | ||
1109 | 265 | slept = rand() % 3 + 1; | ||
1110 | 266 | sleep(slept); | ||
1111 | 267 | break; | ||
1112 | 268 | default: | ||
1113 | 269 | goto error_out; | ||
1114 | 270 | } | ||
1115 | 271 | |||
1116 | 272 | } | ||
1117 | 273 | |||
1118 | 274 | out: | ||
1119 | 275 | |||
1120 | 276 | return fd; | ||
1121 | 277 | |||
1122 | 278 | error_out: | ||
1123 | 279 | |||
1124 | 280 | close(fd); | ||
1125 | 281 | return -1; | ||
1126 | 282 | } | ||
1127 | 283 | |||
1128 | 284 | static const char *winbindd_socket_dir(void) | ||
1129 | 285 | { | ||
1130 | 286 | #ifdef SOCKET_WRAPPER | ||
1131 | 287 | const char *env_dir; | ||
1132 | 288 | |||
1133 | 289 | env_dir = getenv(WINBINDD_SOCKET_DIR_ENVVAR); | ||
1134 | 290 | if (env_dir) { | ||
1135 | 291 | return env_dir; | ||
1136 | 292 | } | ||
1137 | 293 | #endif | ||
1138 | 294 | |||
1139 | 295 | return WINBINDD_SOCKET_DIR; | ||
1140 | 296 | } | ||
1141 | 297 | |||
1142 | 298 | /* Connect to winbindd socket */ | ||
1143 | 299 | |||
1144 | 300 | static int winbind_open_pipe_sock(int recursing, int need_priv) | ||
1145 | 301 | { | ||
1146 | 302 | #ifdef HAVE_UNIXSOCKET | ||
1147 | 303 | static pid_t our_pid; | ||
1148 | 304 | struct winbindd_request request; | ||
1149 | 305 | struct winbindd_response response; | ||
1150 | 306 | ZERO_STRUCT(request); | ||
1151 | 307 | ZERO_STRUCT(response); | ||
1152 | 308 | |||
1153 | 309 | if (our_pid != getpid()) { | ||
1154 | 310 | winbind_close_sock(); | ||
1155 | 311 | our_pid = getpid(); | ||
1156 | 312 | } | ||
1157 | 313 | |||
1158 | 314 | if ((need_priv != 0) && (is_privileged == 0)) { | ||
1159 | 315 | winbind_close_sock(); | ||
1160 | 316 | } | ||
1161 | 317 | |||
1162 | 318 | if (winbindd_fd != -1) { | ||
1163 | 319 | return winbindd_fd; | ||
1164 | 320 | } | ||
1165 | 321 | |||
1166 | 322 | if (recursing) { | ||
1167 | 323 | return -1; | ||
1168 | 324 | } | ||
1169 | 325 | |||
1170 | 326 | if ((winbindd_fd = winbind_named_pipe_sock(winbindd_socket_dir())) == -1) { | ||
1171 | 327 | return -1; | ||
1172 | 328 | } | ||
1173 | 329 | |||
1174 | 330 | is_privileged = 0; | ||
1175 | 331 | |||
1176 | 332 | /* version-check the socket */ | ||
1177 | 333 | |||
1178 | 334 | request.wb_flags = WBFLAG_RECURSE; | ||
1179 | 335 | if ((winbindd_request_response(WINBINDD_INTERFACE_VERSION, &request, &response) != NSS_STATUS_SUCCESS) || (response.data.interface_version != WINBIND_INTERFACE_VERSION)) { | ||
1180 | 336 | winbind_close_sock(); | ||
1181 | 337 | return -1; | ||
1182 | 338 | } | ||
1183 | 339 | |||
1184 | 340 | /* try and get priv pipe */ | ||
1185 | 341 | |||
1186 | 342 | request.wb_flags = WBFLAG_RECURSE; | ||
1187 | 343 | if (winbindd_request_response(WINBINDD_PRIV_PIPE_DIR, &request, &response) == NSS_STATUS_SUCCESS) { | ||
1188 | 344 | int fd; | ||
1189 | 345 | if ((fd = winbind_named_pipe_sock((char *)response.extra_data.data)) != -1) { | ||
1190 | 346 | close(winbindd_fd); | ||
1191 | 347 | winbindd_fd = fd; | ||
1192 | 348 | is_privileged = 1; | ||
1193 | 349 | } | ||
1194 | 350 | } | ||
1195 | 351 | |||
1196 | 352 | if ((need_priv != 0) && (is_privileged == 0)) { | ||
1197 | 353 | return -1; | ||
1198 | 354 | } | ||
1199 | 355 | |||
1200 | 356 | SAFE_FREE(response.extra_data.data); | ||
1201 | 357 | |||
1202 | 358 | return winbindd_fd; | ||
1203 | 359 | #else | ||
1204 | 360 | return -1; | ||
1205 | 361 | #endif /* HAVE_UNIXSOCKET */ | ||
1206 | 362 | } | ||
1207 | 363 | |||
1208 | 364 | /* Write data to winbindd socket */ | ||
1209 | 365 | |||
1210 | 366 | int winbind_write_sock(void *buffer, int count, int recursing, int need_priv) | ||
1211 | 367 | { | ||
1212 | 368 | int result, nwritten; | ||
1213 | 369 | |||
1214 | 370 | /* Open connection to winbind daemon */ | ||
1215 | 371 | |||
1216 | 372 | restart: | ||
1217 | 373 | |||
1218 | 374 | if (winbind_open_pipe_sock(recursing, need_priv) == -1) { | ||
1219 | 375 | errno = ENOENT; | ||
1220 | 376 | return -1; | ||
1221 | 377 | } | ||
1222 | 378 | |||
1223 | 379 | /* Write data to socket */ | ||
1224 | 380 | |||
1225 | 381 | nwritten = 0; | ||
1226 | 382 | |||
1227 | 383 | while(nwritten < count) { | ||
1228 | 384 | struct timeval tv; | ||
1229 | 385 | fd_set r_fds; | ||
1230 | 386 | |||
1231 | 387 | /* Catch pipe close on other end by checking if a read() | ||
1232 | 388 | call would not block by calling select(). */ | ||
1233 | 389 | |||
1234 | 390 | FD_ZERO(&r_fds); | ||
1235 | 391 | FD_SET(winbindd_fd, &r_fds); | ||
1236 | 392 | ZERO_STRUCT(tv); | ||
1237 | 393 | |||
1238 | 394 | if (select(winbindd_fd + 1, &r_fds, NULL, NULL, &tv) == -1) { | ||
1239 | 395 | winbind_close_sock(); | ||
1240 | 396 | return -1; /* Select error */ | ||
1241 | 397 | } | ||
1242 | 398 | |||
1243 | 399 | /* Write should be OK if fd not available for reading */ | ||
1244 | 400 | |||
1245 | 401 | if (!FD_ISSET(winbindd_fd, &r_fds)) { | ||
1246 | 402 | |||
1247 | 403 | /* Do the write */ | ||
1248 | 404 | |||
1249 | 405 | result = write(winbindd_fd, | ||
1250 | 406 | (char *)buffer + nwritten, | ||
1251 | 407 | count - nwritten); | ||
1252 | 408 | |||
1253 | 409 | if ((result == -1) || (result == 0)) { | ||
1254 | 410 | |||
1255 | 411 | /* Write failed */ | ||
1256 | 412 | |||
1257 | 413 | winbind_close_sock(); | ||
1258 | 414 | return -1; | ||
1259 | 415 | } | ||
1260 | 416 | |||
1261 | 417 | nwritten += result; | ||
1262 | 418 | |||
1263 | 419 | } else { | ||
1264 | 420 | |||
1265 | 421 | /* Pipe has closed on remote end */ | ||
1266 | 422 | |||
1267 | 423 | winbind_close_sock(); | ||
1268 | 424 | goto restart; | ||
1269 | 425 | } | ||
1270 | 426 | } | ||
1271 | 427 | |||
1272 | 428 | return nwritten; | ||
1273 | 429 | } | ||
1274 | 430 | |||
1275 | 431 | /* Read data from winbindd socket */ | ||
1276 | 432 | |||
1277 | 433 | int winbind_read_sock(void *buffer, int count) | ||
1278 | 434 | { | ||
1279 | 435 | int nread = 0; | ||
1280 | 436 | int total_time = 0, selret; | ||
1281 | 437 | |||
1282 | 438 | if (winbindd_fd == -1) { | ||
1283 | 439 | return -1; | ||
1284 | 440 | } | ||
1285 | 441 | |||
1286 | 442 | /* Read data from socket */ | ||
1287 | 443 | while(nread < count) { | ||
1288 | 444 | struct timeval tv; | ||
1289 | 445 | fd_set r_fds; | ||
1290 | 446 | |||
1291 | 447 | /* Catch pipe close on other end by checking if a read() | ||
1292 | 448 | call would not block by calling select(). */ | ||
1293 | 449 | |||
1294 | 450 | FD_ZERO(&r_fds); | ||
1295 | 451 | FD_SET(winbindd_fd, &r_fds); | ||
1296 | 452 | ZERO_STRUCT(tv); | ||
1297 | 453 | /* Wait for 5 seconds for a reply. May need to parameterise this... */ | ||
1298 | 454 | tv.tv_sec = 5; | ||
1299 | 455 | |||
1300 | 456 | if ((selret = select(winbindd_fd + 1, &r_fds, NULL, NULL, &tv)) == -1) { | ||
1301 | 457 | winbind_close_sock(); | ||
1302 | 458 | return -1; /* Select error */ | ||
1303 | 459 | } | ||
1304 | 460 | |||
1305 | 461 | if (selret == 0) { | ||
1306 | 462 | /* Not ready for read yet... */ | ||
1307 | 463 | if (total_time >= 30) { | ||
1308 | 464 | /* Timeout */ | ||
1309 | 465 | winbind_close_sock(); | ||
1310 | 466 | return -1; | ||
1311 | 467 | } | ||
1312 | 468 | total_time += 5; | ||
1313 | 469 | continue; | ||
1314 | 470 | } | ||
1315 | 471 | |||
1316 | 472 | if (FD_ISSET(winbindd_fd, &r_fds)) { | ||
1317 | 473 | |||
1318 | 474 | /* Do the Read */ | ||
1319 | 475 | |||
1320 | 476 | int result = read(winbindd_fd, (char *)buffer + nread, | ||
1321 | 477 | count - nread); | ||
1322 | 478 | |||
1323 | 479 | if ((result == -1) || (result == 0)) { | ||
1324 | 480 | |||
1325 | 481 | /* Read failed. I think the only useful thing we | ||
1326 | 482 | can do here is just return -1 and fail since the | ||
1327 | 483 | transaction has failed half way through. */ | ||
1328 | 484 | |||
1329 | 485 | winbind_close_sock(); | ||
1330 | 486 | return -1; | ||
1331 | 487 | } | ||
1332 | 488 | |||
1333 | 489 | nread += result; | ||
1334 | 490 | |||
1335 | 491 | } | ||
1336 | 492 | } | ||
1337 | 493 | |||
1338 | 494 | return nread; | ||
1339 | 495 | } | ||
1340 | 496 | |||
1341 | 497 | /* Read reply */ | ||
1342 | 498 | |||
1343 | 499 | int winbindd_read_reply(struct winbindd_response *response) | ||
1344 | 500 | { | ||
1345 | 501 | int result1, result2 = 0; | ||
1346 | 502 | |||
1347 | 503 | if (!response) { | ||
1348 | 504 | return -1; | ||
1349 | 505 | } | ||
1350 | 506 | |||
1351 | 507 | /* Read fixed length response */ | ||
1352 | 508 | |||
1353 | 509 | result1 = winbind_read_sock(response, | ||
1354 | 510 | sizeof(struct winbindd_response)); | ||
1355 | 511 | if (result1 == -1) { | ||
1356 | 512 | return -1; | ||
1357 | 513 | } | ||
1358 | 514 | |||
1359 | 515 | /* We actually send the pointer value of the extra_data field from | ||
1360 | 516 | the server. This has no meaning in the client's address space | ||
1361 | 517 | so we clear it out. */ | ||
1362 | 518 | |||
1363 | 519 | response->extra_data.data = NULL; | ||
1364 | 520 | |||
1365 | 521 | /* Read variable length response */ | ||
1366 | 522 | |||
1367 | 523 | if (response->length > sizeof(struct winbindd_response)) { | ||
1368 | 524 | int extra_data_len = response->length - | ||
1369 | 525 | sizeof(struct winbindd_response); | ||
1370 | 526 | |||
1371 | 527 | /* Mallocate memory for extra data */ | ||
1372 | 528 | |||
1373 | 529 | if (!(response->extra_data.data = malloc(extra_data_len))) { | ||
1374 | 530 | return -1; | ||
1375 | 531 | } | ||
1376 | 532 | |||
1377 | 533 | result2 = winbind_read_sock(response->extra_data.data, | ||
1378 | 534 | extra_data_len); | ||
1379 | 535 | if (result2 == -1) { | ||
1380 | 536 | winbindd_free_response(response); | ||
1381 | 537 | return -1; | ||
1382 | 538 | } | ||
1383 | 539 | } | ||
1384 | 540 | |||
1385 | 541 | /* Return total amount of data read */ | ||
1386 | 542 | |||
1387 | 543 | return result1 + result2; | ||
1388 | 544 | } | ||
1389 | 545 | |||
1390 | 546 | /* | ||
1391 | 547 | * send simple types of requests | ||
1392 | 548 | */ | ||
1393 | 549 | |||
1394 | 550 | NSS_STATUS winbindd_send_request(int req_type, int need_priv, | ||
1395 | 551 | struct winbindd_request *request) | ||
1396 | 552 | { | ||
1397 | 553 | struct winbindd_request lrequest; | ||
1398 | 554 | |||
1399 | 555 | /* Check for our tricky environment variable */ | ||
1400 | 556 | |||
1401 | 557 | if (winbind_env_set()) { | ||
1402 | 558 | return NSS_STATUS_NOTFOUND; | ||
1403 | 559 | } | ||
1404 | 560 | |||
1405 | 561 | if (!request) { | ||
1406 | 562 | ZERO_STRUCT(lrequest); | ||
1407 | 563 | request = &lrequest; | ||
1408 | 564 | } | ||
1409 | 565 | |||
1410 | 566 | /* Fill in request and send down pipe */ | ||
1411 | 567 | |||
1412 | 568 | winbindd_init_request(request, req_type); | ||
1413 | 569 | |||
1414 | 570 | if (winbind_write_sock(request, sizeof(*request), | ||
1415 | 571 | request->wb_flags & WBFLAG_RECURSE, | ||
1416 | 572 | need_priv) == -1) | ||
1417 | 573 | { | ||
1418 | 574 | /* Set ENOENT for consistency. Required by some apps */ | ||
1419 | 575 | errno = ENOENT; | ||
1420 | 576 | |||
1421 | 577 | return NSS_STATUS_UNAVAIL; | ||
1422 | 578 | } | ||
1423 | 579 | |||
1424 | 580 | if ((request->extra_len != 0) && | ||
1425 | 581 | (winbind_write_sock(request->extra_data.data, | ||
1426 | 582 | request->extra_len, | ||
1427 | 583 | request->wb_flags & WBFLAG_RECURSE, | ||
1428 | 584 | need_priv) == -1)) | ||
1429 | 585 | { | ||
1430 | 586 | /* Set ENOENT for consistency. Required by some apps */ | ||
1431 | 587 | errno = ENOENT; | ||
1432 | 588 | |||
1433 | 589 | return NSS_STATUS_UNAVAIL; | ||
1434 | 590 | } | ||
1435 | 591 | |||
1436 | 592 | return NSS_STATUS_SUCCESS; | ||
1437 | 593 | } | ||
1438 | 594 | |||
1439 | 595 | /* | ||
1440 | 596 | * Get results from winbindd request | ||
1441 | 597 | */ | ||
1442 | 598 | |||
1443 | 599 | NSS_STATUS winbindd_get_response(struct winbindd_response *response) | ||
1444 | 600 | { | ||
1445 | 601 | struct winbindd_response lresponse; | ||
1446 | 602 | |||
1447 | 603 | if (!response) { | ||
1448 | 604 | ZERO_STRUCT(lresponse); | ||
1449 | 605 | response = &lresponse; | ||
1450 | 606 | } | ||
1451 | 607 | |||
1452 | 608 | init_response(response); | ||
1453 | 609 | |||
1454 | 610 | /* Wait for reply */ | ||
1455 | 611 | if (winbindd_read_reply(response) == -1) { | ||
1456 | 612 | /* Set ENOENT for consistency. Required by some apps */ | ||
1457 | 613 | errno = ENOENT; | ||
1458 | 614 | |||
1459 | 615 | return NSS_STATUS_UNAVAIL; | ||
1460 | 616 | } | ||
1461 | 617 | |||
1462 | 618 | /* Throw away extra data if client didn't request it */ | ||
1463 | 619 | if (response == &lresponse) { | ||
1464 | 620 | winbindd_free_response(response); | ||
1465 | 621 | } | ||
1466 | 622 | |||
1467 | 623 | /* Copy reply data from socket */ | ||
1468 | 624 | if (response->result != WINBINDD_OK) { | ||
1469 | 625 | return NSS_STATUS_NOTFOUND; | ||
1470 | 626 | } | ||
1471 | 627 | |||
1472 | 628 | return NSS_STATUS_SUCCESS; | ||
1473 | 629 | } | ||
1474 | 630 | |||
1475 | 631 | /* Handle simple types of requests */ | ||
1476 | 632 | |||
1477 | 633 | NSS_STATUS winbindd_request_response(int req_type, | ||
1478 | 634 | struct winbindd_request *request, | ||
1479 | 635 | struct winbindd_response *response) | ||
1480 | 636 | { | ||
1481 | 637 | NSS_STATUS status = NSS_STATUS_UNAVAIL; | ||
1482 | 638 | int count = 0; | ||
1483 | 639 | |||
1484 | 640 | while ((status == NSS_STATUS_UNAVAIL) && (count < 10)) { | ||
1485 | 641 | status = winbindd_send_request(req_type, 0, request); | ||
1486 | 642 | if (status != NSS_STATUS_SUCCESS) | ||
1487 | 643 | return(status); | ||
1488 | 644 | status = winbindd_get_response(response); | ||
1489 | 645 | count += 1; | ||
1490 | 646 | } | ||
1491 | 647 | |||
1492 | 648 | return status; | ||
1493 | 649 | } | ||
1494 | 650 | |||
1495 | 651 | NSS_STATUS winbindd_priv_request_response(int req_type, | ||
1496 | 652 | struct winbindd_request *request, | ||
1497 | 653 | struct winbindd_response *response) | ||
1498 | 654 | { | ||
1499 | 655 | NSS_STATUS status = NSS_STATUS_UNAVAIL; | ||
1500 | 656 | int count = 0; | ||
1501 | 657 | |||
1502 | 658 | while ((status == NSS_STATUS_UNAVAIL) && (count < 10)) { | ||
1503 | 659 | status = winbindd_send_request(req_type, 1, request); | ||
1504 | 660 | if (status != NSS_STATUS_SUCCESS) | ||
1505 | 661 | return(status); | ||
1506 | 662 | status = winbindd_get_response(response); | ||
1507 | 663 | count += 1; | ||
1508 | 664 | } | ||
1509 | 665 | |||
1510 | 666 | return status; | ||
1511 | 667 | } | ||
1512 | 668 | |||
1513 | 669 | /************************************************************************* | ||
1514 | 670 | ************************************************************************/ | ||
1515 | 671 | |||
1516 | 672 | const char *nss_err_str(NSS_STATUS ret) | ||
1517 | 673 | { | ||
1518 | 674 | switch (ret) { | ||
1519 | 675 | case NSS_STATUS_TRYAGAIN: | ||
1520 | 676 | return "NSS_STATUS_TRYAGAIN"; | ||
1521 | 677 | case NSS_STATUS_SUCCESS: | ||
1522 | 678 | return "NSS_STATUS_SUCCESS"; | ||
1523 | 679 | case NSS_STATUS_NOTFOUND: | ||
1524 | 680 | return "NSS_STATUS_NOTFOUND"; | ||
1525 | 681 | case NSS_STATUS_UNAVAIL: | ||
1526 | 682 | return "NSS_STATUS_UNAVAIL"; | ||
1527 | 683 | #ifdef NSS_STATUS_RETURN | ||
1528 | 684 | case NSS_STATUS_RETURN: | ||
1529 | 685 | return "NSS_STATUS_RETURN"; | ||
1530 | 686 | #endif | ||
1531 | 687 | default: | ||
1532 | 688 | return "UNKNOWN RETURN CODE!!!!!!!"; | ||
1533 | 689 | } | ||
1534 | 690 | } | ||
1535 | 0 | 691 | ||
1536 | === added directory '.pc/security-CVE-2011-0719.patch/source3' | |||
1537 | === added directory '.pc/security-CVE-2011-0719.patch/source3/client' | |||
1538 | === added file '.pc/security-CVE-2011-0719.patch/source3/client/client.c' | |||
1539 | --- .pc/security-CVE-2011-0719.patch/source3/client/client.c 1970-01-01 00:00:00 +0000 | |||
1540 | +++ .pc/security-CVE-2011-0719.patch/source3/client/client.c 2011-03-02 20:47:51 +0000 | |||
1541 | @@ -0,0 +1,5022 @@ | |||
1542 | 1 | /* | ||
1543 | 2 | Unix SMB/CIFS implementation. | ||
1544 | 3 | SMB client | ||
1545 | 4 | Copyright (C) Andrew Tridgell 1994-1998 | ||
1546 | 5 | Copyright (C) Simo Sorce 2001-2002 | ||
1547 | 6 | Copyright (C) Jelmer Vernooij 2003 | ||
1548 | 7 | Copyright (C) Gerald (Jerry) Carter 2004 | ||
1549 | 8 | Copyright (C) Jeremy Allison 1994-2007 | ||
1550 | 9 | |||
1551 | 10 | This program is free software; you can redistribute it and/or modify | ||
1552 | 11 | it under the terms of the GNU General Public License as published by | ||
1553 | 12 | the Free Software Foundation; either version 3 of the License, or | ||
1554 | 13 | (at your option) any later version. | ||
1555 | 14 | |||
1556 | 15 | This program is distributed in the hope that it will be useful, | ||
1557 | 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1558 | 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1559 | 18 | GNU General Public License for more details. | ||
1560 | 19 | |||
1561 | 20 | You should have received a copy of the GNU General Public License | ||
1562 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1563 | 22 | */ | ||
1564 | 23 | |||
1565 | 24 | #include "includes.h" | ||
1566 | 25 | #include "client/client_proto.h" | ||
1567 | 26 | #include "include/rpc_client.h" | ||
1568 | 27 | #ifndef REGISTER | ||
1569 | 28 | #define REGISTER 0 | ||
1570 | 29 | #endif | ||
1571 | 30 | |||
1572 | 31 | extern int do_smb_browse(void); /* mDNS browsing */ | ||
1573 | 32 | |||
1574 | 33 | extern bool AllowDebugChange; | ||
1575 | 34 | extern bool override_logfile; | ||
1576 | 35 | extern char tar_type; | ||
1577 | 36 | |||
1578 | 37 | static int port = 0; | ||
1579 | 38 | static char *service; | ||
1580 | 39 | static char *desthost; | ||
1581 | 40 | static char *calling_name; | ||
1582 | 41 | static bool grepable = false; | ||
1583 | 42 | static char *cmdstr = NULL; | ||
1584 | 43 | const char *cmd_ptr = NULL; | ||
1585 | 44 | |||
1586 | 45 | static int io_bufsize = 524288; | ||
1587 | 46 | |||
1588 | 47 | static int name_type = 0x20; | ||
1589 | 48 | static int max_protocol = PROTOCOL_NT1; | ||
1590 | 49 | |||
1591 | 50 | static int process_tok(char *tok); | ||
1592 | 51 | static int cmd_help(void); | ||
1593 | 52 | |||
1594 | 53 | #define CREATE_ACCESS_READ READ_CONTROL_ACCESS | ||
1595 | 54 | |||
1596 | 55 | /* 30 second timeout on most commands */ | ||
1597 | 56 | #define CLIENT_TIMEOUT (30*1000) | ||
1598 | 57 | #define SHORT_TIMEOUT (5*1000) | ||
1599 | 58 | |||
1600 | 59 | /* value for unused fid field in trans2 secondary request */ | ||
1601 | 60 | #define FID_UNUSED (0xFFFF) | ||
1602 | 61 | |||
1603 | 62 | time_t newer_than = 0; | ||
1604 | 63 | static int archive_level = 0; | ||
1605 | 64 | |||
1606 | 65 | static bool translation = false; | ||
1607 | 66 | static bool have_ip; | ||
1608 | 67 | |||
1609 | 68 | /* clitar bits insert */ | ||
1610 | 69 | extern int blocksize; | ||
1611 | 70 | extern bool tar_inc; | ||
1612 | 71 | extern bool tar_reset; | ||
1613 | 72 | /* clitar bits end */ | ||
1614 | 73 | |||
1615 | 74 | static bool prompt = true; | ||
1616 | 75 | |||
1617 | 76 | static bool recurse = false; | ||
1618 | 77 | static bool showacls = false; | ||
1619 | 78 | bool lowercase = false; | ||
1620 | 79 | |||
1621 | 80 | static struct sockaddr_storage dest_ss; | ||
1622 | 81 | static char dest_ss_str[INET6_ADDRSTRLEN]; | ||
1623 | 82 | |||
1624 | 83 | #define SEPARATORS " \t\n\r" | ||
1625 | 84 | |||
1626 | 85 | static bool abort_mget = true; | ||
1627 | 86 | |||
1628 | 87 | /* timing globals */ | ||
1629 | 88 | uint64_t get_total_size = 0; | ||
1630 | 89 | unsigned int get_total_time_ms = 0; | ||
1631 | 90 | static uint64_t put_total_size = 0; | ||
1632 | 91 | static unsigned int put_total_time_ms = 0; | ||
1633 | 92 | |||
1634 | 93 | /* totals globals */ | ||
1635 | 94 | static double dir_total; | ||
1636 | 95 | |||
1637 | 96 | /* encrypted state. */ | ||
1638 | 97 | static bool smb_encrypt; | ||
1639 | 98 | |||
1640 | 99 | /* root cli_state connection */ | ||
1641 | 100 | |||
1642 | 101 | struct cli_state *cli; | ||
1643 | 102 | |||
1644 | 103 | static char CLI_DIRSEP_CHAR = '\\'; | ||
1645 | 104 | static char CLI_DIRSEP_STR[] = { '\\', '\0' }; | ||
1646 | 105 | |||
1647 | 106 | /* Authentication for client connections. */ | ||
1648 | 107 | struct user_auth_info *auth_info; | ||
1649 | 108 | |||
1650 | 109 | /* Accessor functions for directory paths. */ | ||
1651 | 110 | static char *fileselection; | ||
1652 | 111 | static const char *client_get_fileselection(void) | ||
1653 | 112 | { | ||
1654 | 113 | if (fileselection) { | ||
1655 | 114 | return fileselection; | ||
1656 | 115 | } | ||
1657 | 116 | return ""; | ||
1658 | 117 | } | ||
1659 | 118 | |||
1660 | 119 | static const char *client_set_fileselection(const char *new_fs) | ||
1661 | 120 | { | ||
1662 | 121 | SAFE_FREE(fileselection); | ||
1663 | 122 | if (new_fs) { | ||
1664 | 123 | fileselection = SMB_STRDUP(new_fs); | ||
1665 | 124 | } | ||
1666 | 125 | return client_get_fileselection(); | ||
1667 | 126 | } | ||
1668 | 127 | |||
1669 | 128 | static char *cwd; | ||
1670 | 129 | static const char *client_get_cwd(void) | ||
1671 | 130 | { | ||
1672 | 131 | if (cwd) { | ||
1673 | 132 | return cwd; | ||
1674 | 133 | } | ||
1675 | 134 | return CLI_DIRSEP_STR; | ||
1676 | 135 | } | ||
1677 | 136 | |||
1678 | 137 | static const char *client_set_cwd(const char *new_cwd) | ||
1679 | 138 | { | ||
1680 | 139 | SAFE_FREE(cwd); | ||
1681 | 140 | if (new_cwd) { | ||
1682 | 141 | cwd = SMB_STRDUP(new_cwd); | ||
1683 | 142 | } | ||
1684 | 143 | return client_get_cwd(); | ||
1685 | 144 | } | ||
1686 | 145 | |||
1687 | 146 | static char *cur_dir; | ||
1688 | 147 | const char *client_get_cur_dir(void) | ||
1689 | 148 | { | ||
1690 | 149 | if (cur_dir) { | ||
1691 | 150 | return cur_dir; | ||
1692 | 151 | } | ||
1693 | 152 | return CLI_DIRSEP_STR; | ||
1694 | 153 | } | ||
1695 | 154 | |||
1696 | 155 | const char *client_set_cur_dir(const char *newdir) | ||
1697 | 156 | { | ||
1698 | 157 | SAFE_FREE(cur_dir); | ||
1699 | 158 | if (newdir) { | ||
1700 | 159 | cur_dir = SMB_STRDUP(newdir); | ||
1701 | 160 | } | ||
1702 | 161 | return client_get_cur_dir(); | ||
1703 | 162 | } | ||
1704 | 163 | |||
1705 | 164 | /**************************************************************************** | ||
1706 | 165 | Write to a local file with CR/LF->LF translation if appropriate. Return the | ||
1707 | 166 | number taken from the buffer. This may not equal the number written. | ||
1708 | 167 | ****************************************************************************/ | ||
1709 | 168 | |||
1710 | 169 | static int writefile(int f, char *b, int n) | ||
1711 | 170 | { | ||
1712 | 171 | int i; | ||
1713 | 172 | |||
1714 | 173 | if (!translation) { | ||
1715 | 174 | return write(f,b,n); | ||
1716 | 175 | } | ||
1717 | 176 | |||
1718 | 177 | i = 0; | ||
1719 | 178 | while (i < n) { | ||
1720 | 179 | if (*b == '\r' && (i<(n-1)) && *(b+1) == '\n') { | ||
1721 | 180 | b++;i++; | ||
1722 | 181 | } | ||
1723 | 182 | if (write(f, b, 1) != 1) { | ||
1724 | 183 | break; | ||
1725 | 184 | } | ||
1726 | 185 | b++; | ||
1727 | 186 | i++; | ||
1728 | 187 | } | ||
1729 | 188 | |||
1730 | 189 | return(i); | ||
1731 | 190 | } | ||
1732 | 191 | |||
1733 | 192 | /**************************************************************************** | ||
1734 | 193 | Read from a file with LF->CR/LF translation if appropriate. Return the | ||
1735 | 194 | number read. read approx n bytes. | ||
1736 | 195 | ****************************************************************************/ | ||
1737 | 196 | |||
1738 | 197 | static int readfile(uint8_t *b, int n, XFILE *f) | ||
1739 | 198 | { | ||
1740 | 199 | int i; | ||
1741 | 200 | int c; | ||
1742 | 201 | |||
1743 | 202 | if (!translation) | ||
1744 | 203 | return x_fread(b,1,n,f); | ||
1745 | 204 | |||
1746 | 205 | i = 0; | ||
1747 | 206 | while (i < (n - 1) && (i < BUFFER_SIZE)) { | ||
1748 | 207 | if ((c = x_getc(f)) == EOF) { | ||
1749 | 208 | break; | ||
1750 | 209 | } | ||
1751 | 210 | |||
1752 | 211 | if (c == '\n') { /* change all LFs to CR/LF */ | ||
1753 | 212 | b[i++] = '\r'; | ||
1754 | 213 | } | ||
1755 | 214 | |||
1756 | 215 | b[i++] = c; | ||
1757 | 216 | } | ||
1758 | 217 | |||
1759 | 218 | return(i); | ||
1760 | 219 | } | ||
1761 | 220 | |||
1762 | 221 | struct push_state { | ||
1763 | 222 | XFILE *f; | ||
1764 | 223 | SMB_OFF_T nread; | ||
1765 | 224 | }; | ||
1766 | 225 | |||
1767 | 226 | static size_t push_source(uint8_t *buf, size_t n, void *priv) | ||
1768 | 227 | { | ||
1769 | 228 | struct push_state *state = (struct push_state *)priv; | ||
1770 | 229 | int result; | ||
1771 | 230 | |||
1772 | 231 | if (x_feof(state->f)) { | ||
1773 | 232 | return 0; | ||
1774 | 233 | } | ||
1775 | 234 | |||
1776 | 235 | result = readfile(buf, n, state->f); | ||
1777 | 236 | state->nread += result; | ||
1778 | 237 | return result; | ||
1779 | 238 | } | ||
1780 | 239 | |||
1781 | 240 | /**************************************************************************** | ||
1782 | 241 | Send a message. | ||
1783 | 242 | ****************************************************************************/ | ||
1784 | 243 | |||
1785 | 244 | static void send_message(const char *username) | ||
1786 | 245 | { | ||
1787 | 246 | int total_len = 0; | ||
1788 | 247 | int grp_id; | ||
1789 | 248 | |||
1790 | 249 | if (!cli_message_start(cli, desthost, username, &grp_id)) { | ||
1791 | 250 | d_printf("message start: %s\n", cli_errstr(cli)); | ||
1792 | 251 | return; | ||
1793 | 252 | } | ||
1794 | 253 | |||
1795 | 254 | |||
1796 | 255 | d_printf("Connected. Type your message, ending it with a Control-D\n"); | ||
1797 | 256 | |||
1798 | 257 | while (!feof(stdin) && total_len < 1600) { | ||
1799 | 258 | int maxlen = MIN(1600 - total_len,127); | ||
1800 | 259 | char msg[1024]; | ||
1801 | 260 | int l=0; | ||
1802 | 261 | int c; | ||
1803 | 262 | |||
1804 | 263 | ZERO_ARRAY(msg); | ||
1805 | 264 | |||
1806 | 265 | for (l=0;l<maxlen && (c=fgetc(stdin))!=EOF;l++) { | ||
1807 | 266 | if (c == '\n') | ||
1808 | 267 | msg[l++] = '\r'; | ||
1809 | 268 | msg[l] = c; | ||
1810 | 269 | } | ||
1811 | 270 | |||
1812 | 271 | if ((total_len > 0) && (strlen(msg) == 0)) { | ||
1813 | 272 | break; | ||
1814 | 273 | } | ||
1815 | 274 | |||
1816 | 275 | if (!cli_message_text(cli, msg, l, grp_id)) { | ||
1817 | 276 | d_printf("SMBsendtxt failed (%s)\n",cli_errstr(cli)); | ||
1818 | 277 | return; | ||
1819 | 278 | } | ||
1820 | 279 | |||
1821 | 280 | total_len += l; | ||
1822 | 281 | } | ||
1823 | 282 | |||
1824 | 283 | if (total_len >= 1600) | ||
1825 | 284 | d_printf("the message was truncated to 1600 bytes\n"); | ||
1826 | 285 | else | ||
1827 | 286 | d_printf("sent %d bytes\n",total_len); | ||
1828 | 287 | |||
1829 | 288 | if (!cli_message_end(cli, grp_id)) { | ||
1830 | 289 | d_printf("SMBsendend failed (%s)\n",cli_errstr(cli)); | ||
1831 | 290 | return; | ||
1832 | 291 | } | ||
1833 | 292 | } | ||
1834 | 293 | |||
1835 | 294 | /**************************************************************************** | ||
1836 | 295 | Check the space on a device. | ||
1837 | 296 | ****************************************************************************/ | ||
1838 | 297 | |||
1839 | 298 | static int do_dskattr(void) | ||
1840 | 299 | { | ||
1841 | 300 | int total, bsize, avail; | ||
1842 | 301 | struct cli_state *targetcli = NULL; | ||
1843 | 302 | char *targetpath = NULL; | ||
1844 | 303 | TALLOC_CTX *ctx = talloc_tos(); | ||
1845 | 304 | |||
1846 | 305 | if ( !cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(), &targetcli, &targetpath)) { | ||
1847 | 306 | d_printf("Error in dskattr: %s\n", cli_errstr(cli)); | ||
1848 | 307 | return 1; | ||
1849 | 308 | } | ||
1850 | 309 | |||
1851 | 310 | if (!cli_dskattr(targetcli, &bsize, &total, &avail)) { | ||
1852 | 311 | d_printf("Error in dskattr: %s\n",cli_errstr(targetcli)); | ||
1853 | 312 | return 1; | ||
1854 | 313 | } | ||
1855 | 314 | |||
1856 | 315 | d_printf("\n\t\t%d blocks of size %d. %d blocks available\n", | ||
1857 | 316 | total, bsize, avail); | ||
1858 | 317 | |||
1859 | 318 | return 0; | ||
1860 | 319 | } | ||
1861 | 320 | |||
1862 | 321 | /**************************************************************************** | ||
1863 | 322 | Show cd/pwd. | ||
1864 | 323 | ****************************************************************************/ | ||
1865 | 324 | |||
1866 | 325 | static int cmd_pwd(void) | ||
1867 | 326 | { | ||
1868 | 327 | d_printf("Current directory is %s",service); | ||
1869 | 328 | d_printf("%s\n",client_get_cur_dir()); | ||
1870 | 329 | return 0; | ||
1871 | 330 | } | ||
1872 | 331 | |||
1873 | 332 | /**************************************************************************** | ||
1874 | 333 | Ensure name has correct directory separators. | ||
1875 | 334 | ****************************************************************************/ | ||
1876 | 335 | |||
1877 | 336 | static void normalize_name(char *newdir) | ||
1878 | 337 | { | ||
1879 | 338 | if (!(cli->posix_capabilities & CIFS_UNIX_POSIX_PATHNAMES_CAP)) { | ||
1880 | 339 | string_replace(newdir,'/','\\'); | ||
1881 | 340 | } | ||
1882 | 341 | } | ||
1883 | 342 | |||
1884 | 343 | /**************************************************************************** | ||
1885 | 344 | Change directory - inner section. | ||
1886 | 345 | ****************************************************************************/ | ||
1887 | 346 | |||
1888 | 347 | static int do_cd(const char *new_dir) | ||
1889 | 348 | { | ||
1890 | 349 | char *newdir = NULL; | ||
1891 | 350 | char *saved_dir = NULL; | ||
1892 | 351 | char *new_cd = NULL; | ||
1893 | 352 | char *targetpath = NULL; | ||
1894 | 353 | struct cli_state *targetcli = NULL; | ||
1895 | 354 | SMB_STRUCT_STAT sbuf; | ||
1896 | 355 | uint32 attributes; | ||
1897 | 356 | int ret = 1; | ||
1898 | 357 | TALLOC_CTX *ctx = talloc_stackframe(); | ||
1899 | 358 | |||
1900 | 359 | newdir = talloc_strdup(ctx, new_dir); | ||
1901 | 360 | if (!newdir) { | ||
1902 | 361 | TALLOC_FREE(ctx); | ||
1903 | 362 | return 1; | ||
1904 | 363 | } | ||
1905 | 364 | |||
1906 | 365 | normalize_name(newdir); | ||
1907 | 366 | |||
1908 | 367 | /* Save the current directory in case the new directory is invalid */ | ||
1909 | 368 | |||
1910 | 369 | saved_dir = talloc_strdup(ctx, client_get_cur_dir()); | ||
1911 | 370 | if (!saved_dir) { | ||
1912 | 371 | TALLOC_FREE(ctx); | ||
1913 | 372 | return 1; | ||
1914 | 373 | } | ||
1915 | 374 | |||
1916 | 375 | if (*newdir == CLI_DIRSEP_CHAR) { | ||
1917 | 376 | client_set_cur_dir(newdir); | ||
1918 | 377 | new_cd = newdir; | ||
1919 | 378 | } else { | ||
1920 | 379 | new_cd = talloc_asprintf(ctx, "%s%s", | ||
1921 | 380 | client_get_cur_dir(), | ||
1922 | 381 | newdir); | ||
1923 | 382 | if (!new_cd) { | ||
1924 | 383 | goto out; | ||
1925 | 384 | } | ||
1926 | 385 | } | ||
1927 | 386 | |||
1928 | 387 | /* Ensure cur_dir ends in a DIRSEP */ | ||
1929 | 388 | if ((new_cd[0] != '\0') && (*(new_cd+strlen(new_cd)-1) != CLI_DIRSEP_CHAR)) { | ||
1930 | 389 | new_cd = talloc_asprintf_append(new_cd, "%s", CLI_DIRSEP_STR); | ||
1931 | 390 | if (!new_cd) { | ||
1932 | 391 | goto out; | ||
1933 | 392 | } | ||
1934 | 393 | } | ||
1935 | 394 | client_set_cur_dir(new_cd); | ||
1936 | 395 | |||
1937 | 396 | new_cd = clean_name(ctx, new_cd); | ||
1938 | 397 | client_set_cur_dir(new_cd); | ||
1939 | 398 | |||
1940 | 399 | if ( !cli_resolve_path(ctx, "", auth_info, cli, new_cd, &targetcli, &targetpath)) { | ||
1941 | 400 | d_printf("cd %s: %s\n", new_cd, cli_errstr(cli)); | ||
1942 | 401 | client_set_cur_dir(saved_dir); | ||
1943 | 402 | goto out; | ||
1944 | 403 | } | ||
1945 | 404 | |||
1946 | 405 | if (strequal(targetpath,CLI_DIRSEP_STR )) { | ||
1947 | 406 | TALLOC_FREE(ctx); | ||
1948 | 407 | return 0; | ||
1949 | 408 | } | ||
1950 | 409 | |||
1951 | 410 | /* Use a trans2_qpathinfo to test directories for modern servers. | ||
1952 | 411 | Except Win9x doesn't support the qpathinfo_basic() call..... */ | ||
1953 | 412 | |||
1954 | 413 | if (targetcli->protocol > PROTOCOL_LANMAN2 && !targetcli->win95) { | ||
1955 | 414 | if (!cli_qpathinfo_basic( targetcli, targetpath, &sbuf, &attributes ) ) { | ||
1956 | 415 | d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli)); | ||
1957 | 416 | client_set_cur_dir(saved_dir); | ||
1958 | 417 | goto out; | ||
1959 | 418 | } | ||
1960 | 419 | |||
1961 | 420 | if (!(attributes & FILE_ATTRIBUTE_DIRECTORY)) { | ||
1962 | 421 | d_printf("cd %s: not a directory\n", new_cd); | ||
1963 | 422 | client_set_cur_dir(saved_dir); | ||
1964 | 423 | goto out; | ||
1965 | 424 | } | ||
1966 | 425 | } else { | ||
1967 | 426 | targetpath = talloc_asprintf(ctx, | ||
1968 | 427 | "%s%s", | ||
1969 | 428 | targetpath, | ||
1970 | 429 | CLI_DIRSEP_STR ); | ||
1971 | 430 | if (!targetpath) { | ||
1972 | 431 | client_set_cur_dir(saved_dir); | ||
1973 | 432 | goto out; | ||
1974 | 433 | } | ||
1975 | 434 | targetpath = clean_name(ctx, targetpath); | ||
1976 | 435 | if (!targetpath) { | ||
1977 | 436 | client_set_cur_dir(saved_dir); | ||
1978 | 437 | goto out; | ||
1979 | 438 | } | ||
1980 | 439 | |||
1981 | 440 | if (!cli_chkpath(targetcli, targetpath)) { | ||
1982 | 441 | d_printf("cd %s: %s\n", new_cd, cli_errstr(targetcli)); | ||
1983 | 442 | client_set_cur_dir(saved_dir); | ||
1984 | 443 | goto out; | ||
1985 | 444 | } | ||
1986 | 445 | } | ||
1987 | 446 | |||
1988 | 447 | ret = 0; | ||
1989 | 448 | |||
1990 | 449 | out: | ||
1991 | 450 | |||
1992 | 451 | TALLOC_FREE(ctx); | ||
1993 | 452 | return ret; | ||
1994 | 453 | } | ||
1995 | 454 | |||
1996 | 455 | /**************************************************************************** | ||
1997 | 456 | Change directory. | ||
1998 | 457 | ****************************************************************************/ | ||
1999 | 458 | |||
2000 | 459 | static int cmd_cd(void) | ||
2001 | 460 | { | ||
2002 | 461 | char *buf = NULL; | ||
2003 | 462 | int rc = 0; | ||
2004 | 463 | |||
2005 | 464 | if (next_token_talloc(talloc_tos(), &cmd_ptr, &buf,NULL)) { | ||
2006 | 465 | rc = do_cd(buf); | ||
2007 | 466 | } else { | ||
2008 | 467 | d_printf("Current directory is %s\n",client_get_cur_dir()); | ||
2009 | 468 | } | ||
2010 | 469 | |||
2011 | 470 | return rc; | ||
2012 | 471 | } | ||
2013 | 472 | |||
2014 | 473 | /**************************************************************************** | ||
2015 | 474 | Change directory. | ||
2016 | 475 | ****************************************************************************/ | ||
2017 | 476 | |||
2018 | 477 | static int cmd_cd_oneup(void) | ||
2019 | 478 | { | ||
2020 | 479 | return do_cd(".."); | ||
2021 | 480 | } | ||
2022 | 481 | |||
2023 | 482 | /******************************************************************* | ||
2024 | 483 | Decide if a file should be operated on. | ||
2025 | 484 | ********************************************************************/ | ||
2026 | 485 | |||
2027 | 486 | static bool do_this_one(file_info *finfo) | ||
2028 | 487 | { | ||
2029 | 488 | if (!finfo->name) { | ||
2030 | 489 | return false; | ||
2031 | 490 | } | ||
2032 | 491 | |||
2033 | 492 | if (finfo->mode & aDIR) { | ||
2034 | 493 | return true; | ||
2035 | 494 | } | ||
2036 | 495 | |||
2037 | 496 | if (*client_get_fileselection() && | ||
2038 | 497 | !mask_match(finfo->name,client_get_fileselection(),false)) { | ||
2039 | 498 | DEBUG(3,("mask_match %s failed\n", finfo->name)); | ||
2040 | 499 | return false; | ||
2041 | 500 | } | ||
2042 | 501 | |||
2043 | 502 | if (newer_than && finfo->mtime_ts.tv_sec < newer_than) { | ||
2044 | 503 | DEBUG(3,("newer_than %s failed\n", finfo->name)); | ||
2045 | 504 | return false; | ||
2046 | 505 | } | ||
2047 | 506 | |||
2048 | 507 | if ((archive_level==1 || archive_level==2) && !(finfo->mode & aARCH)) { | ||
2049 | 508 | DEBUG(3,("archive %s failed\n", finfo->name)); | ||
2050 | 509 | return false; | ||
2051 | 510 | } | ||
2052 | 511 | |||
2053 | 512 | return true; | ||
2054 | 513 | } | ||
2055 | 514 | |||
2056 | 515 | /**************************************************************************** | ||
2057 | 516 | Display info about a file. | ||
2058 | 517 | ****************************************************************************/ | ||
2059 | 518 | |||
2060 | 519 | static void display_finfo(file_info *finfo, const char *dir) | ||
2061 | 520 | { | ||
2062 | 521 | time_t t; | ||
2063 | 522 | TALLOC_CTX *ctx = talloc_tos(); | ||
2064 | 523 | |||
2065 | 524 | if (!do_this_one(finfo)) { | ||
2066 | 525 | return; | ||
2067 | 526 | } | ||
2068 | 527 | |||
2069 | 528 | t = finfo->mtime_ts.tv_sec; /* the time is assumed to be passed as GMT */ | ||
2070 | 529 | if (!showacls) { | ||
2071 | 530 | d_printf(" %-30s%7.7s %8.0f %s", | ||
2072 | 531 | finfo->name, | ||
2073 | 532 | attrib_string(finfo->mode), | ||
2074 | 533 | (double)finfo->size, | ||
2075 | 534 | time_to_asc(t)); | ||
2076 | 535 | dir_total += finfo->size; | ||
2077 | 536 | } else { | ||
2078 | 537 | char *afname = NULL; | ||
2079 | 538 | int fnum; | ||
2080 | 539 | |||
2081 | 540 | /* skip if this is . or .. */ | ||
2082 | 541 | if ( strequal(finfo->name,"..") || strequal(finfo->name,".") ) | ||
2083 | 542 | return; | ||
2084 | 543 | /* create absolute filename for cli_nt_create() FIXME */ | ||
2085 | 544 | afname = talloc_asprintf(ctx, | ||
2086 | 545 | "%s%s%s", | ||
2087 | 546 | dir, | ||
2088 | 547 | CLI_DIRSEP_STR, | ||
2089 | 548 | finfo->name); | ||
2090 | 549 | if (!afname) { | ||
2091 | 550 | return; | ||
2092 | 551 | } | ||
2093 | 552 | /* print file meta date header */ | ||
2094 | 553 | d_printf( "FILENAME:%s\n", finfo->name); | ||
2095 | 554 | d_printf( "MODE:%s\n", attrib_string(finfo->mode)); | ||
2096 | 555 | d_printf( "SIZE:%.0f\n", (double)finfo->size); | ||
2097 | 556 | d_printf( "MTIME:%s", time_to_asc(t)); | ||
2098 | 557 | fnum = cli_nt_create(finfo->cli, afname, CREATE_ACCESS_READ); | ||
2099 | 558 | if (fnum == -1) { | ||
2100 | 559 | DEBUG( 0, ("display_finfo() Failed to open %s: %s\n", | ||
2101 | 560 | afname, | ||
2102 | 561 | cli_errstr( finfo->cli))); | ||
2103 | 562 | } else { | ||
2104 | 563 | SEC_DESC *sd = NULL; | ||
2105 | 564 | sd = cli_query_secdesc(finfo->cli, fnum, ctx); | ||
2106 | 565 | if (!sd) { | ||
2107 | 566 | DEBUG( 0, ("display_finfo() failed to " | ||
2108 | 567 | "get security descriptor: %s", | ||
2109 | 568 | cli_errstr( finfo->cli))); | ||
2110 | 569 | } else { | ||
2111 | 570 | display_sec_desc(sd); | ||
2112 | 571 | } | ||
2113 | 572 | TALLOC_FREE(sd); | ||
2114 | 573 | } | ||
2115 | 574 | TALLOC_FREE(afname); | ||
2116 | 575 | } | ||
2117 | 576 | } | ||
2118 | 577 | |||
2119 | 578 | /**************************************************************************** | ||
2120 | 579 | Accumulate size of a file. | ||
2121 | 580 | ****************************************************************************/ | ||
2122 | 581 | |||
2123 | 582 | static void do_du(file_info *finfo, const char *dir) | ||
2124 | 583 | { | ||
2125 | 584 | if (do_this_one(finfo)) { | ||
2126 | 585 | dir_total += finfo->size; | ||
2127 | 586 | } | ||
2128 | 587 | } | ||
2129 | 588 | |||
2130 | 589 | static bool do_list_recurse; | ||
2131 | 590 | static bool do_list_dirs; | ||
2132 | 591 | static char *do_list_queue = 0; | ||
2133 | 592 | static long do_list_queue_size = 0; | ||
2134 | 593 | static long do_list_queue_start = 0; | ||
2135 | 594 | static long do_list_queue_end = 0; | ||
2136 | 595 | static void (*do_list_fn)(file_info *, const char *dir); | ||
2137 | 596 | |||
2138 | 597 | /**************************************************************************** | ||
2139 | 598 | Functions for do_list_queue. | ||
2140 | 599 | ****************************************************************************/ | ||
2141 | 600 | |||
2142 | 601 | /* | ||
2143 | 602 | * The do_list_queue is a NUL-separated list of strings stored in a | ||
2144 | 603 | * char*. Since this is a FIFO, we keep track of the beginning and | ||
2145 | 604 | * ending locations of the data in the queue. When we overflow, we | ||
2146 | 605 | * double the size of the char*. When the start of the data passes | ||
2147 | 606 | * the midpoint, we move everything back. This is logically more | ||
2148 | 607 | * complex than a linked list, but easier from a memory management | ||
2149 | 608 | * angle. In any memory error condition, do_list_queue is reset. | ||
2150 | 609 | * Functions check to ensure that do_list_queue is non-NULL before | ||
2151 | 610 | * accessing it. | ||
2152 | 611 | */ | ||
2153 | 612 | |||
2154 | 613 | static void reset_do_list_queue(void) | ||
2155 | 614 | { | ||
2156 | 615 | SAFE_FREE(do_list_queue); | ||
2157 | 616 | do_list_queue_size = 0; | ||
2158 | 617 | do_list_queue_start = 0; | ||
2159 | 618 | do_list_queue_end = 0; | ||
2160 | 619 | } | ||
2161 | 620 | |||
2162 | 621 | static void init_do_list_queue(void) | ||
2163 | 622 | { | ||
2164 | 623 | reset_do_list_queue(); | ||
2165 | 624 | do_list_queue_size = 1024; | ||
2166 | 625 | do_list_queue = (char *)SMB_MALLOC(do_list_queue_size); | ||
2167 | 626 | if (do_list_queue == 0) { | ||
2168 | 627 | d_printf("malloc fail for size %d\n", | ||
2169 | 628 | (int)do_list_queue_size); | ||
2170 | 629 | reset_do_list_queue(); | ||
2171 | 630 | } else { | ||
2172 | 631 | memset(do_list_queue, 0, do_list_queue_size); | ||
2173 | 632 | } | ||
2174 | 633 | } | ||
2175 | 634 | |||
2176 | 635 | static void adjust_do_list_queue(void) | ||
2177 | 636 | { | ||
2178 | 637 | /* | ||
2179 | 638 | * If the starting point of the queue is more than half way through, | ||
2180 | 639 | * move everything toward the beginning. | ||
2181 | 640 | */ | ||
2182 | 641 | |||
2183 | 642 | if (do_list_queue == NULL) { | ||
2184 | 643 | DEBUG(4,("do_list_queue is empty\n")); | ||
2185 | 644 | do_list_queue_start = do_list_queue_end = 0; | ||
2186 | 645 | return; | ||
2187 | 646 | } | ||
2188 | 647 | |||
2189 | 648 | if (do_list_queue_start == do_list_queue_end) { | ||
2190 | 649 | DEBUG(4,("do_list_queue is empty\n")); | ||
2191 | 650 | do_list_queue_start = do_list_queue_end = 0; | ||
2192 | 651 | *do_list_queue = '\0'; | ||
2193 | 652 | } else if (do_list_queue_start > (do_list_queue_size / 2)) { | ||
2194 | 653 | DEBUG(4,("sliding do_list_queue backward\n")); | ||
2195 | 654 | memmove(do_list_queue, | ||
2196 | 655 | do_list_queue + do_list_queue_start, | ||
2197 | 656 | do_list_queue_end - do_list_queue_start); | ||
2198 | 657 | do_list_queue_end -= do_list_queue_start; | ||
2199 | 658 | do_list_queue_start = 0; | ||
2200 | 659 | } | ||
2201 | 660 | } | ||
2202 | 661 | |||
2203 | 662 | static void add_to_do_list_queue(const char *entry) | ||
2204 | 663 | { | ||
2205 | 664 | long new_end = do_list_queue_end + ((long)strlen(entry)) + 1; | ||
2206 | 665 | while (new_end > do_list_queue_size) { | ||
2207 | 666 | do_list_queue_size *= 2; | ||
2208 | 667 | DEBUG(4,("enlarging do_list_queue to %d\n", | ||
2209 | 668 | (int)do_list_queue_size)); | ||
2210 | 669 | do_list_queue = (char *)SMB_REALLOC(do_list_queue, do_list_queue_size); | ||
2211 | 670 | if (! do_list_queue) { | ||
2212 | 671 | d_printf("failure enlarging do_list_queue to %d bytes\n", | ||
2213 | 672 | (int)do_list_queue_size); | ||
2214 | 673 | reset_do_list_queue(); | ||
2215 | 674 | } else { | ||
2216 | 675 | memset(do_list_queue + do_list_queue_size / 2, | ||
2217 | 676 | 0, do_list_queue_size / 2); | ||
2218 | 677 | } | ||
2219 | 678 | } | ||
2220 | 679 | if (do_list_queue) { | ||
2221 | 680 | safe_strcpy_base(do_list_queue + do_list_queue_end, | ||
2222 | 681 | entry, do_list_queue, do_list_queue_size); | ||
2223 | 682 | do_list_queue_end = new_end; | ||
2224 | 683 | DEBUG(4,("added %s to do_list_queue (start=%d, end=%d)\n", | ||
2225 | 684 | entry, (int)do_list_queue_start, (int)do_list_queue_end)); | ||
2226 | 685 | } | ||
2227 | 686 | } | ||
2228 | 687 | |||
2229 | 688 | static char *do_list_queue_head(void) | ||
2230 | 689 | { | ||
2231 | 690 | return do_list_queue + do_list_queue_start; | ||
2232 | 691 | } | ||
2233 | 692 | |||
2234 | 693 | static void remove_do_list_queue_head(void) | ||
2235 | 694 | { | ||
2236 | 695 | if (do_list_queue_end > do_list_queue_start) { | ||
2237 | 696 | do_list_queue_start += strlen(do_list_queue_head()) + 1; | ||
2238 | 697 | adjust_do_list_queue(); | ||
2239 | 698 | DEBUG(4,("removed head of do_list_queue (start=%d, end=%d)\n", | ||
2240 | 699 | (int)do_list_queue_start, (int)do_list_queue_end)); | ||
2241 | 700 | } | ||
2242 | 701 | } | ||
2243 | 702 | |||
2244 | 703 | static int do_list_queue_empty(void) | ||
2245 | 704 | { | ||
2246 | 705 | return (! (do_list_queue && *do_list_queue)); | ||
2247 | 706 | } | ||
2248 | 707 | |||
2249 | 708 | /**************************************************************************** | ||
2250 | 709 | A helper for do_list. | ||
2251 | 710 | ****************************************************************************/ | ||
2252 | 711 | |||
2253 | 712 | static void do_list_helper(const char *mntpoint, file_info *f, const char *mask, void *state) | ||
2254 | 713 | { | ||
2255 | 714 | TALLOC_CTX *ctx = talloc_tos(); | ||
2256 | 715 | char *dir = NULL; | ||
2257 | 716 | char *dir_end = NULL; | ||
2258 | 717 | |||
2259 | 718 | /* Work out the directory. */ | ||
2260 | 719 | dir = talloc_strdup(ctx, mask); | ||
2261 | 720 | if (!dir) { | ||
2262 | 721 | return; | ||
2263 | 722 | } | ||
2264 | 723 | if ((dir_end = strrchr(dir, CLI_DIRSEP_CHAR)) != NULL) { | ||
2265 | 724 | *dir_end = '\0'; | ||
2266 | 725 | } | ||
2267 | 726 | |||
2268 | 727 | if (f->mode & aDIR) { | ||
2269 | 728 | if (do_list_dirs && do_this_one(f)) { | ||
2270 | 729 | do_list_fn(f, dir); | ||
2271 | 730 | } | ||
2272 | 731 | if (do_list_recurse && | ||
2273 | 732 | f->name && | ||
2274 | 733 | !strequal(f->name,".") && | ||
2275 | 734 | !strequal(f->name,"..")) { | ||
2276 | 735 | char *mask2 = NULL; | ||
2277 | 736 | char *p = NULL; | ||
2278 | 737 | |||
2279 | 738 | if (!f->name[0]) { | ||
2280 | 739 | d_printf("Empty dir name returned. Possible server misconfiguration.\n"); | ||
2281 | 740 | TALLOC_FREE(dir); | ||
2282 | 741 | return; | ||
2283 | 742 | } | ||
2284 | 743 | |||
2285 | 744 | mask2 = talloc_asprintf(ctx, | ||
2286 | 745 | "%s%s", | ||
2287 | 746 | mntpoint, | ||
2288 | 747 | mask); | ||
2289 | 748 | if (!mask2) { | ||
2290 | 749 | TALLOC_FREE(dir); | ||
2291 | 750 | return; | ||
2292 | 751 | } | ||
2293 | 752 | p = strrchr_m(mask2,CLI_DIRSEP_CHAR); | ||
2294 | 753 | if (p) { | ||
2295 | 754 | p[1] = 0; | ||
2296 | 755 | } else { | ||
2297 | 756 | mask2[0] = '\0'; | ||
2298 | 757 | } | ||
2299 | 758 | mask2 = talloc_asprintf_append(mask2, | ||
2300 | 759 | "%s%s*", | ||
2301 | 760 | f->name, | ||
2302 | 761 | CLI_DIRSEP_STR); | ||
2303 | 762 | if (!mask2) { | ||
2304 | 763 | TALLOC_FREE(dir); | ||
2305 | 764 | return; | ||
2306 | 765 | } | ||
2307 | 766 | add_to_do_list_queue(mask2); | ||
2308 | 767 | TALLOC_FREE(mask2); | ||
2309 | 768 | } | ||
2310 | 769 | TALLOC_FREE(dir); | ||
2311 | 770 | return; | ||
2312 | 771 | } | ||
2313 | 772 | |||
2314 | 773 | if (do_this_one(f)) { | ||
2315 | 774 | do_list_fn(f,dir); | ||
2316 | 775 | } | ||
2317 | 776 | TALLOC_FREE(dir); | ||
2318 | 777 | } | ||
2319 | 778 | |||
2320 | 779 | /**************************************************************************** | ||
2321 | 780 | A wrapper around cli_list that adds recursion. | ||
2322 | 781 | ****************************************************************************/ | ||
2323 | 782 | |||
2324 | 783 | void do_list(const char *mask, | ||
2325 | 784 | uint16 attribute, | ||
2326 | 785 | void (*fn)(file_info *, const char *dir), | ||
2327 | 786 | bool rec, | ||
2328 | 787 | bool dirs) | ||
2329 | 788 | { | ||
2330 | 789 | static int in_do_list = 0; | ||
2331 | 790 | TALLOC_CTX *ctx = talloc_tos(); | ||
2332 | 791 | struct cli_state *targetcli = NULL; | ||
2333 | 792 | char *targetpath = NULL; | ||
2334 | 793 | |||
2335 | 794 | if (in_do_list && rec) { | ||
2336 | 795 | fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n"); | ||
2337 | 796 | exit(1); | ||
2338 | 797 | } | ||
2339 | 798 | |||
2340 | 799 | in_do_list = 1; | ||
2341 | 800 | |||
2342 | 801 | do_list_recurse = rec; | ||
2343 | 802 | do_list_dirs = dirs; | ||
2344 | 803 | do_list_fn = fn; | ||
2345 | 804 | |||
2346 | 805 | if (rec) { | ||
2347 | 806 | init_do_list_queue(); | ||
2348 | 807 | add_to_do_list_queue(mask); | ||
2349 | 808 | |||
2350 | 809 | while (!do_list_queue_empty()) { | ||
2351 | 810 | /* | ||
2352 | 811 | * Need to copy head so that it doesn't become | ||
2353 | 812 | * invalid inside the call to cli_list. This | ||
2354 | 813 | * would happen if the list were expanded | ||
2355 | 814 | * during the call. | ||
2356 | 815 | * Fix from E. Jay Berkenbilt (ejb@ql.org) | ||
2357 | 816 | */ | ||
2358 | 817 | char *head = talloc_strdup(ctx, do_list_queue_head()); | ||
2359 | 818 | |||
2360 | 819 | if (!head) { | ||
2361 | 820 | return; | ||
2362 | 821 | } | ||
2363 | 822 | |||
2364 | 823 | /* check for dfs */ | ||
2365 | 824 | |||
2366 | 825 | if ( !cli_resolve_path(ctx, "", auth_info, cli, head, &targetcli, &targetpath ) ) { | ||
2367 | 826 | d_printf("do_list: [%s] %s\n", head, cli_errstr(cli)); | ||
2368 | 827 | remove_do_list_queue_head(); | ||
2369 | 828 | continue; | ||
2370 | 829 | } | ||
2371 | 830 | |||
2372 | 831 | cli_list(targetcli, targetpath, attribute, do_list_helper, NULL); | ||
2373 | 832 | remove_do_list_queue_head(); | ||
2374 | 833 | if ((! do_list_queue_empty()) && (fn == display_finfo)) { | ||
2375 | 834 | char *next_file = do_list_queue_head(); | ||
2376 | 835 | char *save_ch = 0; | ||
2377 | 836 | if ((strlen(next_file) >= 2) && | ||
2378 | 837 | (next_file[strlen(next_file) - 1] == '*') && | ||
2379 | 838 | (next_file[strlen(next_file) - 2] == CLI_DIRSEP_CHAR)) { | ||
2380 | 839 | save_ch = next_file + | ||
2381 | 840 | strlen(next_file) - 2; | ||
2382 | 841 | *save_ch = '\0'; | ||
2383 | 842 | if (showacls) { | ||
2384 | 843 | /* cwd is only used if showacls is on */ | ||
2385 | 844 | client_set_cwd(next_file); | ||
2386 | 845 | } | ||
2387 | 846 | } | ||
2388 | 847 | if (!showacls) /* don't disturbe the showacls output */ | ||
2389 | 848 | d_printf("\n%s\n",next_file); | ||
2390 | 849 | if (save_ch) { | ||
2391 | 850 | *save_ch = CLI_DIRSEP_CHAR; | ||
2392 | 851 | } | ||
2393 | 852 | } | ||
2394 | 853 | TALLOC_FREE(head); | ||
2395 | 854 | TALLOC_FREE(targetpath); | ||
2396 | 855 | } | ||
2397 | 856 | } else { | ||
2398 | 857 | /* check for dfs */ | ||
2399 | 858 | if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) { | ||
2400 | 859 | if (cli_list(targetcli, targetpath, attribute, do_list_helper, NULL) == -1) { | ||
2401 | 860 | d_printf("%s listing %s\n", | ||
2402 | 861 | cli_errstr(targetcli), targetpath); | ||
2403 | 862 | } | ||
2404 | 863 | TALLOC_FREE(targetpath); | ||
2405 | 864 | } else { | ||
2406 | 865 | d_printf("do_list: [%s] %s\n", mask, cli_errstr(cli)); | ||
2407 | 866 | } | ||
2408 | 867 | } | ||
2409 | 868 | |||
2410 | 869 | in_do_list = 0; | ||
2411 | 870 | reset_do_list_queue(); | ||
2412 | 871 | } | ||
2413 | 872 | |||
2414 | 873 | /**************************************************************************** | ||
2415 | 874 | Get a directory listing. | ||
2416 | 875 | ****************************************************************************/ | ||
2417 | 876 | |||
2418 | 877 | static int cmd_dir(void) | ||
2419 | 878 | { | ||
2420 | 879 | TALLOC_CTX *ctx = talloc_tos(); | ||
2421 | 880 | uint16 attribute = aDIR | aSYSTEM | aHIDDEN; | ||
2422 | 881 | char *mask = NULL; | ||
2423 | 882 | char *buf = NULL; | ||
2424 | 883 | int rc = 1; | ||
2425 | 884 | |||
2426 | 885 | dir_total = 0; | ||
2427 | 886 | mask = talloc_strdup(ctx, client_get_cur_dir()); | ||
2428 | 887 | if (!mask) { | ||
2429 | 888 | return 1; | ||
2430 | 889 | } | ||
2431 | 890 | |||
2432 | 891 | if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
2433 | 892 | normalize_name(buf); | ||
2434 | 893 | if (*buf == CLI_DIRSEP_CHAR) { | ||
2435 | 894 | mask = talloc_strdup(ctx, buf); | ||
2436 | 895 | } else { | ||
2437 | 896 | mask = talloc_asprintf_append(mask, "%s", buf); | ||
2438 | 897 | } | ||
2439 | 898 | } else { | ||
2440 | 899 | mask = talloc_asprintf_append(mask, "*"); | ||
2441 | 900 | } | ||
2442 | 901 | if (!mask) { | ||
2443 | 902 | return 1; | ||
2444 | 903 | } | ||
2445 | 904 | |||
2446 | 905 | if (showacls) { | ||
2447 | 906 | /* cwd is only used if showacls is on */ | ||
2448 | 907 | client_set_cwd(client_get_cur_dir()); | ||
2449 | 908 | } | ||
2450 | 909 | |||
2451 | 910 | do_list(mask, attribute, display_finfo, recurse, true); | ||
2452 | 911 | |||
2453 | 912 | rc = do_dskattr(); | ||
2454 | 913 | |||
2455 | 914 | DEBUG(3, ("Total bytes listed: %.0f\n", dir_total)); | ||
2456 | 915 | |||
2457 | 916 | return rc; | ||
2458 | 917 | } | ||
2459 | 918 | |||
2460 | 919 | /**************************************************************************** | ||
2461 | 920 | Get a directory listing. | ||
2462 | 921 | ****************************************************************************/ | ||
2463 | 922 | |||
2464 | 923 | static int cmd_du(void) | ||
2465 | 924 | { | ||
2466 | 925 | TALLOC_CTX *ctx = talloc_tos(); | ||
2467 | 926 | uint16 attribute = aDIR | aSYSTEM | aHIDDEN; | ||
2468 | 927 | char *mask = NULL; | ||
2469 | 928 | char *buf = NULL; | ||
2470 | 929 | int rc = 1; | ||
2471 | 930 | |||
2472 | 931 | dir_total = 0; | ||
2473 | 932 | mask = talloc_strdup(ctx, client_get_cur_dir()); | ||
2474 | 933 | if (!mask) { | ||
2475 | 934 | return 1; | ||
2476 | 935 | } | ||
2477 | 936 | if ((mask[0] != '\0') && (mask[strlen(mask)-1]!=CLI_DIRSEP_CHAR)) { | ||
2478 | 937 | mask = talloc_asprintf_append(mask, "%s", CLI_DIRSEP_STR); | ||
2479 | 938 | if (!mask) { | ||
2480 | 939 | return 1; | ||
2481 | 940 | } | ||
2482 | 941 | } | ||
2483 | 942 | |||
2484 | 943 | if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
2485 | 944 | normalize_name(buf); | ||
2486 | 945 | if (*buf == CLI_DIRSEP_CHAR) { | ||
2487 | 946 | mask = talloc_strdup(ctx, buf); | ||
2488 | 947 | } else { | ||
2489 | 948 | mask = talloc_asprintf_append(mask, "%s", buf); | ||
2490 | 949 | } | ||
2491 | 950 | } else { | ||
2492 | 951 | mask = talloc_strdup(ctx, "*"); | ||
2493 | 952 | } | ||
2494 | 953 | |||
2495 | 954 | do_list(mask, attribute, do_du, recurse, true); | ||
2496 | 955 | |||
2497 | 956 | rc = do_dskattr(); | ||
2498 | 957 | |||
2499 | 958 | d_printf("Total number of bytes: %.0f\n", dir_total); | ||
2500 | 959 | |||
2501 | 960 | return rc; | ||
2502 | 961 | } | ||
2503 | 962 | |||
2504 | 963 | static int cmd_echo(void) | ||
2505 | 964 | { | ||
2506 | 965 | TALLOC_CTX *ctx = talloc_tos(); | ||
2507 | 966 | char *num; | ||
2508 | 967 | char *data; | ||
2509 | 968 | NTSTATUS status; | ||
2510 | 969 | |||
2511 | 970 | if (!next_token_talloc(ctx, &cmd_ptr, &num, NULL) | ||
2512 | 971 | || !next_token_talloc(ctx, &cmd_ptr, &data, NULL)) { | ||
2513 | 972 | d_printf("echo <num> <data>\n"); | ||
2514 | 973 | return 1; | ||
2515 | 974 | } | ||
2516 | 975 | |||
2517 | 976 | status = cli_echo(cli, atoi(num), data_blob_const(data, strlen(data))); | ||
2518 | 977 | |||
2519 | 978 | if (!NT_STATUS_IS_OK(status)) { | ||
2520 | 979 | d_printf("echo failed: %s\n", nt_errstr(status)); | ||
2521 | 980 | return 1; | ||
2522 | 981 | } | ||
2523 | 982 | |||
2524 | 983 | return 0; | ||
2525 | 984 | } | ||
2526 | 985 | |||
2527 | 986 | /**************************************************************************** | ||
2528 | 987 | Get a file from rname to lname | ||
2529 | 988 | ****************************************************************************/ | ||
2530 | 989 | |||
2531 | 990 | static NTSTATUS writefile_sink(char *buf, size_t n, void *priv) | ||
2532 | 991 | { | ||
2533 | 992 | int *pfd = (int *)priv; | ||
2534 | 993 | if (writefile(*pfd, buf, n) == -1) { | ||
2535 | 994 | return map_nt_error_from_unix(errno); | ||
2536 | 995 | } | ||
2537 | 996 | return NT_STATUS_OK; | ||
2538 | 997 | } | ||
2539 | 998 | |||
2540 | 999 | static int do_get(const char *rname, const char *lname_in, bool reget) | ||
2541 | 1000 | { | ||
2542 | 1001 | TALLOC_CTX *ctx = talloc_tos(); | ||
2543 | 1002 | int handle = 0, fnum; | ||
2544 | 1003 | bool newhandle = false; | ||
2545 | 1004 | struct timeval tp_start; | ||
2546 | 1005 | uint16 attr; | ||
2547 | 1006 | SMB_OFF_T size; | ||
2548 | 1007 | off_t start = 0; | ||
2549 | 1008 | SMB_OFF_T nread = 0; | ||
2550 | 1009 | int rc = 0; | ||
2551 | 1010 | struct cli_state *targetcli = NULL; | ||
2552 | 1011 | char *targetname = NULL; | ||
2553 | 1012 | char *lname = NULL; | ||
2554 | 1013 | NTSTATUS status; | ||
2555 | 1014 | |||
2556 | 1015 | lname = talloc_strdup(ctx, lname_in); | ||
2557 | 1016 | if (!lname) { | ||
2558 | 1017 | return 1; | ||
2559 | 1018 | } | ||
2560 | 1019 | |||
2561 | 1020 | if (lowercase) { | ||
2562 | 1021 | strlower_m(lname); | ||
2563 | 1022 | } | ||
2564 | 1023 | |||
2565 | 1024 | if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname ) ) { | ||
2566 | 1025 | d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli)); | ||
2567 | 1026 | return 1; | ||
2568 | 1027 | } | ||
2569 | 1028 | |||
2570 | 1029 | GetTimeOfDay(&tp_start); | ||
2571 | 1030 | |||
2572 | 1031 | fnum = cli_open(targetcli, targetname, O_RDONLY, DENY_NONE); | ||
2573 | 1032 | |||
2574 | 1033 | if (fnum == -1) { | ||
2575 | 1034 | d_printf("%s opening remote file %s\n",cli_errstr(cli),rname); | ||
2576 | 1035 | return 1; | ||
2577 | 1036 | } | ||
2578 | 1037 | |||
2579 | 1038 | if(!strcmp(lname,"-")) { | ||
2580 | 1039 | handle = fileno(stdout); | ||
2581 | 1040 | } else { | ||
2582 | 1041 | if (reget) { | ||
2583 | 1042 | handle = sys_open(lname, O_WRONLY|O_CREAT, 0644); | ||
2584 | 1043 | if (handle >= 0) { | ||
2585 | 1044 | start = sys_lseek(handle, 0, SEEK_END); | ||
2586 | 1045 | if (start == -1) { | ||
2587 | 1046 | d_printf("Error seeking local file\n"); | ||
2588 | 1047 | return 1; | ||
2589 | 1048 | } | ||
2590 | 1049 | } | ||
2591 | 1050 | } else { | ||
2592 | 1051 | handle = sys_open(lname, O_WRONLY|O_CREAT|O_TRUNC, 0644); | ||
2593 | 1052 | } | ||
2594 | 1053 | newhandle = true; | ||
2595 | 1054 | } | ||
2596 | 1055 | if (handle < 0) { | ||
2597 | 1056 | d_printf("Error opening local file %s\n",lname); | ||
2598 | 1057 | return 1; | ||
2599 | 1058 | } | ||
2600 | 1059 | |||
2601 | 1060 | |||
2602 | 1061 | if (!cli_qfileinfo(targetcli, fnum, | ||
2603 | 1062 | &attr, &size, NULL, NULL, NULL, NULL, NULL) && | ||
2604 | 1063 | !cli_getattrE(targetcli, fnum, | ||
2605 | 1064 | &attr, &size, NULL, NULL, NULL)) { | ||
2606 | 1065 | d_printf("getattrib: %s\n",cli_errstr(targetcli)); | ||
2607 | 1066 | return 1; | ||
2608 | 1067 | } | ||
2609 | 1068 | |||
2610 | 1069 | DEBUG(1,("getting file %s of size %.0f as %s ", | ||
2611 | 1070 | rname, (double)size, lname)); | ||
2612 | 1071 | |||
2613 | 1072 | status = cli_pull(targetcli, fnum, start, size, io_bufsize, | ||
2614 | 1073 | writefile_sink, (void *)&handle, &nread); | ||
2615 | 1074 | if (!NT_STATUS_IS_OK(status)) { | ||
2616 | 1075 | d_fprintf(stderr, "parallel_read returned %s\n", | ||
2617 | 1076 | nt_errstr(status)); | ||
2618 | 1077 | cli_close(targetcli, fnum); | ||
2619 | 1078 | return 1; | ||
2620 | 1079 | } | ||
2621 | 1080 | |||
2622 | 1081 | if (!cli_close(targetcli, fnum)) { | ||
2623 | 1082 | d_printf("Error %s closing remote file\n",cli_errstr(cli)); | ||
2624 | 1083 | rc = 1; | ||
2625 | 1084 | } | ||
2626 | 1085 | |||
2627 | 1086 | if (newhandle) { | ||
2628 | 1087 | close(handle); | ||
2629 | 1088 | } | ||
2630 | 1089 | |||
2631 | 1090 | if (archive_level >= 2 && (attr & aARCH)) { | ||
2632 | 1091 | cli_setatr(cli, rname, attr & ~(uint16)aARCH, 0); | ||
2633 | 1092 | } | ||
2634 | 1093 | |||
2635 | 1094 | { | ||
2636 | 1095 | struct timeval tp_end; | ||
2637 | 1096 | int this_time; | ||
2638 | 1097 | |||
2639 | 1098 | GetTimeOfDay(&tp_end); | ||
2640 | 1099 | this_time = | ||
2641 | 1100 | (tp_end.tv_sec - tp_start.tv_sec)*1000 + | ||
2642 | 1101 | (tp_end.tv_usec - tp_start.tv_usec)/1000; | ||
2643 | 1102 | get_total_time_ms += this_time; | ||
2644 | 1103 | get_total_size += nread; | ||
2645 | 1104 | |||
2646 | 1105 | DEBUG(1,("(%3.1f KiloBytes/sec) (average %3.1f KiloBytes/sec)\n", | ||
2647 | 1106 | nread / (1.024*this_time + 1.0e-4), | ||
2648 | 1107 | get_total_size / (1.024*get_total_time_ms))); | ||
2649 | 1108 | } | ||
2650 | 1109 | |||
2651 | 1110 | TALLOC_FREE(targetname); | ||
2652 | 1111 | return rc; | ||
2653 | 1112 | } | ||
2654 | 1113 | |||
2655 | 1114 | /**************************************************************************** | ||
2656 | 1115 | Get a file. | ||
2657 | 1116 | ****************************************************************************/ | ||
2658 | 1117 | |||
2659 | 1118 | static int cmd_get(void) | ||
2660 | 1119 | { | ||
2661 | 1120 | TALLOC_CTX *ctx = talloc_tos(); | ||
2662 | 1121 | char *lname = NULL; | ||
2663 | 1122 | char *rname = NULL; | ||
2664 | 1123 | char *fname = NULL; | ||
2665 | 1124 | |||
2666 | 1125 | rname = talloc_strdup(ctx, client_get_cur_dir()); | ||
2667 | 1126 | if (!rname) { | ||
2668 | 1127 | return 1; | ||
2669 | 1128 | } | ||
2670 | 1129 | |||
2671 | 1130 | if (!next_token_talloc(ctx, &cmd_ptr,&fname,NULL)) { | ||
2672 | 1131 | d_printf("get <filename> [localname]\n"); | ||
2673 | 1132 | return 1; | ||
2674 | 1133 | } | ||
2675 | 1134 | rname = talloc_asprintf_append(rname, "%s", fname); | ||
2676 | 1135 | if (!rname) { | ||
2677 | 1136 | return 1; | ||
2678 | 1137 | } | ||
2679 | 1138 | rname = clean_name(ctx, rname); | ||
2680 | 1139 | if (!rname) { | ||
2681 | 1140 | return 1; | ||
2682 | 1141 | } | ||
2683 | 1142 | |||
2684 | 1143 | next_token_talloc(ctx, &cmd_ptr,&lname,NULL); | ||
2685 | 1144 | if (!lname) { | ||
2686 | 1145 | lname = fname; | ||
2687 | 1146 | } | ||
2688 | 1147 | |||
2689 | 1148 | return do_get(rname, lname, false); | ||
2690 | 1149 | } | ||
2691 | 1150 | |||
2692 | 1151 | /**************************************************************************** | ||
2693 | 1152 | Do an mget operation on one file. | ||
2694 | 1153 | ****************************************************************************/ | ||
2695 | 1154 | |||
2696 | 1155 | static void do_mget(file_info *finfo, const char *dir) | ||
2697 | 1156 | { | ||
2698 | 1157 | TALLOC_CTX *ctx = talloc_tos(); | ||
2699 | 1158 | char *rname = NULL; | ||
2700 | 1159 | char *quest = NULL; | ||
2701 | 1160 | char *saved_curdir = NULL; | ||
2702 | 1161 | char *mget_mask = NULL; | ||
2703 | 1162 | char *new_cd = NULL; | ||
2704 | 1163 | |||
2705 | 1164 | if (!finfo->name) { | ||
2706 | 1165 | return; | ||
2707 | 1166 | } | ||
2708 | 1167 | |||
2709 | 1168 | if (strequal(finfo->name,".") || strequal(finfo->name,"..")) | ||
2710 | 1169 | return; | ||
2711 | 1170 | |||
2712 | 1171 | if (abort_mget) { | ||
2713 | 1172 | d_printf("mget aborted\n"); | ||
2714 | 1173 | return; | ||
2715 | 1174 | } | ||
2716 | 1175 | |||
2717 | 1176 | if (finfo->mode & aDIR) { | ||
2718 | 1177 | if (asprintf(&quest, | ||
2719 | 1178 | "Get directory %s? ",finfo->name) < 0) { | ||
2720 | 1179 | return; | ||
2721 | 1180 | } | ||
2722 | 1181 | } else { | ||
2723 | 1182 | if (asprintf(&quest, | ||
2724 | 1183 | "Get file %s? ",finfo->name) < 0) { | ||
2725 | 1184 | return; | ||
2726 | 1185 | } | ||
2727 | 1186 | } | ||
2728 | 1187 | |||
2729 | 1188 | if (prompt && !yesno(quest)) { | ||
2730 | 1189 | SAFE_FREE(quest); | ||
2731 | 1190 | return; | ||
2732 | 1191 | } | ||
2733 | 1192 | SAFE_FREE(quest); | ||
2734 | 1193 | |||
2735 | 1194 | if (!(finfo->mode & aDIR)) { | ||
2736 | 1195 | rname = talloc_asprintf(ctx, | ||
2737 | 1196 | "%s%s", | ||
2738 | 1197 | client_get_cur_dir(), | ||
2739 | 1198 | finfo->name); | ||
2740 | 1199 | if (!rname) { | ||
2741 | 1200 | return; | ||
2742 | 1201 | } | ||
2743 | 1202 | do_get(rname, finfo->name, false); | ||
2744 | 1203 | TALLOC_FREE(rname); | ||
2745 | 1204 | return; | ||
2746 | 1205 | } | ||
2747 | 1206 | |||
2748 | 1207 | /* handle directories */ | ||
2749 | 1208 | saved_curdir = talloc_strdup(ctx, client_get_cur_dir()); | ||
2750 | 1209 | if (!saved_curdir) { | ||
2751 | 1210 | return; | ||
2752 | 1211 | } | ||
2753 | 1212 | |||
2754 | 1213 | new_cd = talloc_asprintf(ctx, | ||
2755 | 1214 | "%s%s%s", | ||
2756 | 1215 | client_get_cur_dir(), | ||
2757 | 1216 | finfo->name, | ||
2758 | 1217 | CLI_DIRSEP_STR); | ||
2759 | 1218 | if (!new_cd) { | ||
2760 | 1219 | return; | ||
2761 | 1220 | } | ||
2762 | 1221 | client_set_cur_dir(new_cd); | ||
2763 | 1222 | |||
2764 | 1223 | string_replace(finfo->name,'\\','/'); | ||
2765 | 1224 | if (lowercase) { | ||
2766 | 1225 | strlower_m(finfo->name); | ||
2767 | 1226 | } | ||
2768 | 1227 | |||
2769 | 1228 | if (!directory_exist(finfo->name) && | ||
2770 | 1229 | mkdir(finfo->name,0777) != 0) { | ||
2771 | 1230 | d_printf("failed to create directory %s\n",finfo->name); | ||
2772 | 1231 | client_set_cur_dir(saved_curdir); | ||
2773 | 1232 | return; | ||
2774 | 1233 | } | ||
2775 | 1234 | |||
2776 | 1235 | if (chdir(finfo->name) != 0) { | ||
2777 | 1236 | d_printf("failed to chdir to directory %s\n",finfo->name); | ||
2778 | 1237 | client_set_cur_dir(saved_curdir); | ||
2779 | 1238 | return; | ||
2780 | 1239 | } | ||
2781 | 1240 | |||
2782 | 1241 | mget_mask = talloc_asprintf(ctx, | ||
2783 | 1242 | "%s*", | ||
2784 | 1243 | client_get_cur_dir()); | ||
2785 | 1244 | |||
2786 | 1245 | if (!mget_mask) { | ||
2787 | 1246 | return; | ||
2788 | 1247 | } | ||
2789 | 1248 | |||
2790 | 1249 | do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true); | ||
2791 | 1250 | if (chdir("..") == -1) { | ||
2792 | 1251 | d_printf("do_mget: failed to chdir to .. (error %s)\n", | ||
2793 | 1252 | strerror(errno) ); | ||
2794 | 1253 | } | ||
2795 | 1254 | client_set_cur_dir(saved_curdir); | ||
2796 | 1255 | TALLOC_FREE(mget_mask); | ||
2797 | 1256 | TALLOC_FREE(saved_curdir); | ||
2798 | 1257 | TALLOC_FREE(new_cd); | ||
2799 | 1258 | } | ||
2800 | 1259 | |||
2801 | 1260 | /**************************************************************************** | ||
2802 | 1261 | View the file using the pager. | ||
2803 | 1262 | ****************************************************************************/ | ||
2804 | 1263 | |||
2805 | 1264 | static int cmd_more(void) | ||
2806 | 1265 | { | ||
2807 | 1266 | TALLOC_CTX *ctx = talloc_tos(); | ||
2808 | 1267 | char *rname = NULL; | ||
2809 | 1268 | char *fname = NULL; | ||
2810 | 1269 | char *lname = NULL; | ||
2811 | 1270 | char *pager_cmd = NULL; | ||
2812 | 1271 | const char *pager; | ||
2813 | 1272 | int fd; | ||
2814 | 1273 | int rc = 0; | ||
2815 | 1274 | |||
2816 | 1275 | rname = talloc_strdup(ctx, client_get_cur_dir()); | ||
2817 | 1276 | if (!rname) { | ||
2818 | 1277 | return 1; | ||
2819 | 1278 | } | ||
2820 | 1279 | |||
2821 | 1280 | lname = talloc_asprintf(ctx, "%s/smbmore.XXXXXX",tmpdir()); | ||
2822 | 1281 | if (!lname) { | ||
2823 | 1282 | return 1; | ||
2824 | 1283 | } | ||
2825 | 1284 | fd = smb_mkstemp(lname); | ||
2826 | 1285 | if (fd == -1) { | ||
2827 | 1286 | d_printf("failed to create temporary file for more\n"); | ||
2828 | 1287 | return 1; | ||
2829 | 1288 | } | ||
2830 | 1289 | close(fd); | ||
2831 | 1290 | |||
2832 | 1291 | if (!next_token_talloc(ctx, &cmd_ptr,&fname,NULL)) { | ||
2833 | 1292 | d_printf("more <filename>\n"); | ||
2834 | 1293 | unlink(lname); | ||
2835 | 1294 | return 1; | ||
2836 | 1295 | } | ||
2837 | 1296 | rname = talloc_asprintf_append(rname, "%s", fname); | ||
2838 | 1297 | if (!rname) { | ||
2839 | 1298 | return 1; | ||
2840 | 1299 | } | ||
2841 | 1300 | rname = clean_name(ctx,rname); | ||
2842 | 1301 | if (!rname) { | ||
2843 | 1302 | return 1; | ||
2844 | 1303 | } | ||
2845 | 1304 | |||
2846 | 1305 | rc = do_get(rname, lname, false); | ||
2847 | 1306 | |||
2848 | 1307 | pager=getenv("PAGER"); | ||
2849 | 1308 | |||
2850 | 1309 | pager_cmd = talloc_asprintf(ctx, | ||
2851 | 1310 | "%s %s", | ||
2852 | 1311 | (pager? pager:PAGER), | ||
2853 | 1312 | lname); | ||
2854 | 1313 | if (!pager_cmd) { | ||
2855 | 1314 | return 1; | ||
2856 | 1315 | } | ||
2857 | 1316 | if (system(pager_cmd) == -1) { | ||
2858 | 1317 | d_printf("system command '%s' returned -1\n", | ||
2859 | 1318 | pager_cmd); | ||
2860 | 1319 | } | ||
2861 | 1320 | unlink(lname); | ||
2862 | 1321 | |||
2863 | 1322 | return rc; | ||
2864 | 1323 | } | ||
2865 | 1324 | |||
2866 | 1325 | /**************************************************************************** | ||
2867 | 1326 | Do a mget command. | ||
2868 | 1327 | ****************************************************************************/ | ||
2869 | 1328 | |||
2870 | 1329 | static int cmd_mget(void) | ||
2871 | 1330 | { | ||
2872 | 1331 | TALLOC_CTX *ctx = talloc_tos(); | ||
2873 | 1332 | uint16 attribute = aSYSTEM | aHIDDEN; | ||
2874 | 1333 | char *mget_mask = NULL; | ||
2875 | 1334 | char *buf = NULL; | ||
2876 | 1335 | |||
2877 | 1336 | if (recurse) { | ||
2878 | 1337 | attribute |= aDIR; | ||
2879 | 1338 | } | ||
2880 | 1339 | |||
2881 | 1340 | abort_mget = false; | ||
2882 | 1341 | |||
2883 | 1342 | while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
2884 | 1343 | mget_mask = talloc_strdup(ctx, client_get_cur_dir()); | ||
2885 | 1344 | if (!mget_mask) { | ||
2886 | 1345 | return 1; | ||
2887 | 1346 | } | ||
2888 | 1347 | if (*buf == CLI_DIRSEP_CHAR) { | ||
2889 | 1348 | mget_mask = talloc_strdup(ctx, buf); | ||
2890 | 1349 | } else { | ||
2891 | 1350 | mget_mask = talloc_asprintf_append(mget_mask, | ||
2892 | 1351 | "%s", buf); | ||
2893 | 1352 | } | ||
2894 | 1353 | if (!mget_mask) { | ||
2895 | 1354 | return 1; | ||
2896 | 1355 | } | ||
2897 | 1356 | do_list(mget_mask, attribute, do_mget, false, true); | ||
2898 | 1357 | } | ||
2899 | 1358 | |||
2900 | 1359 | if (mget_mask == NULL) { | ||
2901 | 1360 | d_printf("nothing to mget\n"); | ||
2902 | 1361 | return 0; | ||
2903 | 1362 | } | ||
2904 | 1363 | |||
2905 | 1364 | if (!*mget_mask) { | ||
2906 | 1365 | mget_mask = talloc_asprintf(ctx, | ||
2907 | 1366 | "%s*", | ||
2908 | 1367 | client_get_cur_dir()); | ||
2909 | 1368 | if (!mget_mask) { | ||
2910 | 1369 | return 1; | ||
2911 | 1370 | } | ||
2912 | 1371 | do_list(mget_mask, attribute, do_mget, false, true); | ||
2913 | 1372 | } | ||
2914 | 1373 | |||
2915 | 1374 | return 0; | ||
2916 | 1375 | } | ||
2917 | 1376 | |||
2918 | 1377 | /**************************************************************************** | ||
2919 | 1378 | Make a directory of name "name". | ||
2920 | 1379 | ****************************************************************************/ | ||
2921 | 1380 | |||
2922 | 1381 | static bool do_mkdir(const char *name) | ||
2923 | 1382 | { | ||
2924 | 1383 | TALLOC_CTX *ctx = talloc_tos(); | ||
2925 | 1384 | struct cli_state *targetcli; | ||
2926 | 1385 | char *targetname = NULL; | ||
2927 | 1386 | |||
2928 | 1387 | if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) { | ||
2929 | 1388 | d_printf("mkdir %s: %s\n", name, cli_errstr(cli)); | ||
2930 | 1389 | return false; | ||
2931 | 1390 | } | ||
2932 | 1391 | |||
2933 | 1392 | if (!cli_mkdir(targetcli, targetname)) { | ||
2934 | 1393 | d_printf("%s making remote directory %s\n", | ||
2935 | 1394 | cli_errstr(targetcli),name); | ||
2936 | 1395 | return false; | ||
2937 | 1396 | } | ||
2938 | 1397 | |||
2939 | 1398 | return true; | ||
2940 | 1399 | } | ||
2941 | 1400 | |||
2942 | 1401 | /**************************************************************************** | ||
2943 | 1402 | Show 8.3 name of a file. | ||
2944 | 1403 | ****************************************************************************/ | ||
2945 | 1404 | |||
2946 | 1405 | static bool do_altname(const char *name) | ||
2947 | 1406 | { | ||
2948 | 1407 | fstring altname; | ||
2949 | 1408 | |||
2950 | 1409 | if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) { | ||
2951 | 1410 | d_printf("%s getting alt name for %s\n", | ||
2952 | 1411 | cli_errstr(cli),name); | ||
2953 | 1412 | return false; | ||
2954 | 1413 | } | ||
2955 | 1414 | d_printf("%s\n", altname); | ||
2956 | 1415 | |||
2957 | 1416 | return true; | ||
2958 | 1417 | } | ||
2959 | 1418 | |||
2960 | 1419 | /**************************************************************************** | ||
2961 | 1420 | Exit client. | ||
2962 | 1421 | ****************************************************************************/ | ||
2963 | 1422 | |||
2964 | 1423 | static int cmd_quit(void) | ||
2965 | 1424 | { | ||
2966 | 1425 | cli_shutdown(cli); | ||
2967 | 1426 | exit(0); | ||
2968 | 1427 | /* NOTREACHED */ | ||
2969 | 1428 | return 0; | ||
2970 | 1429 | } | ||
2971 | 1430 | |||
2972 | 1431 | /**************************************************************************** | ||
2973 | 1432 | Make a directory. | ||
2974 | 1433 | ****************************************************************************/ | ||
2975 | 1434 | |||
2976 | 1435 | static int cmd_mkdir(void) | ||
2977 | 1436 | { | ||
2978 | 1437 | TALLOC_CTX *ctx = talloc_tos(); | ||
2979 | 1438 | char *mask = NULL; | ||
2980 | 1439 | char *buf = NULL; | ||
2981 | 1440 | |||
2982 | 1441 | mask = talloc_strdup(ctx, client_get_cur_dir()); | ||
2983 | 1442 | if (!mask) { | ||
2984 | 1443 | return 1; | ||
2985 | 1444 | } | ||
2986 | 1445 | |||
2987 | 1446 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
2988 | 1447 | if (!recurse) { | ||
2989 | 1448 | d_printf("mkdir <dirname>\n"); | ||
2990 | 1449 | } | ||
2991 | 1450 | return 1; | ||
2992 | 1451 | } | ||
2993 | 1452 | mask = talloc_asprintf_append(mask, "%s", buf); | ||
2994 | 1453 | if (!mask) { | ||
2995 | 1454 | return 1; | ||
2996 | 1455 | } | ||
2997 | 1456 | |||
2998 | 1457 | if (recurse) { | ||
2999 | 1458 | char *ddir = NULL; | ||
3000 | 1459 | char *ddir2 = NULL; | ||
3001 | 1460 | struct cli_state *targetcli; | ||
3002 | 1461 | char *targetname = NULL; | ||
3003 | 1462 | char *p = NULL; | ||
3004 | 1463 | char *saveptr; | ||
3005 | 1464 | |||
3006 | 1465 | ddir2 = talloc_strdup(ctx, ""); | ||
3007 | 1466 | if (!ddir2) { | ||
3008 | 1467 | return 1; | ||
3009 | 1468 | } | ||
3010 | 1469 | |||
3011 | 1470 | if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { | ||
3012 | 1471 | return 1; | ||
3013 | 1472 | } | ||
3014 | 1473 | |||
3015 | 1474 | ddir = talloc_strdup(ctx, targetname); | ||
3016 | 1475 | if (!ddir) { | ||
3017 | 1476 | return 1; | ||
3018 | 1477 | } | ||
3019 | 1478 | trim_char(ddir,'.','\0'); | ||
3020 | 1479 | p = strtok_r(ddir, "/\\", &saveptr); | ||
3021 | 1480 | while (p) { | ||
3022 | 1481 | ddir2 = talloc_asprintf_append(ddir2, "%s", p); | ||
3023 | 1482 | if (!ddir2) { | ||
3024 | 1483 | return 1; | ||
3025 | 1484 | } | ||
3026 | 1485 | if (!cli_chkpath(targetcli, ddir2)) { | ||
3027 | 1486 | do_mkdir(ddir2); | ||
3028 | 1487 | } | ||
3029 | 1488 | ddir2 = talloc_asprintf_append(ddir2, "%s", CLI_DIRSEP_STR); | ||
3030 | 1489 | if (!ddir2) { | ||
3031 | 1490 | return 1; | ||
3032 | 1491 | } | ||
3033 | 1492 | p = strtok_r(NULL, "/\\", &saveptr); | ||
3034 | 1493 | } | ||
3035 | 1494 | } else { | ||
3036 | 1495 | do_mkdir(mask); | ||
3037 | 1496 | } | ||
3038 | 1497 | |||
3039 | 1498 | return 0; | ||
3040 | 1499 | } | ||
3041 | 1500 | |||
3042 | 1501 | /**************************************************************************** | ||
3043 | 1502 | Show alt name. | ||
3044 | 1503 | ****************************************************************************/ | ||
3045 | 1504 | |||
3046 | 1505 | static int cmd_altname(void) | ||
3047 | 1506 | { | ||
3048 | 1507 | TALLOC_CTX *ctx = talloc_tos(); | ||
3049 | 1508 | char *name; | ||
3050 | 1509 | char *buf; | ||
3051 | 1510 | |||
3052 | 1511 | name = talloc_strdup(ctx, client_get_cur_dir()); | ||
3053 | 1512 | if (!name) { | ||
3054 | 1513 | return 1; | ||
3055 | 1514 | } | ||
3056 | 1515 | |||
3057 | 1516 | if (!next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { | ||
3058 | 1517 | d_printf("altname <file>\n"); | ||
3059 | 1518 | return 1; | ||
3060 | 1519 | } | ||
3061 | 1520 | name = talloc_asprintf_append(name, "%s", buf); | ||
3062 | 1521 | if (!name) { | ||
3063 | 1522 | return 1; | ||
3064 | 1523 | } | ||
3065 | 1524 | do_altname(name); | ||
3066 | 1525 | return 0; | ||
3067 | 1526 | } | ||
3068 | 1527 | |||
3069 | 1528 | /**************************************************************************** | ||
3070 | 1529 | Show all info we can get | ||
3071 | 1530 | ****************************************************************************/ | ||
3072 | 1531 | |||
3073 | 1532 | static int do_allinfo(const char *name) | ||
3074 | 1533 | { | ||
3075 | 1534 | fstring altname; | ||
3076 | 1535 | struct timespec b_time, a_time, m_time, c_time; | ||
3077 | 1536 | SMB_OFF_T size; | ||
3078 | 1537 | uint16_t mode; | ||
3079 | 1538 | SMB_INO_T ino; | ||
3080 | 1539 | NTTIME tmp; | ||
3081 | 1540 | unsigned int num_streams; | ||
3082 | 1541 | struct stream_struct *streams; | ||
3083 | 1542 | unsigned int i; | ||
3084 | 1543 | |||
3085 | 1544 | if (!NT_STATUS_IS_OK(cli_qpathinfo_alt_name(cli, name, altname))) { | ||
3086 | 1545 | d_printf("%s getting alt name for %s\n", | ||
3087 | 1546 | cli_errstr(cli),name); | ||
3088 | 1547 | return false; | ||
3089 | 1548 | } | ||
3090 | 1549 | d_printf("altname: %s\n", altname); | ||
3091 | 1550 | |||
3092 | 1551 | if (!cli_qpathinfo2(cli, name, &b_time, &a_time, &m_time, &c_time, | ||
3093 | 1552 | &size, &mode, &ino)) { | ||
3094 | 1553 | d_printf("%s getting pathinfo for %s\n", | ||
3095 | 1554 | cli_errstr(cli),name); | ||
3096 | 1555 | return false; | ||
3097 | 1556 | } | ||
3098 | 1557 | |||
3099 | 1558 | unix_timespec_to_nt_time(&tmp, b_time); | ||
3100 | 1559 | d_printf("create_time: %s\n", nt_time_string(talloc_tos(), tmp)); | ||
3101 | 1560 | |||
3102 | 1561 | unix_timespec_to_nt_time(&tmp, a_time); | ||
3103 | 1562 | d_printf("access_time: %s\n", nt_time_string(talloc_tos(), tmp)); | ||
3104 | 1563 | |||
3105 | 1564 | unix_timespec_to_nt_time(&tmp, m_time); | ||
3106 | 1565 | d_printf("write_time: %s\n", nt_time_string(talloc_tos(), tmp)); | ||
3107 | 1566 | |||
3108 | 1567 | unix_timespec_to_nt_time(&tmp, c_time); | ||
3109 | 1568 | d_printf("change_time: %s\n", nt_time_string(talloc_tos(), tmp)); | ||
3110 | 1569 | |||
3111 | 1570 | if (!cli_qpathinfo_streams(cli, name, talloc_tos(), &num_streams, | ||
3112 | 1571 | &streams)) { | ||
3113 | 1572 | d_printf("%s getting streams for %s\n", | ||
3114 | 1573 | cli_errstr(cli),name); | ||
3115 | 1574 | return false; | ||
3116 | 1575 | } | ||
3117 | 1576 | |||
3118 | 1577 | for (i=0; i<num_streams; i++) { | ||
3119 | 1578 | d_printf("stream: [%s], %lld bytes\n", streams[i].name, | ||
3120 | 1579 | (unsigned long long)streams[i].size); | ||
3121 | 1580 | } | ||
3122 | 1581 | |||
3123 | 1582 | return 0; | ||
3124 | 1583 | } | ||
3125 | 1584 | |||
3126 | 1585 | /**************************************************************************** | ||
3127 | 1586 | Show all info we can get | ||
3128 | 1587 | ****************************************************************************/ | ||
3129 | 1588 | |||
3130 | 1589 | static int cmd_allinfo(void) | ||
3131 | 1590 | { | ||
3132 | 1591 | TALLOC_CTX *ctx = talloc_tos(); | ||
3133 | 1592 | char *name; | ||
3134 | 1593 | char *buf; | ||
3135 | 1594 | |||
3136 | 1595 | name = talloc_strdup(ctx, client_get_cur_dir()); | ||
3137 | 1596 | if (!name) { | ||
3138 | 1597 | return 1; | ||
3139 | 1598 | } | ||
3140 | 1599 | |||
3141 | 1600 | if (!next_token_talloc(ctx, &cmd_ptr, &buf, NULL)) { | ||
3142 | 1601 | d_printf("allinfo <file>\n"); | ||
3143 | 1602 | return 1; | ||
3144 | 1603 | } | ||
3145 | 1604 | name = talloc_asprintf_append(name, "%s", buf); | ||
3146 | 1605 | if (!name) { | ||
3147 | 1606 | return 1; | ||
3148 | 1607 | } | ||
3149 | 1608 | |||
3150 | 1609 | do_allinfo(name); | ||
3151 | 1610 | |||
3152 | 1611 | return 0; | ||
3153 | 1612 | } | ||
3154 | 1613 | |||
3155 | 1614 | /**************************************************************************** | ||
3156 | 1615 | Put a single file. | ||
3157 | 1616 | ****************************************************************************/ | ||
3158 | 1617 | |||
3159 | 1618 | static int do_put(const char *rname, const char *lname, bool reput) | ||
3160 | 1619 | { | ||
3161 | 1620 | TALLOC_CTX *ctx = talloc_tos(); | ||
3162 | 1621 | int fnum; | ||
3163 | 1622 | XFILE *f; | ||
3164 | 1623 | SMB_OFF_T start = 0; | ||
3165 | 1624 | int rc = 0; | ||
3166 | 1625 | struct timeval tp_start; | ||
3167 | 1626 | struct cli_state *targetcli; | ||
3168 | 1627 | char *targetname = NULL; | ||
3169 | 1628 | struct push_state state; | ||
3170 | 1629 | NTSTATUS status; | ||
3171 | 1630 | |||
3172 | 1631 | if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname)) { | ||
3173 | 1632 | d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli)); | ||
3174 | 1633 | return 1; | ||
3175 | 1634 | } | ||
3176 | 1635 | |||
3177 | 1636 | GetTimeOfDay(&tp_start); | ||
3178 | 1637 | |||
3179 | 1638 | if (reput) { | ||
3180 | 1639 | fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT, DENY_NONE); | ||
3181 | 1640 | if (fnum >= 0) { | ||
3182 | 1641 | if (!cli_qfileinfo(targetcli, fnum, NULL, &start, NULL, NULL, NULL, NULL, NULL) && | ||
3183 | 1642 | !cli_getattrE(targetcli, fnum, NULL, &start, NULL, NULL, NULL)) { | ||
3184 | 1643 | d_printf("getattrib: %s\n",cli_errstr(cli)); | ||
3185 | 1644 | return 1; | ||
3186 | 1645 | } | ||
3187 | 1646 | } | ||
3188 | 1647 | } else { | ||
3189 | 1648 | fnum = cli_open(targetcli, targetname, O_RDWR|O_CREAT|O_TRUNC, DENY_NONE); | ||
3190 | 1649 | } | ||
3191 | 1650 | |||
3192 | 1651 | if (fnum == -1) { | ||
3193 | 1652 | d_printf("%s opening remote file %s\n",cli_errstr(targetcli),rname); | ||
3194 | 1653 | return 1; | ||
3195 | 1654 | } | ||
3196 | 1655 | |||
3197 | 1656 | /* allow files to be piped into smbclient | ||
3198 | 1657 | jdblair 24.jun.98 | ||
3199 | 1658 | |||
3200 | 1659 | Note that in this case this function will exit(0) rather | ||
3201 | 1660 | than returning. */ | ||
3202 | 1661 | if (!strcmp(lname, "-")) { | ||
3203 | 1662 | f = x_stdin; | ||
3204 | 1663 | /* size of file is not known */ | ||
3205 | 1664 | } else { | ||
3206 | 1665 | f = x_fopen(lname,O_RDONLY, 0); | ||
3207 | 1666 | if (f && reput) { | ||
3208 | 1667 | if (x_tseek(f, start, SEEK_SET) == -1) { | ||
3209 | 1668 | d_printf("Error seeking local file\n"); | ||
3210 | 1669 | return 1; | ||
3211 | 1670 | } | ||
3212 | 1671 | } | ||
3213 | 1672 | } | ||
3214 | 1673 | |||
3215 | 1674 | if (!f) { | ||
3216 | 1675 | d_printf("Error opening local file %s\n",lname); | ||
3217 | 1676 | return 1; | ||
3218 | 1677 | } | ||
3219 | 1678 | |||
3220 | 1679 | DEBUG(1,("putting file %s as %s ",lname, | ||
3221 | 1680 | rname)); | ||
3222 | 1681 | |||
3223 | 1682 | x_setvbuf(f, NULL, X_IOFBF, io_bufsize); | ||
3224 | 1683 | |||
3225 | 1684 | state.f = f; | ||
3226 | 1685 | state.nread = 0; | ||
3227 | 1686 | |||
3228 | 1687 | status = cli_push(targetcli, fnum, 0, 0, io_bufsize, push_source, | ||
3229 | 1688 | &state); | ||
3230 | 1689 | if (!NT_STATUS_IS_OK(status)) { | ||
3231 | 1690 | d_fprintf(stderr, "cli_push returned %s\n", nt_errstr(status)); | ||
3232 | 1691 | } | ||
3233 | 1692 | |||
3234 | 1693 | if (!cli_close(targetcli, fnum)) { | ||
3235 | 1694 | d_printf("%s closing remote file %s\n",cli_errstr(cli),rname); | ||
3236 | 1695 | x_fclose(f); | ||
3237 | 1696 | return 1; | ||
3238 | 1697 | } | ||
3239 | 1698 | |||
3240 | 1699 | if (f != x_stdin) { | ||
3241 | 1700 | x_fclose(f); | ||
3242 | 1701 | } | ||
3243 | 1702 | |||
3244 | 1703 | { | ||
3245 | 1704 | struct timeval tp_end; | ||
3246 | 1705 | int this_time; | ||
3247 | 1706 | |||
3248 | 1707 | GetTimeOfDay(&tp_end); | ||
3249 | 1708 | this_time = | ||
3250 | 1709 | (tp_end.tv_sec - tp_start.tv_sec)*1000 + | ||
3251 | 1710 | (tp_end.tv_usec - tp_start.tv_usec)/1000; | ||
3252 | 1711 | put_total_time_ms += this_time; | ||
3253 | 1712 | put_total_size += state.nread; | ||
3254 | 1713 | |||
3255 | 1714 | DEBUG(1,("(%3.1f kb/s) (average %3.1f kb/s)\n", | ||
3256 | 1715 | state.nread / (1.024*this_time + 1.0e-4), | ||
3257 | 1716 | put_total_size / (1.024*put_total_time_ms))); | ||
3258 | 1717 | } | ||
3259 | 1718 | |||
3260 | 1719 | if (f == x_stdin) { | ||
3261 | 1720 | cli_shutdown(cli); | ||
3262 | 1721 | exit(0); | ||
3263 | 1722 | } | ||
3264 | 1723 | |||
3265 | 1724 | return rc; | ||
3266 | 1725 | } | ||
3267 | 1726 | |||
3268 | 1727 | /**************************************************************************** | ||
3269 | 1728 | Put a file. | ||
3270 | 1729 | ****************************************************************************/ | ||
3271 | 1730 | |||
3272 | 1731 | static int cmd_put(void) | ||
3273 | 1732 | { | ||
3274 | 1733 | TALLOC_CTX *ctx = talloc_tos(); | ||
3275 | 1734 | char *lname; | ||
3276 | 1735 | char *rname; | ||
3277 | 1736 | char *buf; | ||
3278 | 1737 | |||
3279 | 1738 | rname = talloc_strdup(ctx, client_get_cur_dir()); | ||
3280 | 1739 | if (!rname) { | ||
3281 | 1740 | return 1; | ||
3282 | 1741 | } | ||
3283 | 1742 | |||
3284 | 1743 | if (!next_token_talloc(ctx, &cmd_ptr,&lname,NULL)) { | ||
3285 | 1744 | d_printf("put <filename>\n"); | ||
3286 | 1745 | return 1; | ||
3287 | 1746 | } | ||
3288 | 1747 | |||
3289 | 1748 | if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3290 | 1749 | rname = talloc_asprintf_append(rname, "%s", buf); | ||
3291 | 1750 | } else { | ||
3292 | 1751 | rname = talloc_asprintf_append(rname, "%s", lname); | ||
3293 | 1752 | } | ||
3294 | 1753 | if (!rname) { | ||
3295 | 1754 | return 1; | ||
3296 | 1755 | } | ||
3297 | 1756 | |||
3298 | 1757 | rname = clean_name(ctx, rname); | ||
3299 | 1758 | if (!rname) { | ||
3300 | 1759 | return 1; | ||
3301 | 1760 | } | ||
3302 | 1761 | |||
3303 | 1762 | { | ||
3304 | 1763 | SMB_STRUCT_STAT st; | ||
3305 | 1764 | /* allow '-' to represent stdin | ||
3306 | 1765 | jdblair, 24.jun.98 */ | ||
3307 | 1766 | if (!file_exist_stat(lname,&st) && | ||
3308 | 1767 | (strcmp(lname,"-"))) { | ||
3309 | 1768 | d_printf("%s does not exist\n",lname); | ||
3310 | 1769 | return 1; | ||
3311 | 1770 | } | ||
3312 | 1771 | } | ||
3313 | 1772 | |||
3314 | 1773 | return do_put(rname, lname, false); | ||
3315 | 1774 | } | ||
3316 | 1775 | |||
3317 | 1776 | /************************************* | ||
3318 | 1777 | File list structure. | ||
3319 | 1778 | *************************************/ | ||
3320 | 1779 | |||
3321 | 1780 | static struct file_list { | ||
3322 | 1781 | struct file_list *prev, *next; | ||
3323 | 1782 | char *file_path; | ||
3324 | 1783 | bool isdir; | ||
3325 | 1784 | } *file_list; | ||
3326 | 1785 | |||
3327 | 1786 | /**************************************************************************** | ||
3328 | 1787 | Free a file_list structure. | ||
3329 | 1788 | ****************************************************************************/ | ||
3330 | 1789 | |||
3331 | 1790 | static void free_file_list (struct file_list *l_head) | ||
3332 | 1791 | { | ||
3333 | 1792 | struct file_list *list, *next; | ||
3334 | 1793 | |||
3335 | 1794 | for (list = l_head; list; list = next) { | ||
3336 | 1795 | next = list->next; | ||
3337 | 1796 | DLIST_REMOVE(l_head, list); | ||
3338 | 1797 | SAFE_FREE(list->file_path); | ||
3339 | 1798 | SAFE_FREE(list); | ||
3340 | 1799 | } | ||
3341 | 1800 | } | ||
3342 | 1801 | |||
3343 | 1802 | /**************************************************************************** | ||
3344 | 1803 | Seek in a directory/file list until you get something that doesn't start with | ||
3345 | 1804 | the specified name. | ||
3346 | 1805 | ****************************************************************************/ | ||
3347 | 1806 | |||
3348 | 1807 | static bool seek_list(struct file_list *list, char *name) | ||
3349 | 1808 | { | ||
3350 | 1809 | while (list) { | ||
3351 | 1810 | trim_string(list->file_path,"./","\n"); | ||
3352 | 1811 | if (strncmp(list->file_path, name, strlen(name)) != 0) { | ||
3353 | 1812 | return true; | ||
3354 | 1813 | } | ||
3355 | 1814 | list = list->next; | ||
3356 | 1815 | } | ||
3357 | 1816 | |||
3358 | 1817 | return false; | ||
3359 | 1818 | } | ||
3360 | 1819 | |||
3361 | 1820 | /**************************************************************************** | ||
3362 | 1821 | Set the file selection mask. | ||
3363 | 1822 | ****************************************************************************/ | ||
3364 | 1823 | |||
3365 | 1824 | static int cmd_select(void) | ||
3366 | 1825 | { | ||
3367 | 1826 | TALLOC_CTX *ctx = talloc_tos(); | ||
3368 | 1827 | char *new_fs = NULL; | ||
3369 | 1828 | next_token_talloc(ctx, &cmd_ptr,&new_fs,NULL) | ||
3370 | 1829 | ; | ||
3371 | 1830 | if (new_fs) { | ||
3372 | 1831 | client_set_fileselection(new_fs); | ||
3373 | 1832 | } else { | ||
3374 | 1833 | client_set_fileselection(""); | ||
3375 | 1834 | } | ||
3376 | 1835 | return 0; | ||
3377 | 1836 | } | ||
3378 | 1837 | |||
3379 | 1838 | /**************************************************************************** | ||
3380 | 1839 | Recursive file matching function act as find | ||
3381 | 1840 | match must be always set to true when calling this function | ||
3382 | 1841 | ****************************************************************************/ | ||
3383 | 1842 | |||
3384 | 1843 | static int file_find(struct file_list **list, const char *directory, | ||
3385 | 1844 | const char *expression, bool match) | ||
3386 | 1845 | { | ||
3387 | 1846 | SMB_STRUCT_DIR *dir; | ||
3388 | 1847 | struct file_list *entry; | ||
3389 | 1848 | struct stat statbuf; | ||
3390 | 1849 | int ret; | ||
3391 | 1850 | char *path; | ||
3392 | 1851 | bool isdir; | ||
3393 | 1852 | const char *dname; | ||
3394 | 1853 | |||
3395 | 1854 | dir = sys_opendir(directory); | ||
3396 | 1855 | if (!dir) | ||
3397 | 1856 | return -1; | ||
3398 | 1857 | |||
3399 | 1858 | while ((dname = readdirname(dir))) { | ||
3400 | 1859 | if (!strcmp("..", dname)) | ||
3401 | 1860 | continue; | ||
3402 | 1861 | if (!strcmp(".", dname)) | ||
3403 | 1862 | continue; | ||
3404 | 1863 | |||
3405 | 1864 | if (asprintf(&path, "%s/%s", directory, dname) <= 0) { | ||
3406 | 1865 | continue; | ||
3407 | 1866 | } | ||
3408 | 1867 | |||
3409 | 1868 | isdir = false; | ||
3410 | 1869 | if (!match || !gen_fnmatch(expression, dname)) { | ||
3411 | 1870 | if (recurse) { | ||
3412 | 1871 | ret = stat(path, &statbuf); | ||
3413 | 1872 | if (ret == 0) { | ||
3414 | 1873 | if (S_ISDIR(statbuf.st_mode)) { | ||
3415 | 1874 | isdir = true; | ||
3416 | 1875 | ret = file_find(list, path, expression, false); | ||
3417 | 1876 | } | ||
3418 | 1877 | } else { | ||
3419 | 1878 | d_printf("file_find: cannot stat file %s\n", path); | ||
3420 | 1879 | } | ||
3421 | 1880 | |||
3422 | 1881 | if (ret == -1) { | ||
3423 | 1882 | SAFE_FREE(path); | ||
3424 | 1883 | sys_closedir(dir); | ||
3425 | 1884 | return -1; | ||
3426 | 1885 | } | ||
3427 | 1886 | } | ||
3428 | 1887 | entry = SMB_MALLOC_P(struct file_list); | ||
3429 | 1888 | if (!entry) { | ||
3430 | 1889 | d_printf("Out of memory in file_find\n"); | ||
3431 | 1890 | sys_closedir(dir); | ||
3432 | 1891 | return -1; | ||
3433 | 1892 | } | ||
3434 | 1893 | entry->file_path = path; | ||
3435 | 1894 | entry->isdir = isdir; | ||
3436 | 1895 | DLIST_ADD(*list, entry); | ||
3437 | 1896 | } else { | ||
3438 | 1897 | SAFE_FREE(path); | ||
3439 | 1898 | } | ||
3440 | 1899 | } | ||
3441 | 1900 | |||
3442 | 1901 | sys_closedir(dir); | ||
3443 | 1902 | return 0; | ||
3444 | 1903 | } | ||
3445 | 1904 | |||
3446 | 1905 | /**************************************************************************** | ||
3447 | 1906 | mput some files. | ||
3448 | 1907 | ****************************************************************************/ | ||
3449 | 1908 | |||
3450 | 1909 | static int cmd_mput(void) | ||
3451 | 1910 | { | ||
3452 | 1911 | TALLOC_CTX *ctx = talloc_tos(); | ||
3453 | 1912 | char *p = NULL; | ||
3454 | 1913 | |||
3455 | 1914 | while (next_token_talloc(ctx, &cmd_ptr,&p,NULL)) { | ||
3456 | 1915 | int ret; | ||
3457 | 1916 | struct file_list *temp_list; | ||
3458 | 1917 | char *quest, *lname, *rname; | ||
3459 | 1918 | |||
3460 | 1919 | file_list = NULL; | ||
3461 | 1920 | |||
3462 | 1921 | ret = file_find(&file_list, ".", p, true); | ||
3463 | 1922 | if (ret) { | ||
3464 | 1923 | free_file_list(file_list); | ||
3465 | 1924 | continue; | ||
3466 | 1925 | } | ||
3467 | 1926 | |||
3468 | 1927 | quest = NULL; | ||
3469 | 1928 | lname = NULL; | ||
3470 | 1929 | rname = NULL; | ||
3471 | 1930 | |||
3472 | 1931 | for (temp_list = file_list; temp_list; | ||
3473 | 1932 | temp_list = temp_list->next) { | ||
3474 | 1933 | |||
3475 | 1934 | SAFE_FREE(lname); | ||
3476 | 1935 | if (asprintf(&lname, "%s/", temp_list->file_path) <= 0) { | ||
3477 | 1936 | continue; | ||
3478 | 1937 | } | ||
3479 | 1938 | trim_string(lname, "./", "/"); | ||
3480 | 1939 | |||
3481 | 1940 | /* check if it's a directory */ | ||
3482 | 1941 | if (temp_list->isdir) { | ||
3483 | 1942 | /* if (!recurse) continue; */ | ||
3484 | 1943 | |||
3485 | 1944 | SAFE_FREE(quest); | ||
3486 | 1945 | if (asprintf(&quest, "Put directory %s? ", lname) < 0) { | ||
3487 | 1946 | break; | ||
3488 | 1947 | } | ||
3489 | 1948 | if (prompt && !yesno(quest)) { /* No */ | ||
3490 | 1949 | /* Skip the directory */ | ||
3491 | 1950 | lname[strlen(lname)-1] = '/'; | ||
3492 | 1951 | if (!seek_list(temp_list, lname)) | ||
3493 | 1952 | break; | ||
3494 | 1953 | } else { /* Yes */ | ||
3495 | 1954 | SAFE_FREE(rname); | ||
3496 | 1955 | if(asprintf(&rname, "%s%s", client_get_cur_dir(), lname) < 0) { | ||
3497 | 1956 | break; | ||
3498 | 1957 | } | ||
3499 | 1958 | normalize_name(rname); | ||
3500 | 1959 | if (!cli_chkpath(cli, rname) && | ||
3501 | 1960 | !do_mkdir(rname)) { | ||
3502 | 1961 | DEBUG (0, ("Unable to make dir, skipping...")); | ||
3503 | 1962 | /* Skip the directory */ | ||
3504 | 1963 | lname[strlen(lname)-1] = '/'; | ||
3505 | 1964 | if (!seek_list(temp_list, lname)) { | ||
3506 | 1965 | break; | ||
3507 | 1966 | } | ||
3508 | 1967 | } | ||
3509 | 1968 | } | ||
3510 | 1969 | continue; | ||
3511 | 1970 | } else { | ||
3512 | 1971 | SAFE_FREE(quest); | ||
3513 | 1972 | if (asprintf(&quest,"Put file %s? ", lname) < 0) { | ||
3514 | 1973 | break; | ||
3515 | 1974 | } | ||
3516 | 1975 | if (prompt && !yesno(quest)) { | ||
3517 | 1976 | /* No */ | ||
3518 | 1977 | continue; | ||
3519 | 1978 | } | ||
3520 | 1979 | |||
3521 | 1980 | /* Yes */ | ||
3522 | 1981 | SAFE_FREE(rname); | ||
3523 | 1982 | if (asprintf(&rname, "%s%s", client_get_cur_dir(), lname) < 0) { | ||
3524 | 1983 | break; | ||
3525 | 1984 | } | ||
3526 | 1985 | } | ||
3527 | 1986 | |||
3528 | 1987 | normalize_name(rname); | ||
3529 | 1988 | |||
3530 | 1989 | do_put(rname, lname, false); | ||
3531 | 1990 | } | ||
3532 | 1991 | free_file_list(file_list); | ||
3533 | 1992 | SAFE_FREE(quest); | ||
3534 | 1993 | SAFE_FREE(lname); | ||
3535 | 1994 | SAFE_FREE(rname); | ||
3536 | 1995 | } | ||
3537 | 1996 | |||
3538 | 1997 | return 0; | ||
3539 | 1998 | } | ||
3540 | 1999 | |||
3541 | 2000 | /**************************************************************************** | ||
3542 | 2001 | Cancel a print job. | ||
3543 | 2002 | ****************************************************************************/ | ||
3544 | 2003 | |||
3545 | 2004 | static int do_cancel(int job) | ||
3546 | 2005 | { | ||
3547 | 2006 | if (cli_printjob_del(cli, job)) { | ||
3548 | 2007 | d_printf("Job %d cancelled\n",job); | ||
3549 | 2008 | return 0; | ||
3550 | 2009 | } else { | ||
3551 | 2010 | d_printf("Error cancelling job %d : %s\n",job,cli_errstr(cli)); | ||
3552 | 2011 | return 1; | ||
3553 | 2012 | } | ||
3554 | 2013 | } | ||
3555 | 2014 | |||
3556 | 2015 | /**************************************************************************** | ||
3557 | 2016 | Cancel a print job. | ||
3558 | 2017 | ****************************************************************************/ | ||
3559 | 2018 | |||
3560 | 2019 | static int cmd_cancel(void) | ||
3561 | 2020 | { | ||
3562 | 2021 | TALLOC_CTX *ctx = talloc_tos(); | ||
3563 | 2022 | char *buf = NULL; | ||
3564 | 2023 | int job; | ||
3565 | 2024 | |||
3566 | 2025 | if (!next_token_talloc(ctx, &cmd_ptr, &buf,NULL)) { | ||
3567 | 2026 | d_printf("cancel <jobid> ...\n"); | ||
3568 | 2027 | return 1; | ||
3569 | 2028 | } | ||
3570 | 2029 | do { | ||
3571 | 2030 | job = atoi(buf); | ||
3572 | 2031 | do_cancel(job); | ||
3573 | 2032 | } while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)); | ||
3574 | 2033 | |||
3575 | 2034 | return 0; | ||
3576 | 2035 | } | ||
3577 | 2036 | |||
3578 | 2037 | /**************************************************************************** | ||
3579 | 2038 | Print a file. | ||
3580 | 2039 | ****************************************************************************/ | ||
3581 | 2040 | |||
3582 | 2041 | static int cmd_print(void) | ||
3583 | 2042 | { | ||
3584 | 2043 | TALLOC_CTX *ctx = talloc_tos(); | ||
3585 | 2044 | char *lname = NULL; | ||
3586 | 2045 | char *rname = NULL; | ||
3587 | 2046 | char *p = NULL; | ||
3588 | 2047 | |||
3589 | 2048 | if (!next_token_talloc(ctx, &cmd_ptr, &lname,NULL)) { | ||
3590 | 2049 | d_printf("print <filename>\n"); | ||
3591 | 2050 | return 1; | ||
3592 | 2051 | } | ||
3593 | 2052 | |||
3594 | 2053 | rname = talloc_strdup(ctx, lname); | ||
3595 | 2054 | if (!rname) { | ||
3596 | 2055 | return 1; | ||
3597 | 2056 | } | ||
3598 | 2057 | p = strrchr_m(rname,'/'); | ||
3599 | 2058 | if (p) { | ||
3600 | 2059 | rname = talloc_asprintf(ctx, | ||
3601 | 2060 | "%s-%d", | ||
3602 | 2061 | p+1, | ||
3603 | 2062 | (int)sys_getpid()); | ||
3604 | 2063 | } | ||
3605 | 2064 | if (strequal(lname,"-")) { | ||
3606 | 2065 | rname = talloc_asprintf(ctx, | ||
3607 | 2066 | "stdin-%d", | ||
3608 | 2067 | (int)sys_getpid()); | ||
3609 | 2068 | } | ||
3610 | 2069 | if (!rname) { | ||
3611 | 2070 | return 1; | ||
3612 | 2071 | } | ||
3613 | 2072 | |||
3614 | 2073 | return do_put(rname, lname, false); | ||
3615 | 2074 | } | ||
3616 | 2075 | |||
3617 | 2076 | /**************************************************************************** | ||
3618 | 2077 | Show a print queue entry. | ||
3619 | 2078 | ****************************************************************************/ | ||
3620 | 2079 | |||
3621 | 2080 | static void queue_fn(struct print_job_info *p) | ||
3622 | 2081 | { | ||
3623 | 2082 | d_printf("%-6d %-9d %s\n", (int)p->id, (int)p->size, p->name); | ||
3624 | 2083 | } | ||
3625 | 2084 | |||
3626 | 2085 | /**************************************************************************** | ||
3627 | 2086 | Show a print queue. | ||
3628 | 2087 | ****************************************************************************/ | ||
3629 | 2088 | |||
3630 | 2089 | static int cmd_queue(void) | ||
3631 | 2090 | { | ||
3632 | 2091 | cli_print_queue(cli, queue_fn); | ||
3633 | 2092 | return 0; | ||
3634 | 2093 | } | ||
3635 | 2094 | |||
3636 | 2095 | /**************************************************************************** | ||
3637 | 2096 | Delete some files. | ||
3638 | 2097 | ****************************************************************************/ | ||
3639 | 2098 | |||
3640 | 2099 | static void do_del(file_info *finfo, const char *dir) | ||
3641 | 2100 | { | ||
3642 | 2101 | TALLOC_CTX *ctx = talloc_tos(); | ||
3643 | 2102 | char *mask = NULL; | ||
3644 | 2103 | |||
3645 | 2104 | mask = talloc_asprintf(ctx, | ||
3646 | 2105 | "%s%c%s", | ||
3647 | 2106 | dir, | ||
3648 | 2107 | CLI_DIRSEP_CHAR, | ||
3649 | 2108 | finfo->name); | ||
3650 | 2109 | if (!mask) { | ||
3651 | 2110 | return; | ||
3652 | 2111 | } | ||
3653 | 2112 | |||
3654 | 2113 | if (finfo->mode & aDIR) { | ||
3655 | 2114 | TALLOC_FREE(mask); | ||
3656 | 2115 | return; | ||
3657 | 2116 | } | ||
3658 | 2117 | |||
3659 | 2118 | if (!cli_unlink(finfo->cli, mask)) { | ||
3660 | 2119 | d_printf("%s deleting remote file %s\n", | ||
3661 | 2120 | cli_errstr(finfo->cli),mask); | ||
3662 | 2121 | } | ||
3663 | 2122 | TALLOC_FREE(mask); | ||
3664 | 2123 | } | ||
3665 | 2124 | |||
3666 | 2125 | /**************************************************************************** | ||
3667 | 2126 | Delete some files. | ||
3668 | 2127 | ****************************************************************************/ | ||
3669 | 2128 | |||
3670 | 2129 | static int cmd_del(void) | ||
3671 | 2130 | { | ||
3672 | 2131 | TALLOC_CTX *ctx = talloc_tos(); | ||
3673 | 2132 | char *mask = NULL; | ||
3674 | 2133 | char *buf = NULL; | ||
3675 | 2134 | uint16 attribute = aSYSTEM | aHIDDEN; | ||
3676 | 2135 | |||
3677 | 2136 | if (recurse) { | ||
3678 | 2137 | attribute |= aDIR; | ||
3679 | 2138 | } | ||
3680 | 2139 | |||
3681 | 2140 | mask = talloc_strdup(ctx, client_get_cur_dir()); | ||
3682 | 2141 | if (!mask) { | ||
3683 | 2142 | return 1; | ||
3684 | 2143 | } | ||
3685 | 2144 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3686 | 2145 | d_printf("del <filename>\n"); | ||
3687 | 2146 | return 1; | ||
3688 | 2147 | } | ||
3689 | 2148 | mask = talloc_asprintf_append(mask, "%s", buf); | ||
3690 | 2149 | if (!mask) { | ||
3691 | 2150 | return 1; | ||
3692 | 2151 | } | ||
3693 | 2152 | |||
3694 | 2153 | do_list(mask,attribute,do_del,false,false); | ||
3695 | 2154 | return 0; | ||
3696 | 2155 | } | ||
3697 | 2156 | |||
3698 | 2157 | /**************************************************************************** | ||
3699 | 2158 | Wildcard delete some files. | ||
3700 | 2159 | ****************************************************************************/ | ||
3701 | 2160 | |||
3702 | 2161 | static int cmd_wdel(void) | ||
3703 | 2162 | { | ||
3704 | 2163 | TALLOC_CTX *ctx = talloc_tos(); | ||
3705 | 2164 | char *mask = NULL; | ||
3706 | 2165 | char *buf = NULL; | ||
3707 | 2166 | uint16 attribute; | ||
3708 | 2167 | struct cli_state *targetcli; | ||
3709 | 2168 | char *targetname = NULL; | ||
3710 | 2169 | |||
3711 | 2170 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3712 | 2171 | d_printf("wdel 0x<attrib> <wcard>\n"); | ||
3713 | 2172 | return 1; | ||
3714 | 2173 | } | ||
3715 | 2174 | |||
3716 | 2175 | attribute = (uint16)strtol(buf, (char **)NULL, 16); | ||
3717 | 2176 | |||
3718 | 2177 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3719 | 2178 | d_printf("wdel 0x<attrib> <wcard>\n"); | ||
3720 | 2179 | return 1; | ||
3721 | 2180 | } | ||
3722 | 2181 | |||
3723 | 2182 | mask = talloc_asprintf(ctx, "%s%s", | ||
3724 | 2183 | client_get_cur_dir(), | ||
3725 | 2184 | buf); | ||
3726 | 2185 | if (!mask) { | ||
3727 | 2186 | return 1; | ||
3728 | 2187 | } | ||
3729 | 2188 | |||
3730 | 2189 | if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { | ||
3731 | 2190 | d_printf("cmd_wdel %s: %s\n", mask, cli_errstr(cli)); | ||
3732 | 2191 | return 1; | ||
3733 | 2192 | } | ||
3734 | 2193 | |||
3735 | 2194 | if (!cli_unlink_full(targetcli, targetname, attribute)) { | ||
3736 | 2195 | d_printf("%s deleting remote files %s\n",cli_errstr(targetcli),targetname); | ||
3737 | 2196 | } | ||
3738 | 2197 | return 0; | ||
3739 | 2198 | } | ||
3740 | 2199 | |||
3741 | 2200 | /**************************************************************************** | ||
3742 | 2201 | ****************************************************************************/ | ||
3743 | 2202 | |||
3744 | 2203 | static int cmd_open(void) | ||
3745 | 2204 | { | ||
3746 | 2205 | TALLOC_CTX *ctx = talloc_tos(); | ||
3747 | 2206 | char *mask = NULL; | ||
3748 | 2207 | char *buf = NULL; | ||
3749 | 2208 | char *targetname = NULL; | ||
3750 | 2209 | struct cli_state *targetcli; | ||
3751 | 2210 | int fnum; | ||
3752 | 2211 | |||
3753 | 2212 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3754 | 2213 | d_printf("open <filename>\n"); | ||
3755 | 2214 | return 1; | ||
3756 | 2215 | } | ||
3757 | 2216 | mask = talloc_asprintf(ctx, | ||
3758 | 2217 | "%s%s", | ||
3759 | 2218 | client_get_cur_dir(), | ||
3760 | 2219 | buf); | ||
3761 | 2220 | if (!mask) { | ||
3762 | 2221 | return 1; | ||
3763 | 2222 | } | ||
3764 | 2223 | |||
3765 | 2224 | if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { | ||
3766 | 2225 | d_printf("open %s: %s\n", mask, cli_errstr(cli)); | ||
3767 | 2226 | return 1; | ||
3768 | 2227 | } | ||
3769 | 2228 | |||
3770 | 2229 | fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA|FILE_WRITE_DATA); | ||
3771 | 2230 | if (fnum == -1) { | ||
3772 | 2231 | fnum = cli_nt_create(targetcli, targetname, FILE_READ_DATA); | ||
3773 | 2232 | if (fnum != -1) { | ||
3774 | 2233 | d_printf("open file %s: for read/write fnum %d\n", targetname, fnum); | ||
3775 | 2234 | } else { | ||
3776 | 2235 | d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli)); | ||
3777 | 2236 | } | ||
3778 | 2237 | } else { | ||
3779 | 2238 | d_printf("open file %s: for read/write fnum %d\n", targetname, fnum); | ||
3780 | 2239 | } | ||
3781 | 2240 | return 0; | ||
3782 | 2241 | } | ||
3783 | 2242 | |||
3784 | 2243 | static int cmd_posix_encrypt(void) | ||
3785 | 2244 | { | ||
3786 | 2245 | TALLOC_CTX *ctx = talloc_tos(); | ||
3787 | 2246 | NTSTATUS status = NT_STATUS_UNSUCCESSFUL; | ||
3788 | 2247 | |||
3789 | 2248 | if (cli->use_kerberos) { | ||
3790 | 2249 | status = cli_gss_smb_encryption_start(cli); | ||
3791 | 2250 | } else { | ||
3792 | 2251 | char *domain = NULL; | ||
3793 | 2252 | char *user = NULL; | ||
3794 | 2253 | char *password = NULL; | ||
3795 | 2254 | |||
3796 | 2255 | if (!next_token_talloc(ctx, &cmd_ptr,&domain,NULL)) { | ||
3797 | 2256 | d_printf("posix_encrypt domain user password\n"); | ||
3798 | 2257 | return 1; | ||
3799 | 2258 | } | ||
3800 | 2259 | |||
3801 | 2260 | if (!next_token_talloc(ctx, &cmd_ptr,&user,NULL)) { | ||
3802 | 2261 | d_printf("posix_encrypt domain user password\n"); | ||
3803 | 2262 | return 1; | ||
3804 | 2263 | } | ||
3805 | 2264 | |||
3806 | 2265 | if (!next_token_talloc(ctx, &cmd_ptr,&password,NULL)) { | ||
3807 | 2266 | d_printf("posix_encrypt domain user password\n"); | ||
3808 | 2267 | return 1; | ||
3809 | 2268 | } | ||
3810 | 2269 | |||
3811 | 2270 | status = cli_raw_ntlm_smb_encryption_start(cli, | ||
3812 | 2271 | user, | ||
3813 | 2272 | password, | ||
3814 | 2273 | domain); | ||
3815 | 2274 | } | ||
3816 | 2275 | |||
3817 | 2276 | if (!NT_STATUS_IS_OK(status)) { | ||
3818 | 2277 | d_printf("posix_encrypt failed with error %s\n", nt_errstr(status)); | ||
3819 | 2278 | } else { | ||
3820 | 2279 | d_printf("encryption on\n"); | ||
3821 | 2280 | smb_encrypt = true; | ||
3822 | 2281 | } | ||
3823 | 2282 | |||
3824 | 2283 | return 0; | ||
3825 | 2284 | } | ||
3826 | 2285 | |||
3827 | 2286 | /**************************************************************************** | ||
3828 | 2287 | ****************************************************************************/ | ||
3829 | 2288 | |||
3830 | 2289 | static int cmd_posix_open(void) | ||
3831 | 2290 | { | ||
3832 | 2291 | TALLOC_CTX *ctx = talloc_tos(); | ||
3833 | 2292 | char *mask = NULL; | ||
3834 | 2293 | char *buf = NULL; | ||
3835 | 2294 | char *targetname = NULL; | ||
3836 | 2295 | struct cli_state *targetcli; | ||
3837 | 2296 | mode_t mode; | ||
3838 | 2297 | int fnum; | ||
3839 | 2298 | |||
3840 | 2299 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3841 | 2300 | d_printf("posix_open <filename> 0<mode>\n"); | ||
3842 | 2301 | return 1; | ||
3843 | 2302 | } | ||
3844 | 2303 | mask = talloc_asprintf(ctx, | ||
3845 | 2304 | "%s%s", | ||
3846 | 2305 | client_get_cur_dir(), | ||
3847 | 2306 | buf); | ||
3848 | 2307 | if (!mask) { | ||
3849 | 2308 | return 1; | ||
3850 | 2309 | } | ||
3851 | 2310 | |||
3852 | 2311 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3853 | 2312 | d_printf("posix_open <filename> 0<mode>\n"); | ||
3854 | 2313 | return 1; | ||
3855 | 2314 | } | ||
3856 | 2315 | mode = (mode_t)strtol(buf, (char **)NULL, 8); | ||
3857 | 2316 | |||
3858 | 2317 | if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { | ||
3859 | 2318 | d_printf("posix_open %s: %s\n", mask, cli_errstr(cli)); | ||
3860 | 2319 | return 1; | ||
3861 | 2320 | } | ||
3862 | 2321 | |||
3863 | 2322 | fnum = cli_posix_open(targetcli, targetname, O_CREAT|O_RDWR, mode); | ||
3864 | 2323 | if (fnum == -1) { | ||
3865 | 2324 | fnum = cli_posix_open(targetcli, targetname, O_CREAT|O_RDONLY, mode); | ||
3866 | 2325 | if (fnum != -1) { | ||
3867 | 2326 | d_printf("posix_open file %s: for read/write fnum %d\n", targetname, fnum); | ||
3868 | 2327 | } else { | ||
3869 | 2328 | d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli)); | ||
3870 | 2329 | } | ||
3871 | 2330 | } else { | ||
3872 | 2331 | d_printf("posix_open file %s: for read/write fnum %d\n", targetname, fnum); | ||
3873 | 2332 | } | ||
3874 | 2333 | |||
3875 | 2334 | return 0; | ||
3876 | 2335 | } | ||
3877 | 2336 | |||
3878 | 2337 | static int cmd_posix_mkdir(void) | ||
3879 | 2338 | { | ||
3880 | 2339 | TALLOC_CTX *ctx = talloc_tos(); | ||
3881 | 2340 | char *mask = NULL; | ||
3882 | 2341 | char *buf = NULL; | ||
3883 | 2342 | char *targetname = NULL; | ||
3884 | 2343 | struct cli_state *targetcli; | ||
3885 | 2344 | mode_t mode; | ||
3886 | 2345 | int fnum; | ||
3887 | 2346 | |||
3888 | 2347 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3889 | 2348 | d_printf("posix_mkdir <filename> 0<mode>\n"); | ||
3890 | 2349 | return 1; | ||
3891 | 2350 | } | ||
3892 | 2351 | mask = talloc_asprintf(ctx, | ||
3893 | 2352 | "%s%s", | ||
3894 | 2353 | client_get_cur_dir(), | ||
3895 | 2354 | buf); | ||
3896 | 2355 | if (!mask) { | ||
3897 | 2356 | return 1; | ||
3898 | 2357 | } | ||
3899 | 2358 | |||
3900 | 2359 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3901 | 2360 | d_printf("posix_mkdir <filename> 0<mode>\n"); | ||
3902 | 2361 | return 1; | ||
3903 | 2362 | } | ||
3904 | 2363 | mode = (mode_t)strtol(buf, (char **)NULL, 8); | ||
3905 | 2364 | |||
3906 | 2365 | if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { | ||
3907 | 2366 | d_printf("posix_mkdir %s: %s\n", mask, cli_errstr(cli)); | ||
3908 | 2367 | return 1; | ||
3909 | 2368 | } | ||
3910 | 2369 | |||
3911 | 2370 | fnum = cli_posix_mkdir(targetcli, targetname, mode); | ||
3912 | 2371 | if (fnum == -1) { | ||
3913 | 2372 | d_printf("Failed to open file %s. %s\n", targetname, cli_errstr(cli)); | ||
3914 | 2373 | } else { | ||
3915 | 2374 | d_printf("posix_mkdir created directory %s\n", targetname); | ||
3916 | 2375 | } | ||
3917 | 2376 | return 0; | ||
3918 | 2377 | } | ||
3919 | 2378 | |||
3920 | 2379 | static int cmd_posix_unlink(void) | ||
3921 | 2380 | { | ||
3922 | 2381 | TALLOC_CTX *ctx = talloc_tos(); | ||
3923 | 2382 | char *mask = NULL; | ||
3924 | 2383 | char *buf = NULL; | ||
3925 | 2384 | char *targetname = NULL; | ||
3926 | 2385 | struct cli_state *targetcli; | ||
3927 | 2386 | |||
3928 | 2387 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3929 | 2388 | d_printf("posix_unlink <filename>\n"); | ||
3930 | 2389 | return 1; | ||
3931 | 2390 | } | ||
3932 | 2391 | mask = talloc_asprintf(ctx, | ||
3933 | 2392 | "%s%s", | ||
3934 | 2393 | client_get_cur_dir(), | ||
3935 | 2394 | buf); | ||
3936 | 2395 | if (!mask) { | ||
3937 | 2396 | return 1; | ||
3938 | 2397 | } | ||
3939 | 2398 | |||
3940 | 2399 | if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { | ||
3941 | 2400 | d_printf("posix_unlink %s: %s\n", mask, cli_errstr(cli)); | ||
3942 | 2401 | return 1; | ||
3943 | 2402 | } | ||
3944 | 2403 | |||
3945 | 2404 | if (!cli_posix_unlink(targetcli, targetname)) { | ||
3946 | 2405 | d_printf("Failed to unlink file %s. %s\n", targetname, cli_errstr(cli)); | ||
3947 | 2406 | } else { | ||
3948 | 2407 | d_printf("posix_unlink deleted file %s\n", targetname); | ||
3949 | 2408 | } | ||
3950 | 2409 | |||
3951 | 2410 | return 0; | ||
3952 | 2411 | } | ||
3953 | 2412 | |||
3954 | 2413 | static int cmd_posix_rmdir(void) | ||
3955 | 2414 | { | ||
3956 | 2415 | TALLOC_CTX *ctx = talloc_tos(); | ||
3957 | 2416 | char *mask = NULL; | ||
3958 | 2417 | char *buf = NULL; | ||
3959 | 2418 | char *targetname = NULL; | ||
3960 | 2419 | struct cli_state *targetcli; | ||
3961 | 2420 | |||
3962 | 2421 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3963 | 2422 | d_printf("posix_rmdir <filename>\n"); | ||
3964 | 2423 | return 1; | ||
3965 | 2424 | } | ||
3966 | 2425 | mask = talloc_asprintf(ctx, | ||
3967 | 2426 | "%s%s", | ||
3968 | 2427 | client_get_cur_dir(), | ||
3969 | 2428 | buf); | ||
3970 | 2429 | if (!mask) { | ||
3971 | 2430 | return 1; | ||
3972 | 2431 | } | ||
3973 | 2432 | |||
3974 | 2433 | if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { | ||
3975 | 2434 | d_printf("posix_rmdir %s: %s\n", mask, cli_errstr(cli)); | ||
3976 | 2435 | return 1; | ||
3977 | 2436 | } | ||
3978 | 2437 | |||
3979 | 2438 | if (!cli_posix_rmdir(targetcli, targetname)) { | ||
3980 | 2439 | d_printf("Failed to unlink directory %s. %s\n", targetname, cli_errstr(cli)); | ||
3981 | 2440 | } else { | ||
3982 | 2441 | d_printf("posix_rmdir deleted directory %s\n", targetname); | ||
3983 | 2442 | } | ||
3984 | 2443 | |||
3985 | 2444 | return 0; | ||
3986 | 2445 | } | ||
3987 | 2446 | |||
3988 | 2447 | static int cmd_close(void) | ||
3989 | 2448 | { | ||
3990 | 2449 | TALLOC_CTX *ctx = talloc_tos(); | ||
3991 | 2450 | char *buf = NULL; | ||
3992 | 2451 | int fnum; | ||
3993 | 2452 | |||
3994 | 2453 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
3995 | 2454 | d_printf("close <fnum>\n"); | ||
3996 | 2455 | return 1; | ||
3997 | 2456 | } | ||
3998 | 2457 | |||
3999 | 2458 | fnum = atoi(buf); | ||
4000 | 2459 | /* We really should use the targetcli here.... */ | ||
4001 | 2460 | if (!cli_close(cli, fnum)) { | ||
4002 | 2461 | d_printf("close %d: %s\n", fnum, cli_errstr(cli)); | ||
4003 | 2462 | return 1; | ||
4004 | 2463 | } | ||
4005 | 2464 | return 0; | ||
4006 | 2465 | } | ||
4007 | 2466 | |||
4008 | 2467 | static int cmd_posix(void) | ||
4009 | 2468 | { | ||
4010 | 2469 | TALLOC_CTX *ctx = talloc_tos(); | ||
4011 | 2470 | uint16 major, minor; | ||
4012 | 2471 | uint32 caplow, caphigh; | ||
4013 | 2472 | char *caps; | ||
4014 | 2473 | |||
4015 | 2474 | if (!SERVER_HAS_UNIX_CIFS(cli)) { | ||
4016 | 2475 | d_printf("Server doesn't support UNIX CIFS extensions.\n"); | ||
4017 | 2476 | return 1; | ||
4018 | 2477 | } | ||
4019 | 2478 | |||
4020 | 2479 | if (!cli_unix_extensions_version(cli, &major, &minor, &caplow, &caphigh)) { | ||
4021 | 2480 | d_printf("Can't get UNIX CIFS extensions version from server.\n"); | ||
4022 | 2481 | return 1; | ||
4023 | 2482 | } | ||
4024 | 2483 | |||
4025 | 2484 | d_printf("Server supports CIFS extensions %u.%u\n", (unsigned int)major, (unsigned int)minor); | ||
4026 | 2485 | |||
4027 | 2486 | caps = talloc_strdup(ctx, ""); | ||
4028 | 2487 | if (!caps) { | ||
4029 | 2488 | return 1; | ||
4030 | 2489 | } | ||
4031 | 2490 | if (caplow & CIFS_UNIX_FCNTL_LOCKS_CAP) { | ||
4032 | 2491 | caps = talloc_asprintf_append(caps, "locks "); | ||
4033 | 2492 | if (!caps) { | ||
4034 | 2493 | return 1; | ||
4035 | 2494 | } | ||
4036 | 2495 | } | ||
4037 | 2496 | if (caplow & CIFS_UNIX_POSIX_ACLS_CAP) { | ||
4038 | 2497 | caps = talloc_asprintf_append(caps, "acls "); | ||
4039 | 2498 | if (!caps) { | ||
4040 | 2499 | return 1; | ||
4041 | 2500 | } | ||
4042 | 2501 | } | ||
4043 | 2502 | if (caplow & CIFS_UNIX_XATTTR_CAP) { | ||
4044 | 2503 | caps = talloc_asprintf_append(caps, "eas "); | ||
4045 | 2504 | if (!caps) { | ||
4046 | 2505 | return 1; | ||
4047 | 2506 | } | ||
4048 | 2507 | } | ||
4049 | 2508 | if (caplow & CIFS_UNIX_POSIX_PATHNAMES_CAP) { | ||
4050 | 2509 | caps = talloc_asprintf_append(caps, "pathnames "); | ||
4051 | 2510 | if (!caps) { | ||
4052 | 2511 | return 1; | ||
4053 | 2512 | } | ||
4054 | 2513 | } | ||
4055 | 2514 | if (caplow & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP) { | ||
4056 | 2515 | caps = talloc_asprintf_append(caps, "posix_path_operations "); | ||
4057 | 2516 | if (!caps) { | ||
4058 | 2517 | return 1; | ||
4059 | 2518 | } | ||
4060 | 2519 | } | ||
4061 | 2520 | if (caplow & CIFS_UNIX_LARGE_READ_CAP) { | ||
4062 | 2521 | caps = talloc_asprintf_append(caps, "large_read "); | ||
4063 | 2522 | if (!caps) { | ||
4064 | 2523 | return 1; | ||
4065 | 2524 | } | ||
4066 | 2525 | } | ||
4067 | 2526 | if (caplow & CIFS_UNIX_LARGE_WRITE_CAP) { | ||
4068 | 2527 | caps = talloc_asprintf_append(caps, "large_write "); | ||
4069 | 2528 | if (!caps) { | ||
4070 | 2529 | return 1; | ||
4071 | 2530 | } | ||
4072 | 2531 | } | ||
4073 | 2532 | if (caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP) { | ||
4074 | 2533 | caps = talloc_asprintf_append(caps, "posix_encrypt "); | ||
4075 | 2534 | if (!caps) { | ||
4076 | 2535 | return 1; | ||
4077 | 2536 | } | ||
4078 | 2537 | } | ||
4079 | 2538 | if (caplow & CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP) { | ||
4080 | 2539 | caps = talloc_asprintf_append(caps, "mandatory_posix_encrypt "); | ||
4081 | 2540 | if (!caps) { | ||
4082 | 2541 | return 1; | ||
4083 | 2542 | } | ||
4084 | 2543 | } | ||
4085 | 2544 | |||
4086 | 2545 | if (*caps && caps[strlen(caps)-1] == ' ') { | ||
4087 | 2546 | caps[strlen(caps)-1] = '\0'; | ||
4088 | 2547 | } | ||
4089 | 2548 | |||
4090 | 2549 | d_printf("Server supports CIFS capabilities %s\n", caps); | ||
4091 | 2550 | |||
4092 | 2551 | if (!cli_set_unix_extensions_capabilities(cli, major, minor, caplow, caphigh)) { | ||
4093 | 2552 | d_printf("Can't set UNIX CIFS extensions capabilities. %s.\n", cli_errstr(cli)); | ||
4094 | 2553 | return 1; | ||
4095 | 2554 | } | ||
4096 | 2555 | |||
4097 | 2556 | if (caplow & CIFS_UNIX_POSIX_PATHNAMES_CAP) { | ||
4098 | 2557 | CLI_DIRSEP_CHAR = '/'; | ||
4099 | 2558 | *CLI_DIRSEP_STR = '/'; | ||
4100 | 2559 | client_set_cur_dir(CLI_DIRSEP_STR); | ||
4101 | 2560 | } | ||
4102 | 2561 | |||
4103 | 2562 | return 0; | ||
4104 | 2563 | } | ||
4105 | 2564 | |||
4106 | 2565 | static int cmd_lock(void) | ||
4107 | 2566 | { | ||
4108 | 2567 | TALLOC_CTX *ctx = talloc_tos(); | ||
4109 | 2568 | char *buf = NULL; | ||
4110 | 2569 | uint64_t start, len; | ||
4111 | 2570 | enum brl_type lock_type; | ||
4112 | 2571 | int fnum; | ||
4113 | 2572 | |||
4114 | 2573 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4115 | 2574 | d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n"); | ||
4116 | 2575 | return 1; | ||
4117 | 2576 | } | ||
4118 | 2577 | fnum = atoi(buf); | ||
4119 | 2578 | |||
4120 | 2579 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4121 | 2580 | d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n"); | ||
4122 | 2581 | return 1; | ||
4123 | 2582 | } | ||
4124 | 2583 | |||
4125 | 2584 | if (*buf == 'r' || *buf == 'R') { | ||
4126 | 2585 | lock_type = READ_LOCK; | ||
4127 | 2586 | } else if (*buf == 'w' || *buf == 'W') { | ||
4128 | 2587 | lock_type = WRITE_LOCK; | ||
4129 | 2588 | } else { | ||
4130 | 2589 | d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n"); | ||
4131 | 2590 | return 1; | ||
4132 | 2591 | } | ||
4133 | 2592 | |||
4134 | 2593 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4135 | 2594 | d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n"); | ||
4136 | 2595 | return 1; | ||
4137 | 2596 | } | ||
4138 | 2597 | |||
4139 | 2598 | start = (uint64_t)strtol(buf, (char **)NULL, 16); | ||
4140 | 2599 | |||
4141 | 2600 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4142 | 2601 | d_printf("lock <fnum> [r|w] <hex-start> <hex-len>\n"); | ||
4143 | 2602 | return 1; | ||
4144 | 2603 | } | ||
4145 | 2604 | |||
4146 | 2605 | len = (uint64_t)strtol(buf, (char **)NULL, 16); | ||
4147 | 2606 | |||
4148 | 2607 | if (!cli_posix_lock(cli, fnum, start, len, true, lock_type)) { | ||
4149 | 2608 | d_printf("lock failed %d: %s\n", fnum, cli_errstr(cli)); | ||
4150 | 2609 | } | ||
4151 | 2610 | |||
4152 | 2611 | return 0; | ||
4153 | 2612 | } | ||
4154 | 2613 | |||
4155 | 2614 | static int cmd_unlock(void) | ||
4156 | 2615 | { | ||
4157 | 2616 | TALLOC_CTX *ctx = talloc_tos(); | ||
4158 | 2617 | char *buf = NULL; | ||
4159 | 2618 | uint64_t start, len; | ||
4160 | 2619 | int fnum; | ||
4161 | 2620 | |||
4162 | 2621 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4163 | 2622 | d_printf("unlock <fnum> <hex-start> <hex-len>\n"); | ||
4164 | 2623 | return 1; | ||
4165 | 2624 | } | ||
4166 | 2625 | fnum = atoi(buf); | ||
4167 | 2626 | |||
4168 | 2627 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4169 | 2628 | d_printf("unlock <fnum> <hex-start> <hex-len>\n"); | ||
4170 | 2629 | return 1; | ||
4171 | 2630 | } | ||
4172 | 2631 | |||
4173 | 2632 | start = (uint64_t)strtol(buf, (char **)NULL, 16); | ||
4174 | 2633 | |||
4175 | 2634 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4176 | 2635 | d_printf("unlock <fnum> <hex-start> <hex-len>\n"); | ||
4177 | 2636 | return 1; | ||
4178 | 2637 | } | ||
4179 | 2638 | |||
4180 | 2639 | len = (uint64_t)strtol(buf, (char **)NULL, 16); | ||
4181 | 2640 | |||
4182 | 2641 | if (!cli_posix_unlock(cli, fnum, start, len)) { | ||
4183 | 2642 | d_printf("unlock failed %d: %s\n", fnum, cli_errstr(cli)); | ||
4184 | 2643 | } | ||
4185 | 2644 | |||
4186 | 2645 | return 0; | ||
4187 | 2646 | } | ||
4188 | 2647 | |||
4189 | 2648 | |||
4190 | 2649 | /**************************************************************************** | ||
4191 | 2650 | Remove a directory. | ||
4192 | 2651 | ****************************************************************************/ | ||
4193 | 2652 | |||
4194 | 2653 | static int cmd_rmdir(void) | ||
4195 | 2654 | { | ||
4196 | 2655 | TALLOC_CTX *ctx = talloc_tos(); | ||
4197 | 2656 | char *mask = NULL; | ||
4198 | 2657 | char *buf = NULL; | ||
4199 | 2658 | char *targetname = NULL; | ||
4200 | 2659 | struct cli_state *targetcli; | ||
4201 | 2660 | |||
4202 | 2661 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4203 | 2662 | d_printf("rmdir <dirname>\n"); | ||
4204 | 2663 | return 1; | ||
4205 | 2664 | } | ||
4206 | 2665 | mask = talloc_asprintf(ctx, | ||
4207 | 2666 | "%s%s", | ||
4208 | 2667 | client_get_cur_dir(), | ||
4209 | 2668 | buf); | ||
4210 | 2669 | if (!mask) { | ||
4211 | 2670 | return 1; | ||
4212 | 2671 | } | ||
4213 | 2672 | |||
4214 | 2673 | if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { | ||
4215 | 2674 | d_printf("rmdir %s: %s\n", mask, cli_errstr(cli)); | ||
4216 | 2675 | return 1; | ||
4217 | 2676 | } | ||
4218 | 2677 | |||
4219 | 2678 | if (!cli_rmdir(targetcli, targetname)) { | ||
4220 | 2679 | d_printf("%s removing remote directory file %s\n", | ||
4221 | 2680 | cli_errstr(targetcli),mask); | ||
4222 | 2681 | } | ||
4223 | 2682 | |||
4224 | 2683 | return 0; | ||
4225 | 2684 | } | ||
4226 | 2685 | |||
4227 | 2686 | /**************************************************************************** | ||
4228 | 2687 | UNIX hardlink. | ||
4229 | 2688 | ****************************************************************************/ | ||
4230 | 2689 | |||
4231 | 2690 | static int cmd_link(void) | ||
4232 | 2691 | { | ||
4233 | 2692 | TALLOC_CTX *ctx = talloc_tos(); | ||
4234 | 2693 | char *oldname = NULL; | ||
4235 | 2694 | char *newname = NULL; | ||
4236 | 2695 | char *buf = NULL; | ||
4237 | 2696 | char *buf2 = NULL; | ||
4238 | 2697 | char *targetname = NULL; | ||
4239 | 2698 | struct cli_state *targetcli; | ||
4240 | 2699 | |||
4241 | 2700 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) || | ||
4242 | 2701 | !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) { | ||
4243 | 2702 | d_printf("link <oldname> <newname>\n"); | ||
4244 | 2703 | return 1; | ||
4245 | 2704 | } | ||
4246 | 2705 | oldname = talloc_asprintf(ctx, | ||
4247 | 2706 | "%s%s", | ||
4248 | 2707 | client_get_cur_dir(), | ||
4249 | 2708 | buf); | ||
4250 | 2709 | if (!oldname) { | ||
4251 | 2710 | return 1; | ||
4252 | 2711 | } | ||
4253 | 2712 | newname = talloc_asprintf(ctx, | ||
4254 | 2713 | "%s%s", | ||
4255 | 2714 | client_get_cur_dir(), | ||
4256 | 2715 | buf2); | ||
4257 | 2716 | if (!newname) { | ||
4258 | 2717 | return 1; | ||
4259 | 2718 | } | ||
4260 | 2719 | |||
4261 | 2720 | if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) { | ||
4262 | 2721 | d_printf("link %s: %s\n", oldname, cli_errstr(cli)); | ||
4263 | 2722 | return 1; | ||
4264 | 2723 | } | ||
4265 | 2724 | |||
4266 | 2725 | if (!SERVER_HAS_UNIX_CIFS(targetcli)) { | ||
4267 | 2726 | d_printf("Server doesn't support UNIX CIFS calls.\n"); | ||
4268 | 2727 | return 1; | ||
4269 | 2728 | } | ||
4270 | 2729 | |||
4271 | 2730 | if (!cli_unix_hardlink(targetcli, targetname, newname)) { | ||
4272 | 2731 | d_printf("%s linking files (%s -> %s)\n", cli_errstr(targetcli), newname, oldname); | ||
4273 | 2732 | return 1; | ||
4274 | 2733 | } | ||
4275 | 2734 | return 0; | ||
4276 | 2735 | } | ||
4277 | 2736 | |||
4278 | 2737 | /**************************************************************************** | ||
4279 | 2738 | UNIX symlink. | ||
4280 | 2739 | ****************************************************************************/ | ||
4281 | 2740 | |||
4282 | 2741 | static int cmd_symlink(void) | ||
4283 | 2742 | { | ||
4284 | 2743 | TALLOC_CTX *ctx = talloc_tos(); | ||
4285 | 2744 | char *oldname = NULL; | ||
4286 | 2745 | char *newname = NULL; | ||
4287 | 2746 | char *buf = NULL; | ||
4288 | 2747 | char *buf2 = NULL; | ||
4289 | 2748 | char *targetname = NULL; | ||
4290 | 2749 | struct cli_state *targetcli; | ||
4291 | 2750 | |||
4292 | 2751 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) || | ||
4293 | 2752 | !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) { | ||
4294 | 2753 | d_printf("symlink <oldname> <newname>\n"); | ||
4295 | 2754 | return 1; | ||
4296 | 2755 | } | ||
4297 | 2756 | oldname = talloc_asprintf(ctx, | ||
4298 | 2757 | "%s%s", | ||
4299 | 2758 | client_get_cur_dir(), | ||
4300 | 2759 | buf); | ||
4301 | 2760 | if (!oldname) { | ||
4302 | 2761 | return 1; | ||
4303 | 2762 | } | ||
4304 | 2763 | newname = talloc_asprintf(ctx, | ||
4305 | 2764 | "%s%s", | ||
4306 | 2765 | client_get_cur_dir(), | ||
4307 | 2766 | buf2); | ||
4308 | 2767 | if (!newname) { | ||
4309 | 2768 | return 1; | ||
4310 | 2769 | } | ||
4311 | 2770 | |||
4312 | 2771 | if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) { | ||
4313 | 2772 | d_printf("link %s: %s\n", oldname, cli_errstr(cli)); | ||
4314 | 2773 | return 1; | ||
4315 | 2774 | } | ||
4316 | 2775 | |||
4317 | 2776 | if (!SERVER_HAS_UNIX_CIFS(targetcli)) { | ||
4318 | 2777 | d_printf("Server doesn't support UNIX CIFS calls.\n"); | ||
4319 | 2778 | return 1; | ||
4320 | 2779 | } | ||
4321 | 2780 | |||
4322 | 2781 | if (!cli_unix_symlink(targetcli, targetname, newname)) { | ||
4323 | 2782 | d_printf("%s symlinking files (%s -> %s)\n", | ||
4324 | 2783 | cli_errstr(targetcli), newname, targetname); | ||
4325 | 2784 | return 1; | ||
4326 | 2785 | } | ||
4327 | 2786 | |||
4328 | 2787 | return 0; | ||
4329 | 2788 | } | ||
4330 | 2789 | |||
4331 | 2790 | /**************************************************************************** | ||
4332 | 2791 | UNIX chmod. | ||
4333 | 2792 | ****************************************************************************/ | ||
4334 | 2793 | |||
4335 | 2794 | static int cmd_chmod(void) | ||
4336 | 2795 | { | ||
4337 | 2796 | TALLOC_CTX *ctx = talloc_tos(); | ||
4338 | 2797 | char *src = NULL; | ||
4339 | 2798 | char *buf = NULL; | ||
4340 | 2799 | char *buf2 = NULL; | ||
4341 | 2800 | char *targetname = NULL; | ||
4342 | 2801 | struct cli_state *targetcli; | ||
4343 | 2802 | mode_t mode; | ||
4344 | 2803 | |||
4345 | 2804 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) || | ||
4346 | 2805 | !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) { | ||
4347 | 2806 | d_printf("chmod mode file\n"); | ||
4348 | 2807 | return 1; | ||
4349 | 2808 | } | ||
4350 | 2809 | src = talloc_asprintf(ctx, | ||
4351 | 2810 | "%s%s", | ||
4352 | 2811 | client_get_cur_dir(), | ||
4353 | 2812 | buf2); | ||
4354 | 2813 | if (!src) { | ||
4355 | 2814 | return 1; | ||
4356 | 2815 | } | ||
4357 | 2816 | |||
4358 | 2817 | mode = (mode_t)strtol(buf, NULL, 8); | ||
4359 | 2818 | |||
4360 | 2819 | if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) { | ||
4361 | 2820 | d_printf("chmod %s: %s\n", src, cli_errstr(cli)); | ||
4362 | 2821 | return 1; | ||
4363 | 2822 | } | ||
4364 | 2823 | |||
4365 | 2824 | if (!SERVER_HAS_UNIX_CIFS(targetcli)) { | ||
4366 | 2825 | d_printf("Server doesn't support UNIX CIFS calls.\n"); | ||
4367 | 2826 | return 1; | ||
4368 | 2827 | } | ||
4369 | 2828 | |||
4370 | 2829 | if (!cli_unix_chmod(targetcli, targetname, mode)) { | ||
4371 | 2830 | d_printf("%s chmod file %s 0%o\n", | ||
4372 | 2831 | cli_errstr(targetcli), src, (unsigned int)mode); | ||
4373 | 2832 | return 1; | ||
4374 | 2833 | } | ||
4375 | 2834 | |||
4376 | 2835 | return 0; | ||
4377 | 2836 | } | ||
4378 | 2837 | |||
4379 | 2838 | static const char *filetype_to_str(mode_t mode) | ||
4380 | 2839 | { | ||
4381 | 2840 | if (S_ISREG(mode)) { | ||
4382 | 2841 | return "regular file"; | ||
4383 | 2842 | } else if (S_ISDIR(mode)) { | ||
4384 | 2843 | return "directory"; | ||
4385 | 2844 | } else | ||
4386 | 2845 | #ifdef S_ISCHR | ||
4387 | 2846 | if (S_ISCHR(mode)) { | ||
4388 | 2847 | return "character device"; | ||
4389 | 2848 | } else | ||
4390 | 2849 | #endif | ||
4391 | 2850 | #ifdef S_ISBLK | ||
4392 | 2851 | if (S_ISBLK(mode)) { | ||
4393 | 2852 | return "block device"; | ||
4394 | 2853 | } else | ||
4395 | 2854 | #endif | ||
4396 | 2855 | #ifdef S_ISFIFO | ||
4397 | 2856 | if (S_ISFIFO(mode)) { | ||
4398 | 2857 | return "fifo"; | ||
4399 | 2858 | } else | ||
4400 | 2859 | #endif | ||
4401 | 2860 | #ifdef S_ISLNK | ||
4402 | 2861 | if (S_ISLNK(mode)) { | ||
4403 | 2862 | return "symbolic link"; | ||
4404 | 2863 | } else | ||
4405 | 2864 | #endif | ||
4406 | 2865 | #ifdef S_ISSOCK | ||
4407 | 2866 | if (S_ISSOCK(mode)) { | ||
4408 | 2867 | return "socket"; | ||
4409 | 2868 | } else | ||
4410 | 2869 | #endif | ||
4411 | 2870 | return ""; | ||
4412 | 2871 | } | ||
4413 | 2872 | |||
4414 | 2873 | static char rwx_to_str(mode_t m, mode_t bt, char ret) | ||
4415 | 2874 | { | ||
4416 | 2875 | if (m & bt) { | ||
4417 | 2876 | return ret; | ||
4418 | 2877 | } else { | ||
4419 | 2878 | return '-'; | ||
4420 | 2879 | } | ||
4421 | 2880 | } | ||
4422 | 2881 | |||
4423 | 2882 | static char *unix_mode_to_str(char *s, mode_t m) | ||
4424 | 2883 | { | ||
4425 | 2884 | char *p = s; | ||
4426 | 2885 | const char *str = filetype_to_str(m); | ||
4427 | 2886 | |||
4428 | 2887 | switch(str[0]) { | ||
4429 | 2888 | case 'd': | ||
4430 | 2889 | *p++ = 'd'; | ||
4431 | 2890 | break; | ||
4432 | 2891 | case 'c': | ||
4433 | 2892 | *p++ = 'c'; | ||
4434 | 2893 | break; | ||
4435 | 2894 | case 'b': | ||
4436 | 2895 | *p++ = 'b'; | ||
4437 | 2896 | break; | ||
4438 | 2897 | case 'f': | ||
4439 | 2898 | *p++ = 'p'; | ||
4440 | 2899 | break; | ||
4441 | 2900 | case 's': | ||
4442 | 2901 | *p++ = str[1] == 'y' ? 'l' : 's'; | ||
4443 | 2902 | break; | ||
4444 | 2903 | case 'r': | ||
4445 | 2904 | default: | ||
4446 | 2905 | *p++ = '-'; | ||
4447 | 2906 | break; | ||
4448 | 2907 | } | ||
4449 | 2908 | *p++ = rwx_to_str(m, S_IRUSR, 'r'); | ||
4450 | 2909 | *p++ = rwx_to_str(m, S_IWUSR, 'w'); | ||
4451 | 2910 | *p++ = rwx_to_str(m, S_IXUSR, 'x'); | ||
4452 | 2911 | *p++ = rwx_to_str(m, S_IRGRP, 'r'); | ||
4453 | 2912 | *p++ = rwx_to_str(m, S_IWGRP, 'w'); | ||
4454 | 2913 | *p++ = rwx_to_str(m, S_IXGRP, 'x'); | ||
4455 | 2914 | *p++ = rwx_to_str(m, S_IROTH, 'r'); | ||
4456 | 2915 | *p++ = rwx_to_str(m, S_IWOTH, 'w'); | ||
4457 | 2916 | *p++ = rwx_to_str(m, S_IXOTH, 'x'); | ||
4458 | 2917 | *p++ = '\0'; | ||
4459 | 2918 | return s; | ||
4460 | 2919 | } | ||
4461 | 2920 | |||
4462 | 2921 | /**************************************************************************** | ||
4463 | 2922 | Utility function for UNIX getfacl. | ||
4464 | 2923 | ****************************************************************************/ | ||
4465 | 2924 | |||
4466 | 2925 | static char *perms_to_string(fstring permstr, unsigned char perms) | ||
4467 | 2926 | { | ||
4468 | 2927 | fstrcpy(permstr, "---"); | ||
4469 | 2928 | if (perms & SMB_POSIX_ACL_READ) { | ||
4470 | 2929 | permstr[0] = 'r'; | ||
4471 | 2930 | } | ||
4472 | 2931 | if (perms & SMB_POSIX_ACL_WRITE) { | ||
4473 | 2932 | permstr[1] = 'w'; | ||
4474 | 2933 | } | ||
4475 | 2934 | if (perms & SMB_POSIX_ACL_EXECUTE) { | ||
4476 | 2935 | permstr[2] = 'x'; | ||
4477 | 2936 | } | ||
4478 | 2937 | return permstr; | ||
4479 | 2938 | } | ||
4480 | 2939 | |||
4481 | 2940 | /**************************************************************************** | ||
4482 | 2941 | UNIX getfacl. | ||
4483 | 2942 | ****************************************************************************/ | ||
4484 | 2943 | |||
4485 | 2944 | static int cmd_getfacl(void) | ||
4486 | 2945 | { | ||
4487 | 2946 | TALLOC_CTX *ctx = talloc_tos(); | ||
4488 | 2947 | char *src = NULL; | ||
4489 | 2948 | char *name = NULL; | ||
4490 | 2949 | char *targetname = NULL; | ||
4491 | 2950 | struct cli_state *targetcli; | ||
4492 | 2951 | uint16 major, minor; | ||
4493 | 2952 | uint32 caplow, caphigh; | ||
4494 | 2953 | char *retbuf = NULL; | ||
4495 | 2954 | size_t rb_size = 0; | ||
4496 | 2955 | SMB_STRUCT_STAT sbuf; | ||
4497 | 2956 | uint16 num_file_acls = 0; | ||
4498 | 2957 | uint16 num_dir_acls = 0; | ||
4499 | 2958 | uint16 i; | ||
4500 | 2959 | |||
4501 | 2960 | if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) { | ||
4502 | 2961 | d_printf("getfacl filename\n"); | ||
4503 | 2962 | return 1; | ||
4504 | 2963 | } | ||
4505 | 2964 | src = talloc_asprintf(ctx, | ||
4506 | 2965 | "%s%s", | ||
4507 | 2966 | client_get_cur_dir(), | ||
4508 | 2967 | name); | ||
4509 | 2968 | if (!src) { | ||
4510 | 2969 | return 1; | ||
4511 | 2970 | } | ||
4512 | 2971 | |||
4513 | 2972 | if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) { | ||
4514 | 2973 | d_printf("stat %s: %s\n", src, cli_errstr(cli)); | ||
4515 | 2974 | return 1; | ||
4516 | 2975 | } | ||
4517 | 2976 | |||
4518 | 2977 | if (!SERVER_HAS_UNIX_CIFS(targetcli)) { | ||
4519 | 2978 | d_printf("Server doesn't support UNIX CIFS calls.\n"); | ||
4520 | 2979 | return 1; | ||
4521 | 2980 | } | ||
4522 | 2981 | |||
4523 | 2982 | if (!cli_unix_extensions_version(targetcli, &major, &minor, | ||
4524 | 2983 | &caplow, &caphigh)) { | ||
4525 | 2984 | d_printf("Can't get UNIX CIFS version from server.\n"); | ||
4526 | 2985 | return 1; | ||
4527 | 2986 | } | ||
4528 | 2987 | |||
4529 | 2988 | if (!(caplow & CIFS_UNIX_POSIX_ACLS_CAP)) { | ||
4530 | 2989 | d_printf("This server supports UNIX extensions " | ||
4531 | 2990 | "but doesn't support POSIX ACLs.\n"); | ||
4532 | 2991 | return 1; | ||
4533 | 2992 | } | ||
4534 | 2993 | |||
4535 | 2994 | if (!cli_unix_stat(targetcli, targetname, &sbuf)) { | ||
4536 | 2995 | d_printf("%s getfacl doing a stat on file %s\n", | ||
4537 | 2996 | cli_errstr(targetcli), src); | ||
4538 | 2997 | return 1; | ||
4539 | 2998 | } | ||
4540 | 2999 | |||
4541 | 3000 | if (!cli_unix_getfacl(targetcli, targetname, &rb_size, &retbuf)) { | ||
4542 | 3001 | d_printf("%s getfacl file %s\n", | ||
4543 | 3002 | cli_errstr(targetcli), src); | ||
4544 | 3003 | return 1; | ||
4545 | 3004 | } | ||
4546 | 3005 | |||
4547 | 3006 | /* ToDo : Print out the ACL values. */ | ||
4548 | 3007 | if (SVAL(retbuf,0) != SMB_POSIX_ACL_VERSION || rb_size < 6) { | ||
4549 | 3008 | d_printf("getfacl file %s, unknown POSIX acl version %u.\n", | ||
4550 | 3009 | src, (unsigned int)CVAL(retbuf,0) ); | ||
4551 | 3010 | SAFE_FREE(retbuf); | ||
4552 | 3011 | return 1; | ||
4553 | 3012 | } | ||
4554 | 3013 | |||
4555 | 3014 | num_file_acls = SVAL(retbuf,2); | ||
4556 | 3015 | num_dir_acls = SVAL(retbuf,4); | ||
4557 | 3016 | if (rb_size != SMB_POSIX_ACL_HEADER_SIZE + SMB_POSIX_ACL_ENTRY_SIZE*(num_file_acls+num_dir_acls)) { | ||
4558 | 3017 | d_printf("getfacl file %s, incorrect POSIX acl buffer size (should be %u, was %u).\n", | ||
4559 | 3018 | src, | ||
4560 | 3019 | (unsigned int)(SMB_POSIX_ACL_HEADER_SIZE + SMB_POSIX_ACL_ENTRY_SIZE*(num_file_acls+num_dir_acls)), | ||
4561 | 3020 | (unsigned int)rb_size); | ||
4562 | 3021 | |||
4563 | 3022 | SAFE_FREE(retbuf); | ||
4564 | 3023 | return 1; | ||
4565 | 3024 | } | ||
4566 | 3025 | |||
4567 | 3026 | d_printf("# file: %s\n", src); | ||
4568 | 3027 | d_printf("# owner: %u\n# group: %u\n", (unsigned int)sbuf.st_uid, (unsigned int)sbuf.st_gid); | ||
4569 | 3028 | |||
4570 | 3029 | if (num_file_acls == 0 && num_dir_acls == 0) { | ||
4571 | 3030 | d_printf("No acls found.\n"); | ||
4572 | 3031 | } | ||
4573 | 3032 | |||
4574 | 3033 | for (i = 0; i < num_file_acls; i++) { | ||
4575 | 3034 | uint32 uorg; | ||
4576 | 3035 | fstring permstring; | ||
4577 | 3036 | unsigned char tagtype = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)); | ||
4578 | 3037 | unsigned char perms = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+1); | ||
4579 | 3038 | |||
4580 | 3039 | switch(tagtype) { | ||
4581 | 3040 | case SMB_POSIX_ACL_USER_OBJ: | ||
4582 | 3041 | d_printf("user::"); | ||
4583 | 3042 | break; | ||
4584 | 3043 | case SMB_POSIX_ACL_USER: | ||
4585 | 3044 | uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+2); | ||
4586 | 3045 | d_printf("user:%u:", uorg); | ||
4587 | 3046 | break; | ||
4588 | 3047 | case SMB_POSIX_ACL_GROUP_OBJ: | ||
4589 | 3048 | d_printf("group::"); | ||
4590 | 3049 | break; | ||
4591 | 3050 | case SMB_POSIX_ACL_GROUP: | ||
4592 | 3051 | uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+(i*SMB_POSIX_ACL_ENTRY_SIZE)+2); | ||
4593 | 3052 | d_printf("group:%u:", uorg); | ||
4594 | 3053 | break; | ||
4595 | 3054 | case SMB_POSIX_ACL_MASK: | ||
4596 | 3055 | d_printf("mask::"); | ||
4597 | 3056 | break; | ||
4598 | 3057 | case SMB_POSIX_ACL_OTHER: | ||
4599 | 3058 | d_printf("other::"); | ||
4600 | 3059 | break; | ||
4601 | 3060 | default: | ||
4602 | 3061 | d_printf("getfacl file %s, incorrect POSIX acl tagtype (%u).\n", | ||
4603 | 3062 | src, (unsigned int)tagtype ); | ||
4604 | 3063 | SAFE_FREE(retbuf); | ||
4605 | 3064 | return 1; | ||
4606 | 3065 | } | ||
4607 | 3066 | |||
4608 | 3067 | d_printf("%s\n", perms_to_string(permstring, perms)); | ||
4609 | 3068 | } | ||
4610 | 3069 | |||
4611 | 3070 | for (i = 0; i < num_dir_acls; i++) { | ||
4612 | 3071 | uint32 uorg; | ||
4613 | 3072 | fstring permstring; | ||
4614 | 3073 | unsigned char tagtype = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)); | ||
4615 | 3074 | unsigned char perms = CVAL(retbuf, SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+1); | ||
4616 | 3075 | |||
4617 | 3076 | switch(tagtype) { | ||
4618 | 3077 | case SMB_POSIX_ACL_USER_OBJ: | ||
4619 | 3078 | d_printf("default:user::"); | ||
4620 | 3079 | break; | ||
4621 | 3080 | case SMB_POSIX_ACL_USER: | ||
4622 | 3081 | uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+2); | ||
4623 | 3082 | d_printf("default:user:%u:", uorg); | ||
4624 | 3083 | break; | ||
4625 | 3084 | case SMB_POSIX_ACL_GROUP_OBJ: | ||
4626 | 3085 | d_printf("default:group::"); | ||
4627 | 3086 | break; | ||
4628 | 3087 | case SMB_POSIX_ACL_GROUP: | ||
4629 | 3088 | uorg = IVAL(retbuf,SMB_POSIX_ACL_HEADER_SIZE+((i+num_file_acls)*SMB_POSIX_ACL_ENTRY_SIZE)+2); | ||
4630 | 3089 | d_printf("default:group:%u:", uorg); | ||
4631 | 3090 | break; | ||
4632 | 3091 | case SMB_POSIX_ACL_MASK: | ||
4633 | 3092 | d_printf("default:mask::"); | ||
4634 | 3093 | break; | ||
4635 | 3094 | case SMB_POSIX_ACL_OTHER: | ||
4636 | 3095 | d_printf("default:other::"); | ||
4637 | 3096 | break; | ||
4638 | 3097 | default: | ||
4639 | 3098 | d_printf("getfacl file %s, incorrect POSIX acl tagtype (%u).\n", | ||
4640 | 3099 | src, (unsigned int)tagtype ); | ||
4641 | 3100 | SAFE_FREE(retbuf); | ||
4642 | 3101 | return 1; | ||
4643 | 3102 | } | ||
4644 | 3103 | |||
4645 | 3104 | d_printf("%s\n", perms_to_string(permstring, perms)); | ||
4646 | 3105 | } | ||
4647 | 3106 | |||
4648 | 3107 | SAFE_FREE(retbuf); | ||
4649 | 3108 | return 0; | ||
4650 | 3109 | } | ||
4651 | 3110 | |||
4652 | 3111 | /**************************************************************************** | ||
4653 | 3112 | UNIX stat. | ||
4654 | 3113 | ****************************************************************************/ | ||
4655 | 3114 | |||
4656 | 3115 | static int cmd_stat(void) | ||
4657 | 3116 | { | ||
4658 | 3117 | TALLOC_CTX *ctx = talloc_tos(); | ||
4659 | 3118 | char *src = NULL; | ||
4660 | 3119 | char *name = NULL; | ||
4661 | 3120 | char *targetname = NULL; | ||
4662 | 3121 | struct cli_state *targetcli; | ||
4663 | 3122 | fstring mode_str; | ||
4664 | 3123 | SMB_STRUCT_STAT sbuf; | ||
4665 | 3124 | struct tm *lt; | ||
4666 | 3125 | |||
4667 | 3126 | if (!next_token_talloc(ctx, &cmd_ptr,&name,NULL)) { | ||
4668 | 3127 | d_printf("stat file\n"); | ||
4669 | 3128 | return 1; | ||
4670 | 3129 | } | ||
4671 | 3130 | src = talloc_asprintf(ctx, | ||
4672 | 3131 | "%s%s", | ||
4673 | 3132 | client_get_cur_dir(), | ||
4674 | 3133 | name); | ||
4675 | 3134 | if (!src) { | ||
4676 | 3135 | return 1; | ||
4677 | 3136 | } | ||
4678 | 3137 | |||
4679 | 3138 | if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) { | ||
4680 | 3139 | d_printf("stat %s: %s\n", src, cli_errstr(cli)); | ||
4681 | 3140 | return 1; | ||
4682 | 3141 | } | ||
4683 | 3142 | |||
4684 | 3143 | if (!SERVER_HAS_UNIX_CIFS(targetcli)) { | ||
4685 | 3144 | d_printf("Server doesn't support UNIX CIFS calls.\n"); | ||
4686 | 3145 | return 1; | ||
4687 | 3146 | } | ||
4688 | 3147 | |||
4689 | 3148 | if (!cli_unix_stat(targetcli, targetname, &sbuf)) { | ||
4690 | 3149 | d_printf("%s stat file %s\n", | ||
4691 | 3150 | cli_errstr(targetcli), src); | ||
4692 | 3151 | return 1; | ||
4693 | 3152 | } | ||
4694 | 3153 | |||
4695 | 3154 | /* Print out the stat values. */ | ||
4696 | 3155 | d_printf("File: %s\n", src); | ||
4697 | 3156 | d_printf("Size: %-12.0f\tBlocks: %u\t%s\n", | ||
4698 | 3157 | (double)sbuf.st_size, | ||
4699 | 3158 | (unsigned int)sbuf.st_blocks, | ||
4700 | 3159 | filetype_to_str(sbuf.st_mode)); | ||
4701 | 3160 | |||
4702 | 3161 | #if defined(S_ISCHR) && defined(S_ISBLK) | ||
4703 | 3162 | if (S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode)) { | ||
4704 | 3163 | d_printf("Inode: %.0f\tLinks: %u\tDevice type: %u,%u\n", | ||
4705 | 3164 | (double)sbuf.st_ino, | ||
4706 | 3165 | (unsigned int)sbuf.st_nlink, | ||
4707 | 3166 | unix_dev_major(sbuf.st_rdev), | ||
4708 | 3167 | unix_dev_minor(sbuf.st_rdev)); | ||
4709 | 3168 | } else | ||
4710 | 3169 | #endif | ||
4711 | 3170 | d_printf("Inode: %.0f\tLinks: %u\n", | ||
4712 | 3171 | (double)sbuf.st_ino, | ||
4713 | 3172 | (unsigned int)sbuf.st_nlink); | ||
4714 | 3173 | |||
4715 | 3174 | d_printf("Access: (0%03o/%s)\tUid: %u\tGid: %u\n", | ||
4716 | 3175 | ((int)sbuf.st_mode & 0777), | ||
4717 | 3176 | unix_mode_to_str(mode_str, sbuf.st_mode), | ||
4718 | 3177 | (unsigned int)sbuf.st_uid, | ||
4719 | 3178 | (unsigned int)sbuf.st_gid); | ||
4720 | 3179 | |||
4721 | 3180 | lt = localtime(&sbuf.st_atime); | ||
4722 | 3181 | if (lt) { | ||
4723 | 3182 | strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt); | ||
4724 | 3183 | } else { | ||
4725 | 3184 | fstrcpy(mode_str, "unknown"); | ||
4726 | 3185 | } | ||
4727 | 3186 | d_printf("Access: %s\n", mode_str); | ||
4728 | 3187 | |||
4729 | 3188 | lt = localtime(&sbuf.st_mtime); | ||
4730 | 3189 | if (lt) { | ||
4731 | 3190 | strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt); | ||
4732 | 3191 | } else { | ||
4733 | 3192 | fstrcpy(mode_str, "unknown"); | ||
4734 | 3193 | } | ||
4735 | 3194 | d_printf("Modify: %s\n", mode_str); | ||
4736 | 3195 | |||
4737 | 3196 | lt = localtime(&sbuf.st_ctime); | ||
4738 | 3197 | if (lt) { | ||
4739 | 3198 | strftime(mode_str, sizeof(mode_str), "%Y-%m-%d %T %z", lt); | ||
4740 | 3199 | } else { | ||
4741 | 3200 | fstrcpy(mode_str, "unknown"); | ||
4742 | 3201 | } | ||
4743 | 3202 | d_printf("Change: %s\n", mode_str); | ||
4744 | 3203 | |||
4745 | 3204 | return 0; | ||
4746 | 3205 | } | ||
4747 | 3206 | |||
4748 | 3207 | |||
4749 | 3208 | /**************************************************************************** | ||
4750 | 3209 | UNIX chown. | ||
4751 | 3210 | ****************************************************************************/ | ||
4752 | 3211 | |||
4753 | 3212 | static int cmd_chown(void) | ||
4754 | 3213 | { | ||
4755 | 3214 | TALLOC_CTX *ctx = talloc_tos(); | ||
4756 | 3215 | char *src = NULL; | ||
4757 | 3216 | uid_t uid; | ||
4758 | 3217 | gid_t gid; | ||
4759 | 3218 | char *buf, *buf2, *buf3; | ||
4760 | 3219 | struct cli_state *targetcli; | ||
4761 | 3220 | char *targetname = NULL; | ||
4762 | 3221 | |||
4763 | 3222 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) || | ||
4764 | 3223 | !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL) || | ||
4765 | 3224 | !next_token_talloc(ctx, &cmd_ptr,&buf3,NULL)) { | ||
4766 | 3225 | d_printf("chown uid gid file\n"); | ||
4767 | 3226 | return 1; | ||
4768 | 3227 | } | ||
4769 | 3228 | |||
4770 | 3229 | uid = (uid_t)atoi(buf); | ||
4771 | 3230 | gid = (gid_t)atoi(buf2); | ||
4772 | 3231 | |||
4773 | 3232 | src = talloc_asprintf(ctx, | ||
4774 | 3233 | "%s%s", | ||
4775 | 3234 | client_get_cur_dir(), | ||
4776 | 3235 | buf3); | ||
4777 | 3236 | if (!src) { | ||
4778 | 3237 | return 1; | ||
4779 | 3238 | } | ||
4780 | 3239 | if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname) ) { | ||
4781 | 3240 | d_printf("chown %s: %s\n", src, cli_errstr(cli)); | ||
4782 | 3241 | return 1; | ||
4783 | 3242 | } | ||
4784 | 3243 | |||
4785 | 3244 | if (!SERVER_HAS_UNIX_CIFS(targetcli)) { | ||
4786 | 3245 | d_printf("Server doesn't support UNIX CIFS calls.\n"); | ||
4787 | 3246 | return 1; | ||
4788 | 3247 | } | ||
4789 | 3248 | |||
4790 | 3249 | if (!cli_unix_chown(targetcli, targetname, uid, gid)) { | ||
4791 | 3250 | d_printf("%s chown file %s uid=%d, gid=%d\n", | ||
4792 | 3251 | cli_errstr(targetcli), src, (int)uid, (int)gid); | ||
4793 | 3252 | return 1; | ||
4794 | 3253 | } | ||
4795 | 3254 | |||
4796 | 3255 | return 0; | ||
4797 | 3256 | } | ||
4798 | 3257 | |||
4799 | 3258 | /**************************************************************************** | ||
4800 | 3259 | Rename some file. | ||
4801 | 3260 | ****************************************************************************/ | ||
4802 | 3261 | |||
4803 | 3262 | static int cmd_rename(void) | ||
4804 | 3263 | { | ||
4805 | 3264 | TALLOC_CTX *ctx = talloc_tos(); | ||
4806 | 3265 | char *src, *dest; | ||
4807 | 3266 | char *buf, *buf2; | ||
4808 | 3267 | struct cli_state *targetcli; | ||
4809 | 3268 | char *targetsrc; | ||
4810 | 3269 | char *targetdest; | ||
4811 | 3270 | |||
4812 | 3271 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) || | ||
4813 | 3272 | !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) { | ||
4814 | 3273 | d_printf("rename <src> <dest>\n"); | ||
4815 | 3274 | return 1; | ||
4816 | 3275 | } | ||
4817 | 3276 | |||
4818 | 3277 | src = talloc_asprintf(ctx, | ||
4819 | 3278 | "%s%s", | ||
4820 | 3279 | client_get_cur_dir(), | ||
4821 | 3280 | buf); | ||
4822 | 3281 | if (!src) { | ||
4823 | 3282 | return 1; | ||
4824 | 3283 | } | ||
4825 | 3284 | |||
4826 | 3285 | dest = talloc_asprintf(ctx, | ||
4827 | 3286 | "%s%s", | ||
4828 | 3287 | client_get_cur_dir(), | ||
4829 | 3288 | buf2); | ||
4830 | 3289 | if (!dest) { | ||
4831 | 3290 | return 1; | ||
4832 | 3291 | } | ||
4833 | 3292 | |||
4834 | 3293 | if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetsrc)) { | ||
4835 | 3294 | d_printf("rename %s: %s\n", src, cli_errstr(cli)); | ||
4836 | 3295 | return 1; | ||
4837 | 3296 | } | ||
4838 | 3297 | |||
4839 | 3298 | if (!cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli, &targetdest)) { | ||
4840 | 3299 | d_printf("rename %s: %s\n", dest, cli_errstr(cli)); | ||
4841 | 3300 | return 1; | ||
4842 | 3301 | } | ||
4843 | 3302 | |||
4844 | 3303 | if (!cli_rename(targetcli, targetsrc, targetdest)) { | ||
4845 | 3304 | d_printf("%s renaming files %s -> %s \n", | ||
4846 | 3305 | cli_errstr(targetcli), | ||
4847 | 3306 | targetsrc, | ||
4848 | 3307 | targetdest); | ||
4849 | 3308 | return 1; | ||
4850 | 3309 | } | ||
4851 | 3310 | |||
4852 | 3311 | return 0; | ||
4853 | 3312 | } | ||
4854 | 3313 | |||
4855 | 3314 | /**************************************************************************** | ||
4856 | 3315 | Print the volume name. | ||
4857 | 3316 | ****************************************************************************/ | ||
4858 | 3317 | |||
4859 | 3318 | static int cmd_volume(void) | ||
4860 | 3319 | { | ||
4861 | 3320 | fstring volname; | ||
4862 | 3321 | uint32 serial_num; | ||
4863 | 3322 | time_t create_date; | ||
4864 | 3323 | |||
4865 | 3324 | if (!cli_get_fs_volume_info(cli, volname, &serial_num, &create_date)) { | ||
4866 | 3325 | d_printf("Errr %s getting volume info\n",cli_errstr(cli)); | ||
4867 | 3326 | return 1; | ||
4868 | 3327 | } | ||
4869 | 3328 | |||
4870 | 3329 | d_printf("Volume: |%s| serial number 0x%x\n", | ||
4871 | 3330 | volname, (unsigned int)serial_num); | ||
4872 | 3331 | return 0; | ||
4873 | 3332 | } | ||
4874 | 3333 | |||
4875 | 3334 | /**************************************************************************** | ||
4876 | 3335 | Hard link files using the NT call. | ||
4877 | 3336 | ****************************************************************************/ | ||
4878 | 3337 | |||
4879 | 3338 | static int cmd_hardlink(void) | ||
4880 | 3339 | { | ||
4881 | 3340 | TALLOC_CTX *ctx = talloc_tos(); | ||
4882 | 3341 | char *src, *dest; | ||
4883 | 3342 | char *buf, *buf2; | ||
4884 | 3343 | struct cli_state *targetcli; | ||
4885 | 3344 | char *targetname; | ||
4886 | 3345 | |||
4887 | 3346 | if (!next_token_talloc(ctx, &cmd_ptr,&buf,NULL) || | ||
4888 | 3347 | !next_token_talloc(ctx, &cmd_ptr,&buf2,NULL)) { | ||
4889 | 3348 | d_printf("hardlink <src> <dest>\n"); | ||
4890 | 3349 | return 1; | ||
4891 | 3350 | } | ||
4892 | 3351 | |||
4893 | 3352 | src = talloc_asprintf(ctx, | ||
4894 | 3353 | "%s%s", | ||
4895 | 3354 | client_get_cur_dir(), | ||
4896 | 3355 | buf); | ||
4897 | 3356 | if (!src) { | ||
4898 | 3357 | return 1; | ||
4899 | 3358 | } | ||
4900 | 3359 | |||
4901 | 3360 | dest = talloc_asprintf(ctx, | ||
4902 | 3361 | "%s%s", | ||
4903 | 3362 | client_get_cur_dir(), | ||
4904 | 3363 | buf2); | ||
4905 | 3364 | if (!dest) { | ||
4906 | 3365 | return 1; | ||
4907 | 3366 | } | ||
4908 | 3367 | |||
4909 | 3368 | if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) { | ||
4910 | 3369 | d_printf("hardlink %s: %s\n", src, cli_errstr(cli)); | ||
4911 | 3370 | return 1; | ||
4912 | 3371 | } | ||
4913 | 3372 | |||
4914 | 3373 | if (!cli_nt_hardlink(targetcli, targetname, dest)) { | ||
4915 | 3374 | d_printf("%s doing an NT hard link of files\n",cli_errstr(targetcli)); | ||
4916 | 3375 | return 1; | ||
4917 | 3376 | } | ||
4918 | 3377 | |||
4919 | 3378 | return 0; | ||
4920 | 3379 | } | ||
4921 | 3380 | |||
4922 | 3381 | /**************************************************************************** | ||
4923 | 3382 | Toggle the prompt flag. | ||
4924 | 3383 | ****************************************************************************/ | ||
4925 | 3384 | |||
4926 | 3385 | static int cmd_prompt(void) | ||
4927 | 3386 | { | ||
4928 | 3387 | prompt = !prompt; | ||
4929 | 3388 | DEBUG(2,("prompting is now %s\n",prompt?"on":"off")); | ||
4930 | 3389 | return 1; | ||
4931 | 3390 | } | ||
4932 | 3391 | |||
4933 | 3392 | /**************************************************************************** | ||
4934 | 3393 | Set the newer than time. | ||
4935 | 3394 | ****************************************************************************/ | ||
4936 | 3395 | |||
4937 | 3396 | static int cmd_newer(void) | ||
4938 | 3397 | { | ||
4939 | 3398 | TALLOC_CTX *ctx = talloc_tos(); | ||
4940 | 3399 | char *buf; | ||
4941 | 3400 | bool ok; | ||
4942 | 3401 | SMB_STRUCT_STAT sbuf; | ||
4943 | 3402 | |||
4944 | 3403 | ok = next_token_talloc(ctx, &cmd_ptr,&buf,NULL); | ||
4945 | 3404 | if (ok && (sys_stat(buf,&sbuf) == 0)) { | ||
4946 | 3405 | newer_than = sbuf.st_mtime; | ||
4947 | 3406 | DEBUG(1,("Getting files newer than %s", | ||
4948 | 3407 | time_to_asc(newer_than))); | ||
4949 | 3408 | } else { | ||
4950 | 3409 | newer_than = 0; | ||
4951 | 3410 | } | ||
4952 | 3411 | |||
4953 | 3412 | if (ok && newer_than == 0) { | ||
4954 | 3413 | d_printf("Error setting newer-than time\n"); | ||
4955 | 3414 | return 1; | ||
4956 | 3415 | } | ||
4957 | 3416 | |||
4958 | 3417 | return 0; | ||
4959 | 3418 | } | ||
4960 | 3419 | |||
4961 | 3420 | /**************************************************************************** | ||
4962 | 3421 | Set the archive level. | ||
4963 | 3422 | ****************************************************************************/ | ||
4964 | 3423 | |||
4965 | 3424 | static int cmd_archive(void) | ||
4966 | 3425 | { | ||
4967 | 3426 | TALLOC_CTX *ctx = talloc_tos(); | ||
4968 | 3427 | char *buf; | ||
4969 | 3428 | |||
4970 | 3429 | if (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) { | ||
4971 | 3430 | archive_level = atoi(buf); | ||
4972 | 3431 | } else { | ||
4973 | 3432 | d_printf("Archive level is %d\n",archive_level); | ||
4974 | 3433 | } | ||
4975 | 3434 | |||
4976 | 3435 | return 0; | ||
4977 | 3436 | } | ||
4978 | 3437 | |||
4979 | 3438 | /**************************************************************************** | ||
4980 | 3439 | Toggle the lowercaseflag. | ||
4981 | 3440 | ****************************************************************************/ | ||
4982 | 3441 | |||
4983 | 3442 | static int cmd_lowercase(void) | ||
4984 | 3443 | { | ||
4985 | 3444 | lowercase = !lowercase; | ||
4986 | 3445 | DEBUG(2,("filename lowercasing is now %s\n",lowercase?"on":"off")); | ||
4987 | 3446 | return 0; | ||
4988 | 3447 | } | ||
4989 | 3448 | |||
4990 | 3449 | /**************************************************************************** | ||
4991 | 3450 | Toggle the case sensitive flag. | ||
4992 | 3451 | ****************************************************************************/ | ||
4993 | 3452 | |||
4994 | 3453 | static int cmd_setcase(void) | ||
4995 | 3454 | { | ||
4996 | 3455 | bool orig_case_sensitive = cli_set_case_sensitive(cli, false); | ||
4997 | 3456 | |||
4998 | 3457 | cli_set_case_sensitive(cli, !orig_case_sensitive); | ||
4999 | 3458 | DEBUG(2,("filename case sensitivity is now %s\n",!orig_case_sensitive ? | ||
5000 | 3459 | "on":"off")); |
The diff has been truncated for viewing.