a65c786c24df1fad094607b6dbc4b26a25b417c0
[kseeger/samba-autobuild-v4-14-test/.git] / source3 / smbd / proto.h
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Main SMB server routines
4  *
5  *  Copyright (C) Andrew Tridgell                       1992-2002,2006
6  *  Copyright (C) Jeremy Allison                        1992-2010
7  *  Copyright (C) Volker Lendecke                       1993-2009
8  *  Copyright (C) John H Terpstra                       1995-1998
9  *  Copyright (C) Luke Kenneth Casson Leighton          1996-1998
10  *  Copyright (C) Paul Ashton                           1997-1998
11  *  Copyright (C) Tim Potter                            1999-2000
12  *  Copyright (C) T.D.Lee@durham.ac.uk                  1999
13  *  Copyright (C) Ying Chen                             2000
14  *  Copyright (C) Shirish Kalele                        2000
15  *  Copyright (C) Andrew Bartlett                       2001-2003
16  *  Copyright (C) Alexander Bokovoy                     2002,2005
17  *  Copyright (C) Simo Sorce                            2001-2002,2009
18  *  Copyright (C) Andreas Gruenbacher                   2002
19  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>       2002
20  *  Copyright (C) Martin Pool                           2002
21  *  Copyright (C) Luke Howard                           2003
22  *  Copyright (C) Stefan (metze) Metzmacher             2003,2009
23  *  Copyright (C) Steve French                          2005
24  *  Copyright (C) Gerald (Jerry) Carter                 2006
25  *  Copyright (C) James Peach                           2006-2007
26  *  Copyright (C) Jelmer Vernooij                       2002-2003
27  *  Copyright (C) Michael Adam                          2007
28  *  Copyright (C) Rishi Srivatsavai                     2007
29  *  Copyright (C) Tim Prouty                            2009
30  *  Copyright (C) Gregor Beck                           2011
31  *
32  *  This program is free software; you can redistribute it and/or modify
33  *  it under the terms of the GNU General Public License as published by
34  *  the Free Software Foundation; either version 3 of the License, or
35  *  (at your option) any later version.
36  *
37  *  This program is distributed in the hope that it will be useful,
38  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
39  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40  *  GNU General Public License for more details.
41  *
42  *  You should have received a copy of the GNU General Public License
43  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
44  */
45
46 #ifndef _SMBD_PROTO_H_
47 #define _SMBD_PROTO_H_
48
49 /* The following definitions come from smbd/signing.c  */
50
51 struct smbXsrv_client;
52 struct smbXsrv_connection;
53 struct dcesrv_context;
54
55 bool srv_check_sign_mac(struct smbXsrv_connection *conn,
56                         const char *inbuf, uint32_t *seqnum, bool trusted_channel);
57 NTSTATUS srv_calculate_sign_mac(struct smbXsrv_connection *conn,
58                                 char *outbuf, uint32_t seqnum);
59 void srv_cancel_sign_response(struct smbXsrv_connection *conn);
60 bool srv_init_signing(struct smbXsrv_connection *conn);
61 void srv_set_signing_negotiated(struct smbXsrv_connection *conn,
62                                 bool allowed, bool mandatory);
63 bool srv_is_signing_active(struct smbXsrv_connection *conn);
64 bool srv_is_signing_negotiated(struct smbXsrv_connection *conn);
65 void srv_set_signing(struct smbXsrv_connection *conn,
66                      const DATA_BLOB user_session_key,
67                      const DATA_BLOB response);
68
69 /* The following definitions come from smbd/aio.c  */
70
71 struct aio_extra;
72 bool aio_write_through_requested(struct aio_extra *aio_ex);
73 NTSTATUS schedule_aio_read_and_X(connection_struct *conn,
74                              struct smb_request *req,
75                              files_struct *fsp, off_t startpos,
76                              size_t smb_maxcnt);
77 NTSTATUS schedule_aio_write_and_X(connection_struct *conn,
78                               struct smb_request *req,
79                               files_struct *fsp, const char *data,
80                               off_t startpos,
81                               size_t numtowrite);
82 NTSTATUS schedule_smb2_aio_read(connection_struct *conn,
83                                 struct smb_request *smbreq,
84                                 files_struct *fsp,
85                                 TALLOC_CTX *ctx,
86                                 DATA_BLOB *preadbuf,
87                                 off_t startpos,
88                                 size_t smb_maxcnt);
89 NTSTATUS schedule_aio_smb2_write(connection_struct *conn,
90                                 struct smb_request *smbreq,
91                                 files_struct *fsp,
92                                 uint64_t in_offset,
93                                 DATA_BLOB in_data,
94                                 bool write_through);
95 bool cancel_smb2_aio(struct smb_request *smbreq);
96 bool aio_add_req_to_fsp(files_struct *fsp, struct tevent_req *req);
97
98 /* The following definitions come from smbd/blocking.c  */
99
100 NTSTATUS smbd_do_locks_try(
101         struct files_struct *fsp,
102         enum brl_flavour lock_flav,
103         uint16_t num_locks,
104         struct smbd_lock_element *locks,
105         uint16_t *blocker_idx,
106         struct server_id *blocking_pid,
107         uint64_t *blocking_smblctx);
108 struct tevent_req *smbd_smb1_do_locks_send(
109         TALLOC_CTX *mem_ctx,
110         struct tevent_context *ev,
111         struct smb_request **smbreq, /* talloc_move()d into our state */
112         struct files_struct *fsp,
113         uint32_t lock_timeout,
114         bool large_offset,
115         enum brl_flavour lock_flav,
116         uint16_t num_locks,
117         struct smbd_lock_element *locks);
118 NTSTATUS smbd_smb1_do_locks_recv(struct tevent_req *req);
119 bool smbd_smb1_do_locks_extract_smbreq(
120         struct tevent_req *req,
121         TALLOC_CTX *mem_ctx,
122         struct smb_request **psmbreq);
123 void smbd_smb1_brl_finish_by_req(struct tevent_req *req, NTSTATUS status);
124 bool smbd_smb1_brl_finish_by_lock(
125         struct files_struct *fsp,
126         bool large_offset,
127         enum brl_flavour lock_flav,
128         struct smbd_lock_element lock,
129         NTSTATUS finish_status);
130 bool smbd_smb1_brl_finish_by_mid(
131         struct smbd_server_connection *sconn, uint64_t mid);
132
133 /* The following definitions come from smbd/close.c  */
134
135 void set_close_write_time(struct files_struct *fsp, struct timespec ts);
136 NTSTATUS close_file(struct smb_request *req, files_struct *fsp,
137                     enum file_close_type close_type);
138 void msg_close_file(struct messaging_context *msg_ctx,
139                     void *private_data,
140                     uint32_t msg_type,
141                     struct server_id server_id,
142                     DATA_BLOB *data);
143 NTSTATUS delete_all_streams(connection_struct *conn,
144                         const struct smb_filename *smb_fname);
145 bool recursive_rmdir(TALLOC_CTX *ctx,
146                      connection_struct *conn,
147                      struct smb_filename *smb_dname);
148 bool has_other_nonposix_opens(struct share_mode_lock *lck,
149                               struct files_struct *fsp);
150
151 /* The following definitions come from smbd/conn.c  */
152
153 int conn_num_open(struct smbd_server_connection *sconn);
154 bool conn_snum_used(struct smbd_server_connection *sconn, int snum);
155 connection_struct *conn_new(struct smbd_server_connection *sconn);
156 bool conn_idle_all(struct smbd_server_connection *sconn, time_t t);
157 void conn_clear_vuid_caches(struct smbd_server_connection *sconn, uint64_t vuid);
158 void conn_free(connection_struct *conn);
159 void conn_setup_case_options(connection_struct *conn);
160 void conn_force_tdis(
161         struct smbd_server_connection *sconn,
162         bool (*check_fn)(struct connection_struct *conn,
163                          void *private_data),
164         void *private_data);
165 void msg_force_tdis(struct messaging_context *msg,
166                     void *private_data,
167                     uint32_t msg_type,
168                     struct server_id server_id,
169                     DATA_BLOB *data);
170 void msg_force_tdis_denied(
171         struct messaging_context *msg,
172         void *private_data,
173         uint32_t msg_type,
174         struct server_id server_id,
175         DATA_BLOB *data);
176
177 /* The following definitions come from smbd/connection.c  */
178
179 int count_current_connections(const char *sharename, bool verify);
180 bool connections_snum_used(struct smbd_server_connection *unused, int snum);
181
182 /* The following definitions come from smbd/dfree.c  */
183
184 uint64_t get_dfree_info(connection_struct *conn, struct smb_filename *fname,
185                         uint64_t *bsize, uint64_t *dfree, uint64_t *dsize);
186 void flush_dfree_cache(void);
187
188 /* The following definitions come from smbd/dir.c  */
189
190 bool init_dptrs(struct smbd_server_connection *sconn);
191 const char *dptr_path(struct smbd_server_connection *sconn, int key);
192 const char *dptr_wcard(struct smbd_server_connection *sconn, int key);
193 uint16_t dptr_attr(struct smbd_server_connection *sconn, int key);
194 void dptr_closecnum(connection_struct *conn);
195 NTSTATUS dptr_create(connection_struct *conn,
196                 struct smb_request *req,
197                 files_struct *fsp,
198                 bool old_handle,
199                 bool expect_close,
200                 uint16_t spid,
201                 const char *wcard,
202                 uint32_t attr,
203                 struct dptr_struct **dptr_ret);
204 void dptr_CloseDir(files_struct *fsp);
205 void dptr_SeekDir(struct dptr_struct *dptr, long offset);
206 long dptr_TellDir(struct dptr_struct *dptr);
207 bool dptr_has_wild(struct dptr_struct *dptr);
208 int dptr_dnum(struct dptr_struct *dptr);
209 bool dptr_get_priv(struct dptr_struct *dptr);
210 void dptr_set_priv(struct dptr_struct *dptr);
211 bool dptr_SearchDir(struct dptr_struct *dptr, const char *name, long *poffset, SMB_STRUCT_STAT *pst);
212 bool dptr_fill(struct smbd_server_connection *sconn,
213                char *buf1,unsigned int key);
214 files_struct *dptr_fetch_fsp(struct smbd_server_connection *sconn,
215                                char *buf,int *num);
216 files_struct *dptr_fetch_lanman2_fsp(struct smbd_server_connection *sconn,
217                                        int dptr_num);
218 bool get_dir_entry(TALLOC_CTX *ctx,
219                 struct dptr_struct *dirptr,
220                 const char *mask,
221                 uint32_t dirtype,
222                 char **pp_fname_out,
223                 off_t *size,
224                 uint32_t *mode,
225                 struct timespec *date,
226                 bool check_descend,
227                 bool ask_sharemode);
228 struct smb_Dir;
229 bool is_visible_file(connection_struct *conn,
230                 struct smb_Dir *dir_hnd,
231                 const char *name,
232                 SMB_STRUCT_STAT *pst,
233                 bool use_veto);
234 struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx,
235                         connection_struct *conn,
236                         const struct smb_filename *smb_fname,
237                         const char *mask,
238                         uint32_t attr);
239 const char *ReadDirName(struct smb_Dir *dir_hnd, long *poffset,
240                         SMB_STRUCT_STAT *sbuf, char **talloced);
241 void RewindDir(struct smb_Dir *dir_hnd, long *poffset);
242 void SeekDir(struct smb_Dir *dirp, long offset);
243 long TellDir(struct smb_Dir *dirp);
244 bool SearchDir(struct smb_Dir *dirp, const char *name, long *poffset);
245 NTSTATUS can_delete_directory(struct connection_struct *conn,
246                                 const char *dirname);
247 bool have_file_open_below(connection_struct *conn,
248                         const struct smb_filename *name);
249
250 /* The following definitions come from smbd/dmapi.c  */
251
252 const void *dmapi_get_current_session(void);
253 bool dmapi_have_session(void);
254 bool dmapi_new_session(void);
255 bool dmapi_destroy_session(void);
256 uint32_t dmapi_file_flags(const char * const path);
257
258 /* The following definitions come from smbd/dnsregister.c  */
259
260 bool smbd_setup_mdns_registration(struct tevent_context *ev,
261                                   TALLOC_CTX *mem_ctx,
262                                   uint16_t port);
263
264 /* The following definitions come from smbd/dosmode.c  */
265
266 mode_t unix_mode(connection_struct *conn, int dosmode,
267                  const struct smb_filename *smb_fname,
268                  struct smb_filename *smb_fname_parent);
269 uint32_t dos_mode_msdfs(connection_struct *conn,
270                       const struct smb_filename *smb_fname);
271 uint32_t fdos_mode(struct files_struct *fsp);
272 struct tevent_req *dos_mode_at_send(TALLOC_CTX *mem_ctx,
273                                     struct tevent_context *ev,
274                                     files_struct *dir_fsp,
275                                     struct smb_filename *smb_fname);
276 NTSTATUS dos_mode_at_recv(struct tevent_req *req, uint32_t *dosmode);
277 int file_set_dosmode(connection_struct *conn,
278                      struct smb_filename *smb_fname,
279                      uint32_t dosmode,
280                      struct smb_filename *parent_dir,
281                      bool newfile);
282 NTSTATUS file_set_sparse(connection_struct *conn,
283                          struct files_struct *fsp,
284                          bool sparse);
285 int file_ntimes(connection_struct *conn, const struct smb_filename *smb_fname,
286                 struct smb_file_time *ft);
287 bool set_sticky_write_time_path(struct file_id fileid, struct timespec mtime);
288 bool set_sticky_write_time_fsp(struct files_struct *fsp,
289                                struct timespec mtime);
290
291 NTSTATUS fget_ea_dos_attribute(struct files_struct *fsp,
292                               uint32_t *pattr);
293 NTSTATUS set_ea_dos_attribute(connection_struct *conn,
294                               const struct smb_filename *smb_fname,
295                               uint32_t dosmode);
296
297 NTSTATUS set_create_timespec_ea(connection_struct *conn,
298                                 const struct smb_filename *smb_fname,
299                                 struct timespec create_time);
300
301 struct timespec get_create_timespec(connection_struct *conn,
302                                 struct files_struct *fsp,
303                                 const struct smb_filename *smb_fname);
304
305 struct timespec get_change_timespec(connection_struct *conn,
306                                 struct files_struct *fsp,
307                                 const struct smb_filename *smb_fname);
308
309 NTSTATUS parse_dos_attribute_blob(struct smb_filename *smb_fname,
310                                   DATA_BLOB blob,
311                                   uint32_t *pattr);
312
313 /* The following definitions come from smbd/error.c  */
314
315 bool use_nt_status(void);
316 void error_packet_set(char *outbuf, uint8_t eclass, uint32_t ecode, NTSTATUS ntstatus, int line, const char *file);
317 size_t error_packet(char *outbuf,
318                     uint8_t eclass,
319                     uint32_t ecode,
320                     NTSTATUS ntstatus,
321                     int line,
322                     const char *file);
323 void reply_nt_error(struct smb_request *req, NTSTATUS ntstatus,
324                     int line, const char *file);
325 void reply_force_dos_error(struct smb_request *req, uint8_t eclass, uint32_t ecode,
326                     int line, const char *file);
327 void reply_both_error(struct smb_request *req, uint8_t eclass, uint32_t ecode,
328                       NTSTATUS status, int line, const char *file);
329 void reply_openerror(struct smb_request *req, NTSTATUS status);
330
331 /* The following definitions come from smbd/file_access.c  */
332
333 bool can_delete_file_in_directory(connection_struct *conn,
334                         struct files_struct *dirfsp,
335                         const struct smb_filename *smb_fname);
336 bool can_write_to_file(connection_struct *conn,
337                         struct files_struct *dirfsp,
338                         const struct smb_filename *smb_fname);
339 bool directory_has_default_acl(connection_struct *conn,
340                         struct files_struct *dirfsp,
341                         struct smb_filename *smb_fname);
342 NTSTATUS can_set_delete_on_close(files_struct *fsp, uint32_t dosmode);
343
344 /* The following definitions come from smbd/fileio.c  */
345
346 ssize_t read_file(files_struct *fsp,char *data,off_t pos,size_t n);
347 void fsp_flush_write_time_update(struct files_struct *fsp);
348 void trigger_write_time_update(struct files_struct *fsp);
349 void trigger_write_time_update_immediate(struct files_struct *fsp);
350 void mark_file_modified(files_struct *fsp);
351 ssize_t write_file(struct smb_request *req,
352                         files_struct *fsp,
353                         const char *data,
354                         off_t pos,
355                         size_t n);
356 NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_through);
357
358 /* The following definitions come from smbd/filename.c  */
359
360 uint32_t ucf_flags_from_smb_request(struct smb_request *req);
361 uint32_t filename_create_ucf_flags(struct smb_request *req, uint32_t create_disposition);
362 NTSTATUS unix_convert(TALLOC_CTX *ctx,
363                       connection_struct *conn,
364                       const char *orig_path,
365                       NTTIME twrp,
366                       struct smb_filename **smb_fname,
367                       uint32_t ucf_flags);
368 NTSTATUS check_name(connection_struct *conn,
369                         const struct smb_filename *smb_fname);
370 NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname,
371                                     uint32_t ucf_flags,
372                                     NTTIME twrp);
373 int get_real_filename(connection_struct *conn,
374                       struct smb_filename *path,
375                       const char *name,
376                       TALLOC_CTX *mem_ctx,
377                       char **found_name);
378 int get_real_filename_full_scan(connection_struct *conn,
379                                 const char *path,
380                                 const char *name,
381                                 bool mangled,
382                                 TALLOC_CTX *mem_ctx,
383                                 char **found_name);
384 char *get_original_lcomp(TALLOC_CTX *ctx,
385                         connection_struct *conn,
386                         const char *filename_in,
387                         uint32_t ucf_flags);
388 NTSTATUS filename_convert(TALLOC_CTX *mem_ctx,
389                         connection_struct *conn,
390                         const char *name_in,
391                         uint32_t ucf_flags,
392                         NTTIME twrp,
393                         struct smb_filename **pp_smb_fname);
394 NTSTATUS filename_convert_with_privilege(TALLOC_CTX *mem_ctx,
395                         connection_struct *conn,
396                         struct smb_request *smbreq,
397                         const char *name_in,
398                         uint32_t ucf_flags,
399                         struct smb_filename **pp_smb_fname);
400
401 /* The following definitions come from smbd/files.c  */
402
403 NTSTATUS fsp_new(struct connection_struct *conn, TALLOC_CTX *mem_ctx,
404                  files_struct **result);
405 void fsp_set_gen_id(files_struct *fsp);
406 NTSTATUS file_new(struct smb_request *req, connection_struct *conn,
407                   files_struct **result);
408 NTSTATUS fsp_bind_smb(struct files_struct *fsp, struct smb_request *req);
409 void file_close_conn(connection_struct *conn);
410 bool file_init_global(void);
411 bool file_init(struct smbd_server_connection *sconn);
412 void file_close_user(struct smbd_server_connection *sconn, uint64_t vuid);
413 struct files_struct *files_forall(
414         struct smbd_server_connection *sconn,
415         struct files_struct *(*fn)(struct files_struct *fsp,
416                                    void *private_data),
417         void *private_data);
418 files_struct *file_find_fd(struct smbd_server_connection *sconn, int fd);
419 files_struct *file_find_dif(struct smbd_server_connection *sconn,
420                             struct file_id id, unsigned long gen_id);
421 files_struct *file_find_di_first(struct smbd_server_connection *sconn,
422                                  struct file_id id,
423                                  bool need_fsa);
424 files_struct *file_find_di_next(files_struct *start_fsp,
425                                  bool need_fsa);
426 struct files_struct *file_find_one_fsp_from_lease_key(
427         struct smbd_server_connection *sconn,
428         const struct smb2_lease_key *lease_key);
429 bool file_find_subpath(files_struct *dir_fsp);
430 void file_free(struct smb_request *req, files_struct *fsp);
431 files_struct *file_fsp(struct smb_request *req, uint16_t fid);
432 struct files_struct *file_fsp_get(struct smbd_smb2_request *smb2req,
433                                   uint64_t persistent_id,
434                                   uint64_t volatile_id);
435 struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
436                                    uint64_t persistent_id,
437                                    uint64_t volatile_id);
438 NTSTATUS dup_file_fsp(
439         struct smb_request *req,
440         files_struct *from,
441         uint32_t access_mask,
442         uint32_t create_options,
443         files_struct *to);
444 NTSTATUS file_name_hash(connection_struct *conn,
445                         const char *name, uint32_t *p_name_hash);
446 NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
447                            const struct smb_filename *smb_fname_in);
448 size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen);
449 void fsp_set_base_fsp(struct files_struct *fsp, struct files_struct *base_fsp);
450
451 NTSTATUS create_internal_fsp(connection_struct *conn,
452                              const struct smb_filename *smb_fname,
453                              struct files_struct **_fsp);
454 NTSTATUS create_internal_dirfsp(connection_struct *conn,
455                                 const struct smb_filename *smb_dname,
456                                 struct files_struct **_fsp);
457
458 NTSTATUS open_internal_dirfsp(connection_struct *conn,
459                               const struct smb_filename *smb_dname,
460                               int open_flags,
461                               struct files_struct **_fsp);
462
463 NTSTATUS openat_pathref_fsp(const struct files_struct *dirfsp,
464                             struct smb_filename *smb_fname);
465
466 void smb_fname_fsp_unlink(struct smb_filename *smb_fname);
467
468 NTSTATUS move_smb_fname_fsp_link(struct smb_filename *smb_fname_dst,
469                                  struct smb_filename *smb_fname_src);
470
471 NTSTATUS synthetic_pathref(TALLOC_CTX *mem_ctx,
472                            struct files_struct *dirfsp,
473                            const char *base_name,
474                            const char *stream_name,
475                            const SMB_STRUCT_STAT *psbuf,
476                            NTTIME twrp,
477                            uint32_t flags,
478                            struct smb_filename **_smb_fname);
479
480 /* The following definitions come from smbd/ipc.c  */
481
482 NTSTATUS nt_status_np_pipe(NTSTATUS status);
483 void send_trans_reply(connection_struct *conn,
484                       struct smb_request *req,
485                       char *rparam, int rparam_len,
486                       char *rdata, int rdata_len,
487                       bool buffer_too_large);
488 void reply_trans(struct smb_request *req);
489 void reply_transs(struct smb_request *req);
490
491 /* The following definitions come from smbd/lanman.c  */
492
493 void api_reply(connection_struct *conn, uint64_t vuid,
494                struct smb_request *req,
495                char *data, char *params,
496                int tdscnt, int tpscnt,
497                int mdrcnt, int mprcnt);
498
499 /* The following definitions come from smbd/mangle.c  */
500
501 void mangle_reset_cache(void);
502 void mangle_change_to_posix(void);
503 bool mangle_is_mangled(const char *s, const struct share_params *p);
504 bool mangle_is_8_3(const char *fname, bool check_case,
505                    const struct share_params *p);
506 bool mangle_is_8_3_wildcards(const char *fname, bool check_case,
507                              const struct share_params *p);
508 bool mangle_must_mangle(const char *fname,
509                    const struct share_params *p);
510 bool mangle_lookup_name_from_8_3(TALLOC_CTX *ctx,
511                         const char *in,
512                         char **out, /* talloced on the given context. */
513                         const struct share_params *p);
514 bool name_to_8_3(const char *in,
515                 char out[13],
516                 bool cache83,
517                 const struct share_params *p);
518
519 /* The following definitions come from smbd/mangle_hash.c  */
520
521 const struct mangle_fns *mangle_hash_init(void);
522
523 /* The following definitions come from smbd/mangle_hash2.c  */
524
525 const struct mangle_fns *mangle_hash2_init(void);
526 const struct mangle_fns *posix_mangle_init(void);
527
528 /* The following definitions come from smbd/message.c  */
529
530 void reply_sends(struct smb_request *req);
531 void reply_sendstrt(struct smb_request *req);
532 void reply_sendtxt(struct smb_request *req);
533 void reply_sendend(struct smb_request *req);
534
535 /* The following definitions come from smbd/msdfs.c  */
536
537 bool parse_msdfs_symlink(TALLOC_CTX *ctx,
538                         bool shuffle_referrals,
539                         const char *target,
540                         struct referral **preflist,
541                         size_t *refcount);
542 bool is_msdfs_link(connection_struct *conn,
543                 struct smb_filename *smb_fname);
544 struct junction_map;
545 NTSTATUS get_referred_path(TALLOC_CTX *ctx,
546                            struct auth_session_info *session_info,
547                            const char *dfs_path,
548                            const struct tsocket_address *remote_address,
549                            const struct tsocket_address *local_address,
550                            bool allow_broken_path,
551                            struct junction_map *jucn,
552                            int *consumedcntp,
553                            bool *self_referralp);
554 int setup_dfs_referral(connection_struct *orig_conn,
555                         const char *dfs_path,
556                         int max_referral_level,
557                         char **ppdata, NTSTATUS *pstatus);
558 bool create_junction(TALLOC_CTX *ctx,
559                 const char *dfs_path,
560                 bool allow_broken_path,
561                 struct junction_map *jucn);
562 struct referral;
563 char *msdfs_link_string(TALLOC_CTX *ctx,
564                 const struct referral *reflist,
565                 size_t referral_count);
566 bool create_msdfs_link(const struct junction_map *jucn,
567                        struct auth_session_info *session_info);
568 bool remove_msdfs_link(const struct junction_map *jucn,
569                        struct auth_session_info *session_info);
570
571 struct junction_map *enum_msdfs_links(TALLOC_CTX *ctx,
572                                       struct auth_session_info *session_info,
573                                       size_t *p_num_jn);
574 NTSTATUS dfs_redirect(TALLOC_CTX *ctx,
575                         connection_struct *conn,
576                         const char *name_in,
577                         uint32_t ucf_flags,
578                         bool allow_broken_path,
579                         char **pp_name_out);
580 struct connection_struct;
581 struct smb_filename;
582 struct conn_struct_tos {
583         struct connection_struct *conn;
584         struct smb_filename *oldcwd_fname;
585 };
586 NTSTATUS create_conn_struct_tos(struct messaging_context *msg,
587                                 int snum,
588                                 const char *path,
589                                 const struct auth_session_info *session_info,
590                                 struct conn_struct_tos **_c);
591 NTSTATUS create_conn_struct_tos_cwd(struct messaging_context *msg,
592                                     int snum,
593                                     const char *path,
594                                     const struct auth_session_info *session_info,
595                                     struct conn_struct_tos **_c);
596
597 /* The following definitions come from smbd/negprot.c  */
598
599 void reply_negprot(struct smb_request *req);
600
601 /* The following definitions come from smbd/notify.c  */
602
603 bool change_notify_fsp_has_changes(struct files_struct *fsp);
604 void change_notify_reply(struct smb_request *req,
605                          NTSTATUS error_code,
606                          uint32_t max_param,
607                          struct notify_change_buf *notify_buf,
608                          void (*reply_fn)(struct smb_request *req,
609                                           NTSTATUS error_code,
610                                           uint8_t *buf, size_t len));
611 void notify_callback(struct smbd_server_connection *sconn,
612                      void *private_data, struct timespec when,
613                      const struct notify_event *e);
614 NTSTATUS change_notify_create(struct files_struct *fsp,
615                               uint32_t max_buffer_size,
616                               uint32_t filter,
617                               bool recursive);
618 NTSTATUS change_notify_add_request(struct smb_request *req,
619                                 uint32_t max_param,
620                                 uint32_t filter, bool recursive,
621                                 struct files_struct *fsp,
622                                 void (*reply_fn)(struct smb_request *req,
623                                         NTSTATUS error_code,
624                                         uint8_t *buf, size_t len));
625 void smbd_notify_cancel_deleted(struct messaging_context *msg,
626                                 void *private_data, uint32_t msg_type,
627                                 struct server_id server_id, DATA_BLOB *data);
628 void smbd_notifyd_restarted(struct messaging_context *msg,
629                             void *private_data, uint32_t msg_type,
630                             struct server_id server_id, DATA_BLOB *data);
631 bool remove_pending_change_notify_requests_by_mid(
632         struct smbd_server_connection *sconn, uint64_t mid);
633 void remove_pending_change_notify_requests_by_fid(files_struct *fsp,
634                                                   NTSTATUS status);
635 void notify_fname(connection_struct *conn, uint32_t action, uint32_t filter,
636                   const char *path);
637 char *notify_filter_string(TALLOC_CTX *mem_ctx, uint32_t filter);
638 struct sys_notify_context *sys_notify_context_create(TALLOC_CTX *mem_ctx,
639                                                      struct tevent_context *ev);
640
641 /* The following definitions come from smbd/notify_inotify.c  */
642
643 int inotify_watch(TALLOC_CTX *mem_ctx,
644                   struct sys_notify_context *ctx,
645                   const char *path,
646                   uint32_t *filter,
647                   uint32_t *subdir_filter,
648                   void (*callback)(struct sys_notify_context *ctx,
649                                    void *private_data,
650                                    struct notify_event *ev,
651                                    uint32_t filter),
652                   void *private_data,
653                   void *handle_p);
654
655 int fam_watch(TALLOC_CTX *mem_ctx,
656               struct sys_notify_context *ctx,
657               const char *path,
658               uint32_t *filter,
659               uint32_t *subdir_filter,
660               void (*callback)(struct sys_notify_context *ctx,
661                                void *private_data,
662                                struct notify_event *ev,
663                                uint32_t filter),
664               void *private_data,
665               void *handle_p);
666
667
668 /* The following definitions come from smbd/notify_internal.c  */
669
670 struct notify_context *notify_init(
671         TALLOC_CTX *mem_ctx, struct messaging_context *msg,
672         struct smbd_server_connection *sconn,
673         void (*callback)(struct smbd_server_connection *sconn,
674                          void *, struct timespec,
675                          const struct notify_event *));
676 NTSTATUS notify_add(struct notify_context *ctx,
677                     const char *path, uint32_t filter, uint32_t subdir_filter,
678                     void *private_data);
679 NTSTATUS notify_remove(struct notify_context *ctx, void *private_data,
680                        char *path);
681 void notify_trigger(struct notify_context *notify,
682                     uint32_t action, uint32_t filter,
683                     const char *dir, const char *path);
684
685 /* The following definitions come from smbd/ntquotas.c  */
686
687 NTSTATUS vfs_get_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype,
688                          struct dom_sid *psid, SMB_NTQUOTA_STRUCT *qt);
689 int vfs_set_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype, struct dom_sid *psid, SMB_NTQUOTA_STRUCT *qt);
690 int vfs_get_user_ntquota_list(files_struct *fsp, SMB_NTQUOTA_LIST **qt_list);
691 void *init_quota_handle(TALLOC_CTX *mem_ctx);
692
693 /* The following definitions come from smbd/nttrans.c  */
694
695 void reply_ntcreate_and_X(struct smb_request *req);
696 NTSTATUS set_sd(files_struct *fsp, struct security_descriptor *psd,
697                        uint32_t security_info_sent);
698 NTSTATUS set_sd_blob(files_struct *fsp, uint8_t *data, uint32_t sd_len,
699                        uint32_t security_info_sent);
700 struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size);
701 void reply_ntcancel(struct smb_request *req);
702 void reply_ntrename(struct smb_request *req);
703 NTSTATUS smbd_do_query_security_desc(connection_struct *conn,
704                                         TALLOC_CTX *mem_ctx,
705                                         files_struct *fsp,
706                                         uint32_t security_info_wanted,
707                                         uint32_t max_data_count,
708                                         uint8_t **ppmarshalled_sd,
709                                         size_t *psd_size);
710 #ifdef HAVE_SYS_QUOTAS
711
712 struct smb2_query_quota_info;
713
714 NTSTATUS smbd_do_query_getinfo_quota(TALLOC_CTX *mem_ctx,
715                                      files_struct *fsp,
716                                      bool restart_scan,
717                                      bool return_single,
718                                      uint32_t sid_list_length,
719                                      DATA_BLOB *sidbuffer,
720                                      uint32_t max_data_count,
721                                      uint8_t **p_data,
722                                      uint32_t *p_data_size);
723 #endif
724 void reply_nttrans(struct smb_request *req);
725 void reply_nttranss(struct smb_request *req);
726
727 /* The following definitions come from smbd/open.c  */
728
729 NTSTATUS smbd_check_access_rights(struct connection_struct *conn,
730                                 struct files_struct *dirfsp,
731                                 const struct smb_filename *smb_fname,
732                                 bool use_privs,
733                                 uint32_t access_mask);
734 NTSTATUS smbd_check_access_rights_fsp(struct files_struct *fsp,
735                                       bool use_privs,
736                                       uint32_t access_mask);
737 NTSTATUS check_parent_access(struct connection_struct *conn,
738                                 struct files_struct *dirfsp,
739                                 struct smb_filename *smb_fname,
740                                 uint32_t access_mask);
741 NTSTATUS fd_openat(const struct files_struct *dirfsp,
742                    struct smb_filename *smb_fname,
743                    files_struct *fsp,
744                    int flags, mode_t mode);
745 NTSTATUS fd_close(files_struct *fsp);
746 void change_file_owner_to_parent(connection_struct *conn,
747                                  struct smb_filename *inherit_from_dir,
748                                  files_struct *fsp);
749 bool is_oplock_stat_open(uint32_t access_mask);
750 bool is_lease_stat_open(uint32_t access_mask);
751 NTSTATUS send_break_message(struct messaging_context *msg_ctx,
752                             const struct file_id *id,
753                             const struct share_mode_entry *exclusive,
754                             uint16_t break_to);
755 struct deferred_open_record;
756 bool is_deferred_open_async(const struct deferred_open_record *rec);
757 bool defer_smb1_sharing_violation(struct smb_request *req);
758 NTSTATUS create_directory(connection_struct *conn, struct smb_request *req,
759                           struct smb_filename *smb_dname);
760 void msg_file_was_renamed(struct messaging_context *msg,
761                           void *private_data,
762                           uint32_t msg_type,
763                           struct server_id server_id,
764                           DATA_BLOB *data);
765 struct fsp_lease *find_fsp_lease(struct files_struct *new_fsp,
766                                  const struct smb2_lease_key *key,
767                                  uint32_t current_state,
768                                  uint16_t lease_version,
769                                  uint16_t lease_epoch);
770 NTSTATUS create_file_default(connection_struct *conn,
771                              struct smb_request *req,
772                              struct smb_filename * smb_fname,
773                              uint32_t access_mask,
774                              uint32_t share_access,
775                              uint32_t create_disposition,
776                              uint32_t create_options,
777                              uint32_t file_attributes,
778                              uint32_t oplock_request,
779                              const struct smb2_lease *lease,
780                              uint64_t allocation_size,
781                              uint32_t private_flags,
782                              struct security_descriptor *sd,
783                              struct ea_list *ea_list,
784                              files_struct **result,
785                              int *pinfo,
786                              const struct smb2_create_blobs *in_context_blobs,
787                              struct smb2_create_blobs *out_context_blobs);
788
789 /* The following definitions come from smbd/oplock.c  */
790
791 uint32_t get_lease_type(struct share_mode_entry *e, struct file_id id);
792
793 void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp);
794 NTSTATUS set_file_oplock(files_struct *fsp);
795 bool remove_oplock(files_struct *fsp);
796 bool downgrade_oplock(files_struct *fsp);
797 bool fsp_lease_update(struct files_struct *fsp);
798 NTSTATUS downgrade_lease(struct smbXsrv_client *client,
799                         uint32_t num_file_ids,
800                         const struct file_id *ids,
801                         const struct smb2_lease_key *key,
802                         uint32_t lease_state);
803 void contend_level2_oplocks_begin(files_struct *fsp,
804                                   enum level2_contention_type type);
805 void contend_level2_oplocks_end(files_struct *fsp,
806                                 enum level2_contention_type type);
807 void smbd_contend_level2_oplocks_begin(files_struct *fsp,
808                                   enum level2_contention_type type);
809 void smbd_contend_level2_oplocks_end(files_struct *fsp,
810                                 enum level2_contention_type type);
811 void share_mode_entry_to_message(char *msg, const struct file_id *id,
812                                  const struct share_mode_entry *e);
813 void message_to_share_mode_entry(struct file_id *id,
814                                  struct share_mode_entry *e,
815                                  const char *msg);
816 bool init_oplocks(struct smbd_server_connection *sconn);
817 void init_kernel_oplocks(struct smbd_server_connection *sconn);
818
819 /* The following definitions come from smbd/oplock_linux.c  */
820
821 int linux_set_lease_sighandler(int fd);
822 int linux_setlease(int fd, int leasetype);
823 struct kernel_oplocks *linux_init_kernel_oplocks(struct smbd_server_connection *sconn);
824
825 /* The following definitions come from smbd/password.c  */
826
827 void invalidate_vuid(struct smbd_server_connection *sconn, uint64_t vuid);
828 int register_homes_share(const char *username);
829
830 /* The following definitions come from smbd/pipes.c  */
831
832 NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
833                       struct files_struct **pfsp);
834 void reply_open_pipe_and_X(connection_struct *conn, struct smb_request *req);
835 void reply_pipe_write(struct smb_request *req);
836 void reply_pipe_write_and_X(struct smb_request *req);
837 void reply_pipe_read_and_X(struct smb_request *req);
838
839 /* The following definitions come from smbd/posix_acls.c  */
840
841 mode_t unix_perms_to_acl_perms(mode_t mode, int r_mask, int w_mask, int x_mask);
842 int map_acl_perms_to_permset(mode_t mode, SMB_ACL_PERMSET_T *p_permset);
843 uint32_t map_canon_ace_perms(int snum,
844                                 enum security_ace_type *pacl_type,
845                                 mode_t perms,
846                                 bool directory_ace);
847 NTSTATUS unpack_nt_owners(connection_struct *conn, uid_t *puser, gid_t *pgrp, uint32_t security_info_sent, const struct security_descriptor *psd);
848 bool current_user_in_group(connection_struct *conn, gid_t gid);
849 SMB_ACL_T free_empty_sys_acl(connection_struct *conn, SMB_ACL_T the_acl);
850 NTSTATUS posix_fget_nt_acl(struct files_struct *fsp, uint32_t security_info,
851                            TALLOC_CTX *mem_ctx,
852                            struct security_descriptor **ppdesc);
853 NTSTATUS posix_get_nt_acl(struct connection_struct *conn,
854                         const struct smb_filename *smb_fname_in,
855                         uint32_t security_info,
856                         TALLOC_CTX *mem_ctx,
857                         struct security_descriptor **ppdesc);
858 NTSTATUS try_chown(files_struct *fsp, uid_t uid, gid_t gid);
859 NTSTATUS set_nt_acl(files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd);
860 int get_acl_group_bits( connection_struct *conn,
861                         const struct smb_filename *smb_fname,
862                         mode_t *mode);
863 int inherit_access_posix_acl(connection_struct *conn,
864                         struct smb_filename *inherit_from_dir,
865                         const struct smb_filename *smb_fname,
866                         mode_t mode);
867 NTSTATUS set_unix_posix_default_acl(connection_struct *conn,
868                                 files_struct *fsp,
869                                 uint16_t num_def_acls, const char *pdata);
870 NTSTATUS set_unix_posix_acl(connection_struct *conn, files_struct *fsp,
871                                 uint16_t num_acls,
872                                 const char *pdata);
873 int posix_sys_acl_blob_get_file(vfs_handle_struct *handle,
874                                 const struct smb_filename *smb_fname,
875                                 TALLOC_CTX *mem_ctx,
876                                 char **blob_description,
877                                 DATA_BLOB *blob);
878 int posix_sys_acl_blob_get_fd(vfs_handle_struct *handle,
879                               files_struct *fsp,
880                               TALLOC_CTX *mem_ctx,
881                               char **blob_description,
882                               DATA_BLOB *blob);
883
884 enum default_acl_style {DEFAULT_ACL_POSIX, DEFAULT_ACL_WINDOWS, DEFAULT_ACL_EVERYONE};
885
886 const struct enum_list *get_default_acl_style_list(void);
887
888 NTSTATUS make_default_filesystem_acl(
889         TALLOC_CTX *ctx,
890         enum default_acl_style acl_style,
891         const char *name,
892         const SMB_STRUCT_STAT *psbuf,
893         struct security_descriptor **ppdesc);
894
895 /* The following definitions come from smbd/process.c  */
896
897 bool srv_send_smb(struct smbXsrv_connection *xconn, char *buffer,
898                   bool no_signing, uint32_t seqnum,
899                   bool do_encrypt,
900                   struct smb_perfcount_data *pcd);
901 size_t srv_set_message(char *buf,
902                        size_t num_words,
903                        size_t num_bytes,
904                        bool zero);
905 void remove_deferred_open_message_smb(struct smbXsrv_connection *xconn,
906                                       uint64_t mid);
907 bool schedule_deferred_open_message_smb(struct smbXsrv_connection *xconn,
908                                         uint64_t mid);
909 bool open_was_deferred(struct smbXsrv_connection *xconn, uint64_t mid);
910 bool get_deferred_open_message_state(struct smb_request *smbreq,
911                                 struct timeval *p_request_time,
912                                 struct deferred_open_record **open_rec);
913 bool push_deferred_open_message_smb(struct smb_request *req,
914                                     struct timeval timeout,
915                                     struct file_id id,
916                                     struct deferred_open_record *open_rec);
917 NTSTATUS allow_new_trans(struct trans_state *list, uint64_t mid);
918 void reply_outbuf(struct smb_request *req, uint8_t num_words, uint32_t num_bytes);
919 void smb_request_done(struct smb_request *req);
920 const char *smb_fn_name(int type);
921 void add_to_common_flags2(uint32_t v);
922 void remove_from_common_flags2(uint32_t v);
923 void construct_reply_common_req(struct smb_request *req, char *outbuf);
924 bool smb1_is_chain(const uint8_t *buf);
925 bool smb1_walk_chain(const uint8_t *buf,
926                      bool (*fn)(uint8_t cmd,
927                                 uint8_t wct, const uint16_t *vwv,
928                                 uint16_t num_bytes, const uint8_t *bytes,
929                                 void *private_data),
930                      void *private_data);
931 unsigned smb1_chain_length(const uint8_t *buf);
932 bool smb1_parse_chain(TALLOC_CTX *mem_ctx, const uint8_t *buf,
933                       struct smbXsrv_connection *xconn,
934                       bool encrypted, uint32_t seqnum,
935                       struct smb_request ***reqs, unsigned *num_reqs);
936 bool req_is_in_chain(const struct smb_request *req);
937 void smbd_process(struct tevent_context *ev_ctx,
938                   struct messaging_context *msg_ctx,
939                   struct dcesrv_context *dce_ctx,
940                   int sock_fd,
941                   bool interactive);
942 bool fork_echo_handler(struct smbXsrv_connection *xconn);
943
944 /* The following definitions come from smbd/quotas.c  */
945
946 bool disk_quotas(connection_struct *conn, struct smb_filename *fname,
947                  uint64_t *bsize, uint64_t *dfree, uint64_t *dsize);
948
949 /* The following definitions come from smbd/reply.c  */
950
951 NTSTATUS check_path_syntax(char *path);
952 NTSTATUS check_path_syntax_posix(char *path);
953 size_t srvstr_get_path(TALLOC_CTX *ctx,
954                         const char *inbuf,
955                         uint16_t smb_flags2,
956                         char **pp_dest,
957                         const char *src,
958                         size_t src_len,
959                         int flags,
960                         NTSTATUS *err);
961 size_t srvstr_get_path_posix(TALLOC_CTX *ctx,
962                         const char *inbuf,
963                         uint16_t smb_flags2,
964                         char **pp_dest,
965                         const char *src,
966                         size_t src_len,
967                         int flags,
968                         NTSTATUS *err);
969 size_t srvstr_get_path_req(TALLOC_CTX *mem_ctx, struct smb_request *req,
970                            char **pp_dest, const char *src, int flags,
971                            NTSTATUS *err);
972 size_t srvstr_pull_req_talloc(TALLOC_CTX *ctx, struct smb_request *req,
973                               char **dest, const uint8_t *src, int flags);
974 bool check_fsp_open(connection_struct *conn, struct smb_request *req,
975                     files_struct *fsp);
976 bool check_fsp(connection_struct *conn, struct smb_request *req,
977                files_struct *fsp);
978 bool check_fsp_ntquota_handle(connection_struct *conn, struct smb_request *req,
979                               files_struct *fsp);
980 void reply_special(struct smbXsrv_connection *xconn, char *inbuf, size_t inbuf_size);
981 void reply_tcon(struct smb_request *req);
982 void reply_tcon_and_X(struct smb_request *req);
983 void reply_unknown_new(struct smb_request *req, uint8_t type);
984 void reply_ioctl(struct smb_request *req);
985 void reply_checkpath(struct smb_request *req);
986 void reply_getatr(struct smb_request *req);
987 void reply_setatr(struct smb_request *req);
988 void reply_dskattr(struct smb_request *req);
989 void reply_search(struct smb_request *req);
990 void reply_fclose(struct smb_request *req);
991 void reply_open(struct smb_request *req);
992 void reply_open_and_X(struct smb_request *req);
993 void reply_ulogoffX(struct smb_request *req);
994 void reply_mknew(struct smb_request *req);
995 void reply_ctemp(struct smb_request *req);
996 NTSTATUS unlink_internals(connection_struct *conn,
997                         struct smb_request *req,
998                         uint32_t dirtype,
999                         struct smb_filename *smb_fname,
1000                         bool has_wcard);
1001 void reply_unlink(struct smb_request *req);
1002 ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
1003                       off_t startpos, size_t nread);
1004 ssize_t sendfile_short_send(struct smbXsrv_connection *xconn,
1005                             files_struct *fsp,
1006                             ssize_t nread,
1007                             size_t headersize,
1008                             size_t smb_maxcnt);
1009 void reply_readbraw(struct smb_request *req);
1010 void reply_lockread(struct smb_request *req);
1011 size_t setup_readX_header(char *outbuf, size_t smb_maxcnt);
1012 void reply_read(struct smb_request *req);
1013 void reply_read_and_X(struct smb_request *req);
1014 void error_to_writebrawerr(struct smb_request *req);
1015 void reply_writebraw(struct smb_request *req);
1016 void reply_writeunlock(struct smb_request *req);
1017 void reply_write(struct smb_request *req);
1018 bool is_valid_writeX_buffer(struct smbXsrv_connection *xconn,
1019                             const uint8_t *inbuf);
1020 void reply_write_and_X(struct smb_request *req);
1021 void reply_lseek(struct smb_request *req);
1022 void reply_flush(struct smb_request *req);
1023 void reply_exit(struct smb_request *req);
1024 void reply_close(struct smb_request *req);
1025 void reply_writeclose(struct smb_request *req);
1026 void reply_lock(struct smb_request *req);
1027 void reply_unlock(struct smb_request *req);
1028 void reply_tdis(struct smb_request *req);
1029 void reply_echo(struct smb_request *req);
1030 void reply_printopen(struct smb_request *req);
1031 void reply_printclose(struct smb_request *req);
1032 void reply_printqueue(struct smb_request *req);
1033 void reply_printwrite(struct smb_request *req);
1034 void reply_mkdir(struct smb_request *req);
1035 void reply_rmdir(struct smb_request *req);
1036 NTSTATUS rename_internals_fsp(connection_struct *conn,
1037                         files_struct *fsp,
1038                         struct smb_filename *smb_fname_dst_in,
1039                         const char *dst_original_lcomp,
1040                         uint32_t attrs,
1041                         bool replace_if_exists);
1042 NTSTATUS rename_internals(TALLOC_CTX *ctx,
1043                         connection_struct *conn,
1044                         struct smb_request *req,
1045                         struct smb_filename *smb_fname_src,
1046                         const char *src_original_lcomp,
1047                         struct smb_filename *smb_fname_dst,
1048                         const char *dst_original_lcomp,
1049                         uint32_t attrs,
1050                         bool replace_if_exists,
1051                         uint32_t access_mask);
1052 void reply_mv(struct smb_request *req);
1053 NTSTATUS copy_file(TALLOC_CTX *ctx,
1054                         connection_struct *conn,
1055                         struct smb_filename *smb_fname_src,
1056                         struct smb_filename *smb_fname_dst,
1057                         int ofun,
1058                         int count,
1059                         bool target_is_directory);
1060 void reply_copy(struct smb_request *req);
1061 uint64_t get_lock_pid(const uint8_t *data, int data_offset,
1062                     bool large_file_format);
1063 uint64_t get_lock_count(const uint8_t *data, int data_offset,
1064                         bool large_file_format);
1065 uint64_t get_lock_offset(const uint8_t *data, int data_offset,
1066                          bool large_file_format);
1067 void reply_lockingX(struct smb_request *req);
1068 void reply_readbmpx(struct smb_request *req);
1069 void reply_readbs(struct smb_request *req);
1070 void reply_setattrE(struct smb_request *req);
1071 void reply_writebmpx(struct smb_request *req);
1072 void reply_writebs(struct smb_request *req);
1073 void reply_getattrE(struct smb_request *req);
1074
1075 /* The following definitions come from smbd/seal.c  */
1076
1077 bool is_encrypted_packet(const uint8_t *inbuf);
1078 void srv_free_enc_buffer(struct smbXsrv_connection *xconn, char *buf);
1079 NTSTATUS srv_decrypt_buffer(struct smbXsrv_connection *xconn, char *buf);
1080 NTSTATUS srv_encrypt_buffer(struct smbXsrv_connection *xconn, char *buf,
1081                             char **buf_out);
1082 NTSTATUS srv_request_encryption_setup(connection_struct *conn,
1083                                         unsigned char **ppdata,
1084                                         size_t *p_data_size,
1085                                         unsigned char **pparam,
1086                                         size_t *p_param_size);
1087 NTSTATUS srv_encryption_start(connection_struct *conn);
1088 void server_encryption_shutdown(struct smbXsrv_connection *xconn);
1089
1090 /* The following definitions come from smbd/sec_ctx.c  */
1091
1092 bool unix_token_equal(const struct security_unix_token *t1, const struct security_unix_token *t2);
1093 bool push_sec_ctx(void);
1094 void set_sec_ctx(uid_t uid, gid_t gid, int ngroups, gid_t *groups, const struct security_token *token);
1095 void set_root_sec_ctx(void);
1096 bool pop_sec_ctx(void);
1097 void init_sec_ctx(void);
1098 const struct security_token *sec_ctx_active_token(void);
1099
1100 /* The following definitions come from smbd/server.c  */
1101
1102 struct memcache *smbd_memcache(void);
1103 bool snum_is_shared_printer(int snum);
1104 void delete_and_reload_printers(void);
1105 bool reload_services(struct smbd_server_connection *sconn,
1106                      bool (*snumused) (struct smbd_server_connection *, int),
1107                      bool test);
1108
1109 /* The following definitions come from smbd/server_exit.c  */
1110
1111 void smbd_exit_server(const char *reason) _NORETURN_;
1112 void smbd_exit_server_cleanly(const char *const reason) _NORETURN_;
1113
1114 /* The following definitions come from smbd/service.c  */
1115
1116 bool set_conn_connectpath(connection_struct *conn, const char *connectpath);
1117 bool canonicalize_connect_path(connection_struct *conn);
1118 NTSTATUS set_conn_force_user_group(connection_struct *conn, int snum);
1119 void set_current_case_sensitive(connection_struct *conn, uint16_t flags);
1120 bool chdir_current_service(connection_struct *conn);
1121 void load_registry_shares(void);
1122 int add_home_service(const char *service, const char *username, const char *homedir);
1123 int find_service(TALLOC_CTX *ctx, const char *service, char **p_service_out);
1124 connection_struct *make_connection_smb2(struct smbd_smb2_request *req,
1125                                         struct smbXsrv_tcon *tcon,
1126                                         int snum,
1127                                         const char *pdev,
1128                                         NTSTATUS *pstatus);
1129 connection_struct *make_connection(struct smb_request *req,
1130                                    NTTIME now,
1131                                    const char *service_in,
1132                                    const char *pdev, uint64_t vuid,
1133                                    NTSTATUS *status);
1134 void close_cnum(connection_struct *conn, uint64_t vuid);
1135
1136 /* The following definitions come from smbd/session.c  */
1137 struct sessionid;
1138 struct smbXsrv_session;
1139 bool session_init(void);
1140 bool session_claim(struct smbXsrv_session *session);
1141 void session_yield(struct smbXsrv_session *session);
1142 int list_sessions(TALLOC_CTX *mem_ctx, struct sessionid **session_list);
1143 int find_sessions(TALLOC_CTX *mem_ctx, const char *username,
1144                   const char *machine, struct sessionid **session_list);
1145
1146 /* The following definitions come from smbd/sesssetup.c  */
1147
1148 void reply_sesssetup_and_X(struct smb_request *req);
1149
1150 /* The following definitions come from smbd/share_access.c  */
1151
1152 bool token_contains_name_in_list(const char *username,
1153                                  const char *domain,
1154                                  const char *sharename,
1155                                  const struct security_token *token,
1156                                  const char **list);
1157 bool user_ok_token(const char *username, const char *domain,
1158                    const struct security_token *token, int snum);
1159 bool is_share_read_only_for_token(const char *username,
1160                                   const char *domain,
1161                                   const struct security_token *token,
1162                                   connection_struct *conn);
1163
1164 /* The following definitions come from smbd/srvstr.c  */
1165
1166 NTSTATUS srvstr_push_fn(const char *base_ptr, uint16_t smb_flags2, void *dest,
1167                       const char *src, int dest_len, int flags, size_t *ret_len);
1168 ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags);
1169
1170 /* The following definitions come from smbd/statcache.c  */
1171
1172 void stat_cache_add( const char *full_orig_name,
1173                 const char *translated_path,
1174                 NTTIME twrp,
1175                 bool case_sensitive);
1176 bool stat_cache_lookup(connection_struct *conn,
1177                         bool posix_paths,
1178                         char **pp_name,
1179                         char **pp_dirpath,
1180                         char **pp_start,
1181                         NTTIME twrp,
1182                         SMB_STRUCT_STAT *pst);
1183 void smbd_send_stat_cache_delete_message(struct messaging_context *msg_ctx,
1184                                     const char *name);
1185 void send_stat_cache_delete_message(struct messaging_context *msg_ctx,
1186                                     const char *name);
1187 void stat_cache_delete(const char *name);
1188 struct TDB_DATA;
1189 unsigned int fast_string_hash(struct TDB_DATA *key);
1190 bool reset_stat_cache( void );
1191
1192 /* The following definitions come from smbd/statvfs.c  */
1193
1194 int sys_statvfs(const char *path, vfs_statvfs_struct *statbuf);
1195
1196 /* The following definitions come from smbd/trans2.c  */
1197
1198 NTSTATUS check_access_fsp(struct files_struct *fsp,
1199                           uint32_t access_mask);
1200 uint64_t smb_roundup(connection_struct *conn, uint64_t val);
1201 bool samba_private_attr_name(const char *unix_ea_name);
1202 NTSTATUS get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn,
1203                         files_struct *fsp,
1204                         const struct smb_filename *smb_fname,
1205                         const char *ea_name,
1206                         struct ea_struct *pea);
1207 NTSTATUS get_ea_names_from_file(TALLOC_CTX *mem_ctx,
1208                         connection_struct *conn,
1209                         files_struct *fsp,
1210                         const struct smb_filename *smb_fname,
1211                         char ***pnames,
1212                         size_t *pnum_names);
1213 NTSTATUS set_ea(connection_struct *conn, files_struct *fsp,
1214                 struct ea_list *ea_list);
1215 struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used);
1216 void send_trans2_replies(connection_struct *conn,
1217                         struct smb_request *req,
1218                         NTSTATUS status,
1219                          const char *params,
1220                          int paramsize,
1221                          const char *pdata,
1222                          int datasize,
1223                          int max_data_bytes);
1224 unsigned char *create_volume_objectid(connection_struct *conn, unsigned char objid[16]);
1225 NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
1226                 connection_struct *conn,
1227                 struct smb_request *req,
1228                 bool overwrite_if_exists,
1229                 const struct smb_filename *smb_fname_old,
1230                 struct smb_filename *smb_fname_new);
1231 NTSTATUS smb_set_file_time(connection_struct *conn,
1232                            files_struct *fsp,
1233                            struct smb_filename *smb_fname,
1234                            struct smb_file_time *ft,
1235                            bool setting_write_time);
1236 void reply_findclose(struct smb_request *req);
1237 void reply_findnclose(struct smb_request *req);
1238 void reply_trans2(struct smb_request *req);
1239 void reply_transs2(struct smb_request *req);
1240
1241 enum perm_type {
1242         PERM_NEW_FILE,
1243         PERM_NEW_DIR,
1244         PERM_EXISTING_FILE,
1245         PERM_EXISTING_DIR
1246 };
1247
1248 NTSTATUS unix_perms_from_wire(connection_struct *conn,
1249                               const SMB_STRUCT_STAT *psbuf,
1250                               uint32_t perms,
1251                               enum perm_type ptype,
1252                               mode_t *ret_perms);
1253
1254 /* The following definitions come from smbd/uid.c  */
1255
1256 bool change_to_guest(void);
1257 NTSTATUS check_user_share_access(connection_struct *conn,
1258                                 const struct auth_session_info *session_info,
1259                                 uint32_t *p_share_access,
1260                                 bool *p_readonly_share);
1261 bool change_to_user_and_service(connection_struct *conn, uint64_t vuid);
1262 bool change_to_user_and_service_by_fsp(struct files_struct *fsp);
1263 bool smbd_change_to_root_user(void);
1264 bool smbd_become_authenticated_pipe_user(struct auth_session_info *session_info);
1265 bool smbd_unbecome_authenticated_pipe_user(void);
1266 void become_root(void);
1267 void unbecome_root(void);
1268 void smbd_become_root(void);
1269 void smbd_unbecome_root(void);
1270 bool become_user_without_service(connection_struct *conn, uint64_t vuid);
1271 bool become_user_without_service_by_fsp(struct files_struct *fsp);
1272 bool become_user_without_service_by_session(connection_struct *conn,
1273                             const struct auth_session_info *session_info);
1274 bool unbecome_user_without_service(void);
1275 uid_t get_current_uid(connection_struct *conn);
1276 gid_t get_current_gid(connection_struct *conn);
1277 const struct security_unix_token *get_current_utok(connection_struct *conn);
1278 const struct security_token *get_current_nttok(connection_struct *conn);
1279
1280 /* The following definitions come from smbd/utmp.c  */
1281
1282 void sys_utmp_claim(const char *username, const char *hostname,
1283                     const char *id_str, int id_num);
1284 void sys_utmp_yield(const char *username, const char *hostname,
1285                     const char *id_str, int id_num);
1286
1287 /* The following definitions come from smbd/vfs.c  */
1288
1289 bool vfs_init_custom(connection_struct *conn, const char *vfs_object);
1290 bool smbd_vfs_init(connection_struct *conn);
1291 NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname);
1292 bool vfs_valid_pread_range(off_t offset, size_t length);
1293 bool vfs_valid_pwrite_range(off_t offset, size_t length);
1294 ssize_t vfs_pwrite_data(struct smb_request *req,
1295                         files_struct *fsp,
1296                         const char *buffer,
1297                         size_t N,
1298                         off_t offset);
1299 int vfs_allocate_file_space(files_struct *fsp, uint64_t len);
1300 int vfs_set_filelen(files_struct *fsp, off_t len);
1301 int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len);
1302 int vfs_fill_sparse(files_struct *fsp, off_t len);
1303 int vfs_set_blocking(files_struct *fsp, bool set);
1304 off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n);
1305 const char *vfs_readdirname(connection_struct *conn,
1306                             struct files_struct *dirfsp,
1307                             void *p,
1308                             SMB_STRUCT_STAT *sbuf,
1309                             char **talloced);
1310 int vfs_ChDir(connection_struct *conn,
1311                         const struct smb_filename *smb_fname);
1312 struct smb_filename *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn);
1313 NTSTATUS check_reduced_name(connection_struct *conn,
1314                         const struct smb_filename *cwd_fname,
1315                         const struct smb_filename *smb_fname);
1316 NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
1317                         const struct smb_filename *smb_fname,
1318                         struct smb_request *smbreq);
1319 int vfs_stat(struct connection_struct *conn,
1320              struct smb_filename *smb_fname);
1321 int vfs_stat_smb_basename(struct connection_struct *conn,
1322                         const struct smb_filename *smb_fname_in,
1323                         SMB_STRUCT_STAT *psbuf);
1324 NTSTATUS vfs_stat_fsp(files_struct *fsp);
1325 NTSTATUS vfs_streaminfo(connection_struct *conn,
1326                         struct files_struct *fsp,
1327                         const struct smb_filename *smb_fname,
1328                         TALLOC_CTX *mem_ctx,
1329                         unsigned int *num_streams,
1330                         struct stream_struct **streams);
1331 void init_smb_file_time(struct smb_file_time *ft);
1332 int vfs_fake_fd(void);
1333 int vfs_fake_fd_close(int fd);
1334
1335 /* The following definitions come from smbd/avahi_register.c */
1336
1337 void *avahi_start_register(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
1338                            uint16_t port);
1339
1340 /* The following definitions come from smbd/smb2_create.c */
1341
1342 NTSTATUS vfs_default_durable_cookie(struct files_struct *fsp,
1343                                     TALLOC_CTX *mem_ctx,
1344                                     DATA_BLOB *cookie_blob);
1345 NTSTATUS vfs_default_durable_disconnect(struct files_struct *fsp,
1346                                         const DATA_BLOB old_cookie,
1347                                         TALLOC_CTX *mem_ctx,
1348                                         DATA_BLOB *new_cookie);
1349 NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
1350                                        struct smb_request *smb1req,
1351                                        struct smbXsrv_open *op,
1352                                        const DATA_BLOB old_cookie,
1353                                        TALLOC_CTX *mem_ctx,
1354                                        files_struct **result,
1355                                        DATA_BLOB *new_cookie);
1356
1357 #endif /* _SMBD_PROTO_H_ */