notifyd: Factor out notify_walk() into its own file
[gd/samba-autobuild/.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_force_tdis(
160         struct smbd_server_connection *sconn,
161         bool (*check_fn)(struct connection_struct *conn,
162                          void *private_data),
163         void *private_data);
164 void msg_force_tdis(struct messaging_context *msg,
165                     void *private_data,
166                     uint32_t msg_type,
167                     struct server_id server_id,
168                     DATA_BLOB *data);
169 void msg_force_tdis_denied(
170         struct messaging_context *msg,
171         void *private_data,
172         uint32_t msg_type,
173         struct server_id server_id,
174         DATA_BLOB *data);
175
176 /* The following definitions come from smbd/connection.c  */
177
178 int count_current_connections(const char *sharename, bool verify);
179 bool connections_snum_used(struct smbd_server_connection *unused, int snum);
180
181 /* The following definitions come from smbd/dfree.c  */
182
183 uint64_t get_dfree_info(connection_struct *conn, struct smb_filename *fname,
184                         uint64_t *bsize, uint64_t *dfree, uint64_t *dsize);
185 void flush_dfree_cache(void);
186
187 /* The following definitions come from smbd/dir.c  */
188
189 bool init_dptrs(struct smbd_server_connection *sconn);
190 const char *dptr_path(struct smbd_server_connection *sconn, int key);
191 const char *dptr_wcard(struct smbd_server_connection *sconn, int key);
192 uint16_t dptr_attr(struct smbd_server_connection *sconn, int key);
193 void dptr_closecnum(connection_struct *conn);
194 NTSTATUS dptr_create(connection_struct *conn,
195                 struct smb_request *req,
196                 files_struct *fsp,
197                 bool old_handle,
198                 bool expect_close,
199                 uint16_t spid,
200                 const char *wcard,
201                 uint32_t attr,
202                 struct dptr_struct **dptr_ret);
203 void dptr_CloseDir(files_struct *fsp);
204 void dptr_SeekDir(struct dptr_struct *dptr, long offset);
205 long dptr_TellDir(struct dptr_struct *dptr);
206 bool dptr_has_wild(struct dptr_struct *dptr);
207 int dptr_dnum(struct dptr_struct *dptr);
208 bool dptr_get_priv(struct dptr_struct *dptr);
209 void dptr_set_priv(struct dptr_struct *dptr);
210 bool dptr_SearchDir(struct dptr_struct *dptr, const char *name, long *poffset, SMB_STRUCT_STAT *pst);
211 bool dptr_fill(struct smbd_server_connection *sconn,
212                char *buf1,unsigned int key);
213 files_struct *dptr_fetch_fsp(struct smbd_server_connection *sconn,
214                                char *buf,int *num);
215 files_struct *dptr_fetch_lanman2_fsp(struct smbd_server_connection *sconn,
216                                        int dptr_num);
217 bool get_dir_entry(TALLOC_CTX *ctx,
218                 struct dptr_struct *dirptr,
219                 const char *mask,
220                 uint32_t dirtype,
221                 char **pp_fname_out,
222                 off_t *size,
223                 uint32_t *mode,
224                 struct timespec *date,
225                 bool check_descend,
226                 bool ask_sharemode);
227 struct smb_Dir;
228 bool is_visible_file(connection_struct *conn,
229                 struct smb_Dir *dir_hnd,
230                 const char *name,
231                 SMB_STRUCT_STAT *pst,
232                 bool use_veto);
233 struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx,
234                         connection_struct *conn,
235                         const struct smb_filename *smb_fname,
236                         const char *mask,
237                         uint32_t attr);
238 const char *ReadDirName(struct smb_Dir *dir_hnd, long *poffset,
239                         SMB_STRUCT_STAT *sbuf, char **talloced);
240 void RewindDir(struct smb_Dir *dir_hnd, long *poffset);
241 void SeekDir(struct smb_Dir *dirp, long offset);
242 long TellDir(struct smb_Dir *dirp);
243 bool SearchDir(struct smb_Dir *dirp, const char *name, long *poffset);
244 NTSTATUS can_delete_directory(struct connection_struct *conn,
245                                 const char *dirname);
246 bool have_file_open_below(connection_struct *conn,
247                         const struct smb_filename *name);
248
249 /* The following definitions come from smbd/dmapi.c  */
250
251 const void *dmapi_get_current_session(void);
252 bool dmapi_have_session(void);
253 bool dmapi_new_session(void);
254 bool dmapi_destroy_session(void);
255 uint32_t dmapi_file_flags(const char * const path);
256
257 /* The following definitions come from smbd/dnsregister.c  */
258
259 bool smbd_setup_mdns_registration(struct tevent_context *ev,
260                                   TALLOC_CTX *mem_ctx,
261                                   uint16_t port);
262
263 /* The following definitions come from smbd/dosmode.c  */
264
265 mode_t unix_mode(connection_struct *conn, int dosmode,
266                  const struct smb_filename *smb_fname,
267                  struct smb_filename *smb_fname_parent);
268 uint32_t dos_mode_msdfs(connection_struct *conn,
269                       const struct smb_filename *smb_fname);
270 uint32_t dos_mode(connection_struct *conn, struct smb_filename *smb_fname);
271 struct tevent_req *dos_mode_at_send(TALLOC_CTX *mem_ctx,
272                                     struct tevent_context *ev,
273                                     files_struct *dir_fsp,
274                                     struct smb_filename *smb_fname);
275 NTSTATUS dos_mode_at_recv(struct tevent_req *req, uint32_t *dosmode);
276 int file_set_dosmode(connection_struct *conn,
277                      struct smb_filename *smb_fname,
278                      uint32_t dosmode,
279                      struct smb_filename *parent_dir,
280                      bool newfile);
281 NTSTATUS file_set_sparse(connection_struct *conn,
282                          struct files_struct *fsp,
283                          bool sparse);
284 int file_ntimes(connection_struct *conn, const struct smb_filename *smb_fname,
285                 struct smb_file_time *ft);
286 bool set_sticky_write_time_path(struct file_id fileid, struct timespec mtime);
287 bool set_sticky_write_time_fsp(struct files_struct *fsp,
288                                struct timespec mtime);
289
290 NTSTATUS get_ea_dos_attribute(connection_struct *conn,
291                               struct smb_filename *smb_fname,
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 files_struct *file_find_di_next(files_struct *start_fsp);
424 struct files_struct *file_find_one_fsp_from_lease_key(
425         struct smbd_server_connection *sconn,
426         const struct smb2_lease_key *lease_key);
427 bool file_find_subpath(files_struct *dir_fsp);
428 void fsp_free(files_struct *fsp);
429 void file_free(struct smb_request *req, files_struct *fsp);
430 files_struct *file_fsp(struct smb_request *req, uint16_t fid);
431 struct files_struct *file_fsp_get(struct smbd_smb2_request *smb2req,
432                                   uint64_t persistent_id,
433                                   uint64_t volatile_id);
434 struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
435                                    uint64_t persistent_id,
436                                    uint64_t volatile_id);
437 NTSTATUS dup_file_fsp(
438         struct smb_request *req,
439         files_struct *from,
440         uint32_t access_mask,
441         uint32_t create_options,
442         files_struct *to);
443 NTSTATUS file_name_hash(connection_struct *conn,
444                         const char *name, uint32_t *p_name_hash);
445 NTSTATUS fsp_set_smb_fname(struct files_struct *fsp,
446                            const struct smb_filename *smb_fname_in);
447 size_t fsp_fullbasepath(struct files_struct *fsp, char *buf, size_t buflen);
448
449 NTSTATUS create_internal_dirfsp(connection_struct *conn,
450                                 const struct smb_filename *smb_dname,
451                                 struct files_struct **_fsp);
452
453 NTSTATUS open_internal_dirfsp(connection_struct *conn,
454                               const struct smb_filename *smb_dname,
455                               int open_flags,
456                               struct files_struct **_fsp);
457
458 /* The following definitions come from smbd/ipc.c  */
459
460 NTSTATUS nt_status_np_pipe(NTSTATUS status);
461 void send_trans_reply(connection_struct *conn,
462                       struct smb_request *req,
463                       char *rparam, int rparam_len,
464                       char *rdata, int rdata_len,
465                       bool buffer_too_large);
466 void reply_trans(struct smb_request *req);
467 void reply_transs(struct smb_request *req);
468
469 /* The following definitions come from smbd/lanman.c  */
470
471 void api_reply(connection_struct *conn, uint64_t vuid,
472                struct smb_request *req,
473                char *data, char *params,
474                int tdscnt, int tpscnt,
475                int mdrcnt, int mprcnt);
476
477 /* The following definitions come from smbd/mangle.c  */
478
479 void mangle_reset_cache(void);
480 void mangle_change_to_posix(void);
481 bool mangle_is_mangled(const char *s, const struct share_params *p);
482 bool mangle_is_8_3(const char *fname, bool check_case,
483                    const struct share_params *p);
484 bool mangle_is_8_3_wildcards(const char *fname, bool check_case,
485                              const struct share_params *p);
486 bool mangle_must_mangle(const char *fname,
487                    const struct share_params *p);
488 bool mangle_lookup_name_from_8_3(TALLOC_CTX *ctx,
489                         const char *in,
490                         char **out, /* talloced on the given context. */
491                         const struct share_params *p);
492 bool name_to_8_3(const char *in,
493                 char out[13],
494                 bool cache83,
495                 const struct share_params *p);
496
497 /* The following definitions come from smbd/mangle_hash.c  */
498
499 const struct mangle_fns *mangle_hash_init(void);
500
501 /* The following definitions come from smbd/mangle_hash2.c  */
502
503 const struct mangle_fns *mangle_hash2_init(void);
504 const struct mangle_fns *posix_mangle_init(void);
505
506 /* The following definitions come from smbd/message.c  */
507
508 void reply_sends(struct smb_request *req);
509 void reply_sendstrt(struct smb_request *req);
510 void reply_sendtxt(struct smb_request *req);
511 void reply_sendend(struct smb_request *req);
512
513 /* The following definitions come from smbd/msdfs.c  */
514
515 bool parse_msdfs_symlink(TALLOC_CTX *ctx,
516                         bool shuffle_referrals,
517                         const char *target,
518                         struct referral **preflist,
519                         size_t *refcount);
520 bool is_msdfs_link(connection_struct *conn,
521                 struct smb_filename *smb_fname);
522 struct junction_map;
523 NTSTATUS get_referred_path(TALLOC_CTX *ctx,
524                            struct auth_session_info *session_info,
525                            const char *dfs_path,
526                            const struct tsocket_address *remote_address,
527                            const struct tsocket_address *local_address,
528                            bool allow_broken_path,
529                            struct junction_map *jucn,
530                            int *consumedcntp,
531                            bool *self_referralp);
532 int setup_dfs_referral(connection_struct *orig_conn,
533                         const char *dfs_path,
534                         int max_referral_level,
535                         char **ppdata, NTSTATUS *pstatus);
536 bool create_junction(TALLOC_CTX *ctx,
537                 const char *dfs_path,
538                 bool allow_broken_path,
539                 struct junction_map *jucn);
540 struct referral;
541 char *msdfs_link_string(TALLOC_CTX *ctx,
542                 const struct referral *reflist,
543                 size_t referral_count);
544 bool create_msdfs_link(const struct junction_map *jucn,
545                        struct auth_session_info *session_info);
546 bool remove_msdfs_link(const struct junction_map *jucn,
547                        struct auth_session_info *session_info);
548
549 struct junction_map *enum_msdfs_links(TALLOC_CTX *ctx,
550                                       struct auth_session_info *session_info,
551                                       size_t *p_num_jn);
552 NTSTATUS dfs_redirect(TALLOC_CTX *ctx,
553                         connection_struct *conn,
554                         const char *name_in,
555                         uint32_t ucf_flags,
556                         bool allow_broken_path,
557                         char **pp_name_out);
558 struct connection_struct;
559 struct smb_filename;
560 struct conn_struct_tos {
561         struct connection_struct *conn;
562         struct smb_filename *oldcwd_fname;
563 };
564 NTSTATUS create_conn_struct_tos(struct messaging_context *msg,
565                                 int snum,
566                                 const char *path,
567                                 const struct auth_session_info *session_info,
568                                 struct conn_struct_tos **_c);
569 NTSTATUS create_conn_struct_tos_cwd(struct messaging_context *msg,
570                                     int snum,
571                                     const char *path,
572                                     const struct auth_session_info *session_info,
573                                     struct conn_struct_tos **_c);
574
575 /* The following definitions come from smbd/negprot.c  */
576
577 void reply_negprot(struct smb_request *req);
578
579 /* The following definitions come from smbd/notify.c  */
580
581 bool change_notify_fsp_has_changes(struct files_struct *fsp);
582 void change_notify_reply(struct smb_request *req,
583                          NTSTATUS error_code,
584                          uint32_t max_param,
585                          struct notify_change_buf *notify_buf,
586                          void (*reply_fn)(struct smb_request *req,
587                                           NTSTATUS error_code,
588                                           uint8_t *buf, size_t len));
589 void notify_callback(struct smbd_server_connection *sconn,
590                      void *private_data, struct timespec when,
591                      const struct notify_event *e);
592 NTSTATUS change_notify_create(struct files_struct *fsp,
593                               uint32_t max_buffer_size,
594                               uint32_t filter,
595                               bool recursive);
596 NTSTATUS change_notify_add_request(struct smb_request *req,
597                                 uint32_t max_param,
598                                 uint32_t filter, bool recursive,
599                                 struct files_struct *fsp,
600                                 void (*reply_fn)(struct smb_request *req,
601                                         NTSTATUS error_code,
602                                         uint8_t *buf, size_t len));
603 void smbd_notify_cancel_deleted(struct messaging_context *msg,
604                                 void *private_data, uint32_t msg_type,
605                                 struct server_id server_id, DATA_BLOB *data);
606 void smbd_notifyd_restarted(struct messaging_context *msg,
607                             void *private_data, uint32_t msg_type,
608                             struct server_id server_id, DATA_BLOB *data);
609 bool remove_pending_change_notify_requests_by_mid(
610         struct smbd_server_connection *sconn, uint64_t mid);
611 void remove_pending_change_notify_requests_by_fid(files_struct *fsp,
612                                                   NTSTATUS status);
613 void notify_fname(connection_struct *conn, uint32_t action, uint32_t filter,
614                   const char *path);
615 char *notify_filter_string(TALLOC_CTX *mem_ctx, uint32_t filter);
616 struct sys_notify_context *sys_notify_context_create(TALLOC_CTX *mem_ctx,
617                                                      struct tevent_context *ev);
618
619 /* The following definitions come from smbd/notify_inotify.c  */
620
621 int inotify_watch(TALLOC_CTX *mem_ctx,
622                   struct sys_notify_context *ctx,
623                   const char *path,
624                   uint32_t *filter,
625                   uint32_t *subdir_filter,
626                   void (*callback)(struct sys_notify_context *ctx,
627                                    void *private_data,
628                                    struct notify_event *ev,
629                                    uint32_t filter),
630                   void *private_data,
631                   void *handle_p);
632
633 int fam_watch(TALLOC_CTX *mem_ctx,
634               struct sys_notify_context *ctx,
635               const char *path,
636               uint32_t *filter,
637               uint32_t *subdir_filter,
638               void (*callback)(struct sys_notify_context *ctx,
639                                void *private_data,
640                                struct notify_event *ev,
641                                uint32_t filter),
642               void *private_data,
643               void *handle_p);
644
645
646 /* The following definitions come from smbd/notify_internal.c  */
647
648 struct notify_context *notify_init(
649         TALLOC_CTX *mem_ctx, struct messaging_context *msg,
650         struct smbd_server_connection *sconn,
651         void (*callback)(struct smbd_server_connection *sconn,
652                          void *, struct timespec,
653                          const struct notify_event *));
654 NTSTATUS notify_add(struct notify_context *ctx,
655                     const char *path, uint32_t filter, uint32_t subdir_filter,
656                     void *private_data);
657 NTSTATUS notify_remove(struct notify_context *ctx, void *private_data,
658                        char *path);
659 void notify_trigger(struct notify_context *notify,
660                     uint32_t action, uint32_t filter,
661                     const char *dir, const char *path);
662
663 /* The following definitions come from smbd/ntquotas.c  */
664
665 NTSTATUS vfs_get_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype,
666                          struct dom_sid *psid, SMB_NTQUOTA_STRUCT *qt);
667 int vfs_set_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype, struct dom_sid *psid, SMB_NTQUOTA_STRUCT *qt);
668 int vfs_get_user_ntquota_list(files_struct *fsp, SMB_NTQUOTA_LIST **qt_list);
669 void *init_quota_handle(TALLOC_CTX *mem_ctx);
670
671 /* The following definitions come from smbd/nttrans.c  */
672
673 void reply_ntcreate_and_X(struct smb_request *req);
674 NTSTATUS set_sd(files_struct *fsp, struct security_descriptor *psd,
675                        uint32_t security_info_sent);
676 NTSTATUS set_sd_blob(files_struct *fsp, uint8_t *data, uint32_t sd_len,
677                        uint32_t security_info_sent);
678 struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size);
679 void reply_ntcancel(struct smb_request *req);
680 void reply_ntrename(struct smb_request *req);
681 NTSTATUS smbd_do_query_security_desc(connection_struct *conn,
682                                         TALLOC_CTX *mem_ctx,
683                                         files_struct *fsp,
684                                         uint32_t security_info_wanted,
685                                         uint32_t max_data_count,
686                                         uint8_t **ppmarshalled_sd,
687                                         size_t *psd_size);
688 #ifdef HAVE_SYS_QUOTAS
689
690 struct smb2_query_quota_info;
691
692 NTSTATUS smbd_do_query_getinfo_quota(TALLOC_CTX *mem_ctx,
693                                      files_struct *fsp,
694                                      bool restart_scan,
695                                      bool return_single,
696                                      uint32_t sid_list_length,
697                                      DATA_BLOB *sidbuffer,
698                                      uint32_t max_data_count,
699                                      uint8_t **p_data,
700                                      uint32_t *p_data_size);
701 #endif
702 void reply_nttrans(struct smb_request *req);
703 void reply_nttranss(struct smb_request *req);
704
705 /* The following definitions come from smbd/open.c  */
706
707 NTSTATUS smbd_check_access_rights(struct connection_struct *conn,
708                                 struct files_struct *dirfsp,
709                                 const struct smb_filename *smb_fname,
710                                 bool use_privs,
711                                 uint32_t access_mask);
712 NTSTATUS check_parent_access(struct connection_struct *conn,
713                                 struct files_struct *dirfsp,
714                                 struct smb_filename *smb_fname,
715                                 uint32_t access_mask);
716 NTSTATUS fd_open(files_struct *fsp,
717                  int flags, mode_t mode);
718 NTSTATUS fd_close(files_struct *fsp);
719 void change_file_owner_to_parent(connection_struct *conn,
720                                  struct smb_filename *inherit_from_dir,
721                                  files_struct *fsp);
722 bool is_oplock_stat_open(uint32_t access_mask);
723 bool is_lease_stat_open(uint32_t access_mask);
724 NTSTATUS send_break_message(struct messaging_context *msg_ctx,
725                             const struct file_id *id,
726                             const struct share_mode_entry *exclusive,
727                             uint16_t break_to);
728 struct deferred_open_record;
729 bool is_deferred_open_async(const struct deferred_open_record *rec);
730 bool defer_smb1_sharing_violation(struct smb_request *req);
731 NTSTATUS create_directory(connection_struct *conn, struct smb_request *req,
732                           struct smb_filename *smb_dname);
733 void msg_file_was_renamed(struct messaging_context *msg,
734                           void *private_data,
735                           uint32_t msg_type,
736                           struct server_id server_id,
737                           DATA_BLOB *data);
738 struct fsp_lease *find_fsp_lease(struct files_struct *new_fsp,
739                                  const struct smb2_lease_key *key,
740                                  uint32_t current_state,
741                                  uint16_t lease_version,
742                                  uint16_t lease_epoch);
743 NTSTATUS create_file_default(connection_struct *conn,
744                              struct smb_request *req,
745                              struct smb_filename * smb_fname,
746                              uint32_t access_mask,
747                              uint32_t share_access,
748                              uint32_t create_disposition,
749                              uint32_t create_options,
750                              uint32_t file_attributes,
751                              uint32_t oplock_request,
752                              const struct smb2_lease *lease,
753                              uint64_t allocation_size,
754                              uint32_t private_flags,
755                              struct security_descriptor *sd,
756                              struct ea_list *ea_list,
757                              files_struct **result,
758                              int *pinfo,
759                              const struct smb2_create_blobs *in_context_blobs,
760                              struct smb2_create_blobs *out_context_blobs);
761
762 /* The following definitions come from smbd/oplock.c  */
763
764 uint32_t get_lease_type(struct share_mode_entry *e, struct file_id id);
765
766 void break_kernel_oplock(struct messaging_context *msg_ctx, files_struct *fsp);
767 NTSTATUS set_file_oplock(files_struct *fsp);
768 bool remove_oplock(files_struct *fsp);
769 bool downgrade_oplock(files_struct *fsp);
770 bool fsp_lease_update(struct files_struct *fsp);
771 NTSTATUS downgrade_lease(struct smbXsrv_client *client,
772                         uint32_t num_file_ids,
773                         const struct file_id *ids,
774                         const struct smb2_lease_key *key,
775                         uint32_t lease_state);
776 void contend_level2_oplocks_begin(files_struct *fsp,
777                                   enum level2_contention_type type);
778 void contend_level2_oplocks_end(files_struct *fsp,
779                                 enum level2_contention_type type);
780 void smbd_contend_level2_oplocks_begin(files_struct *fsp,
781                                   enum level2_contention_type type);
782 void smbd_contend_level2_oplocks_end(files_struct *fsp,
783                                 enum level2_contention_type type);
784 void share_mode_entry_to_message(char *msg, const struct file_id *id,
785                                  const struct share_mode_entry *e);
786 void message_to_share_mode_entry(struct file_id *id,
787                                  struct share_mode_entry *e,
788                                  const char *msg);
789 bool init_oplocks(struct smbd_server_connection *sconn);
790 void init_kernel_oplocks(struct smbd_server_connection *sconn);
791
792 /* The following definitions come from smbd/oplock_linux.c  */
793
794 int linux_set_lease_sighandler(int fd);
795 int linux_setlease(int fd, int leasetype);
796 struct kernel_oplocks *linux_init_kernel_oplocks(struct smbd_server_connection *sconn);
797
798 /* The following definitions come from smbd/password.c  */
799
800 void invalidate_vuid(struct smbd_server_connection *sconn, uint64_t vuid);
801 int register_homes_share(const char *username);
802
803 /* The following definitions come from smbd/pipes.c  */
804
805 NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
806                       struct files_struct **pfsp);
807 void reply_open_pipe_and_X(connection_struct *conn, struct smb_request *req);
808 void reply_pipe_write(struct smb_request *req);
809 void reply_pipe_write_and_X(struct smb_request *req);
810 void reply_pipe_read_and_X(struct smb_request *req);
811
812 /* The following definitions come from smbd/posix_acls.c  */
813
814 mode_t unix_perms_to_acl_perms(mode_t mode, int r_mask, int w_mask, int x_mask);
815 int map_acl_perms_to_permset(mode_t mode, SMB_ACL_PERMSET_T *p_permset);
816 uint32_t map_canon_ace_perms(int snum,
817                                 enum security_ace_type *pacl_type,
818                                 mode_t perms,
819                                 bool directory_ace);
820 NTSTATUS unpack_nt_owners(connection_struct *conn, uid_t *puser, gid_t *pgrp, uint32_t security_info_sent, const struct security_descriptor *psd);
821 bool current_user_in_group(connection_struct *conn, gid_t gid);
822 SMB_ACL_T free_empty_sys_acl(connection_struct *conn, SMB_ACL_T the_acl);
823 NTSTATUS posix_fget_nt_acl(struct files_struct *fsp, uint32_t security_info,
824                            TALLOC_CTX *mem_ctx,
825                            struct security_descriptor **ppdesc);
826 NTSTATUS posix_get_nt_acl(struct connection_struct *conn,
827                         const struct smb_filename *smb_fname_in,
828                         uint32_t security_info,
829                         TALLOC_CTX *mem_ctx,
830                         struct security_descriptor **ppdesc);
831 NTSTATUS try_chown(files_struct *fsp, uid_t uid, gid_t gid);
832 NTSTATUS set_nt_acl(files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd);
833 int get_acl_group_bits( connection_struct *conn,
834                         const struct smb_filename *smb_fname,
835                         mode_t *mode);
836 int inherit_access_posix_acl(connection_struct *conn,
837                         struct smb_filename *inherit_from_dir,
838                         const struct smb_filename *smb_fname,
839                         mode_t mode);
840 NTSTATUS set_unix_posix_default_acl(connection_struct *conn,
841                                 files_struct *fsp,
842                                 uint16_t num_def_acls, const char *pdata);
843 NTSTATUS set_unix_posix_acl(connection_struct *conn, files_struct *fsp,
844                                 uint16_t num_acls,
845                                 const char *pdata);
846 int posix_sys_acl_blob_get_file(vfs_handle_struct *handle,
847                                 const struct smb_filename *smb_fname,
848                                 TALLOC_CTX *mem_ctx,
849                                 char **blob_description,
850                                 DATA_BLOB *blob);
851 int posix_sys_acl_blob_get_fd(vfs_handle_struct *handle,
852                               files_struct *fsp,
853                               TALLOC_CTX *mem_ctx,
854                               char **blob_description,
855                               DATA_BLOB *blob);
856
857 enum default_acl_style {DEFAULT_ACL_POSIX, DEFAULT_ACL_WINDOWS, DEFAULT_ACL_EVERYONE};
858
859 const struct enum_list *get_default_acl_style_list(void);
860
861 NTSTATUS make_default_filesystem_acl(
862         TALLOC_CTX *ctx,
863         enum default_acl_style acl_style,
864         const char *name,
865         const SMB_STRUCT_STAT *psbuf,
866         struct security_descriptor **ppdesc);
867
868 /* The following definitions come from smbd/process.c  */
869
870 bool srv_send_smb(struct smbXsrv_connection *xconn, char *buffer,
871                   bool no_signing, uint32_t seqnum,
872                   bool do_encrypt,
873                   struct smb_perfcount_data *pcd);
874 size_t srv_set_message(char *buf,
875                        size_t num_words,
876                        size_t num_bytes,
877                        bool zero);
878 void remove_deferred_open_message_smb(struct smbXsrv_connection *xconn,
879                                       uint64_t mid);
880 bool schedule_deferred_open_message_smb(struct smbXsrv_connection *xconn,
881                                         uint64_t mid);
882 bool open_was_deferred(struct smbXsrv_connection *xconn, uint64_t mid);
883 bool get_deferred_open_message_state(struct smb_request *smbreq,
884                                 struct timeval *p_request_time,
885                                 struct deferred_open_record **open_rec);
886 bool push_deferred_open_message_smb(struct smb_request *req,
887                                     struct timeval timeout,
888                                     struct file_id id,
889                                     struct deferred_open_record *open_rec);
890 NTSTATUS allow_new_trans(struct trans_state *list, uint64_t mid);
891 void reply_outbuf(struct smb_request *req, uint8_t num_words, uint32_t num_bytes);
892 void smb_request_done(struct smb_request *req);
893 const char *smb_fn_name(int type);
894 void add_to_common_flags2(uint32_t v);
895 void remove_from_common_flags2(uint32_t v);
896 void construct_reply_common_req(struct smb_request *req, char *outbuf);
897 bool smb1_is_chain(const uint8_t *buf);
898 bool smb1_walk_chain(const uint8_t *buf,
899                      bool (*fn)(uint8_t cmd,
900                                 uint8_t wct, const uint16_t *vwv,
901                                 uint16_t num_bytes, const uint8_t *bytes,
902                                 void *private_data),
903                      void *private_data);
904 unsigned smb1_chain_length(const uint8_t *buf);
905 bool smb1_parse_chain(TALLOC_CTX *mem_ctx, const uint8_t *buf,
906                       struct smbXsrv_connection *xconn,
907                       bool encrypted, uint32_t seqnum,
908                       struct smb_request ***reqs, unsigned *num_reqs);
909 bool req_is_in_chain(const struct smb_request *req);
910 void smbd_process(struct tevent_context *ev_ctx,
911                   struct messaging_context *msg_ctx,
912                   struct dcesrv_context *dce_ctx,
913                   int sock_fd,
914                   bool interactive);
915 bool fork_echo_handler(struct smbXsrv_connection *xconn);
916
917 /* The following definitions come from smbd/quotas.c  */
918
919 bool disk_quotas(connection_struct *conn, struct smb_filename *fname,
920                  uint64_t *bsize, uint64_t *dfree, uint64_t *dsize);
921
922 /* The following definitions come from smbd/reply.c  */
923
924 NTSTATUS check_path_syntax(char *path);
925 NTSTATUS check_path_syntax_posix(char *path);
926 size_t srvstr_get_path(TALLOC_CTX *ctx,
927                         const char *inbuf,
928                         uint16_t smb_flags2,
929                         char **pp_dest,
930                         const char *src,
931                         size_t src_len,
932                         int flags,
933                         NTSTATUS *err);
934 size_t srvstr_get_path_posix(TALLOC_CTX *ctx,
935                         const char *inbuf,
936                         uint16_t smb_flags2,
937                         char **pp_dest,
938                         const char *src,
939                         size_t src_len,
940                         int flags,
941                         NTSTATUS *err);
942 size_t srvstr_get_path_req(TALLOC_CTX *mem_ctx, struct smb_request *req,
943                            char **pp_dest, const char *src, int flags,
944                            NTSTATUS *err);
945 size_t srvstr_pull_req_talloc(TALLOC_CTX *ctx, struct smb_request *req,
946                               char **dest, const uint8_t *src, int flags);
947 bool check_fsp_open(connection_struct *conn, struct smb_request *req,
948                     files_struct *fsp);
949 bool check_fsp(connection_struct *conn, struct smb_request *req,
950                files_struct *fsp);
951 bool check_fsp_ntquota_handle(connection_struct *conn, struct smb_request *req,
952                               files_struct *fsp);
953 void reply_special(struct smbXsrv_connection *xconn, char *inbuf, size_t inbuf_size);
954 void reply_tcon(struct smb_request *req);
955 void reply_tcon_and_X(struct smb_request *req);
956 void reply_unknown_new(struct smb_request *req, uint8_t type);
957 void reply_ioctl(struct smb_request *req);
958 void reply_checkpath(struct smb_request *req);
959 void reply_getatr(struct smb_request *req);
960 void reply_setatr(struct smb_request *req);
961 void reply_dskattr(struct smb_request *req);
962 void reply_search(struct smb_request *req);
963 void reply_fclose(struct smb_request *req);
964 void reply_open(struct smb_request *req);
965 void reply_open_and_X(struct smb_request *req);
966 void reply_ulogoffX(struct smb_request *req);
967 void reply_mknew(struct smb_request *req);
968 void reply_ctemp(struct smb_request *req);
969 NTSTATUS unlink_internals(connection_struct *conn,
970                         struct smb_request *req,
971                         uint32_t dirtype,
972                         struct smb_filename *smb_fname,
973                         bool has_wcard);
974 void reply_unlink(struct smb_request *req);
975 ssize_t fake_sendfile(struct smbXsrv_connection *xconn, files_struct *fsp,
976                       off_t startpos, size_t nread);
977 ssize_t sendfile_short_send(struct smbXsrv_connection *xconn,
978                             files_struct *fsp,
979                             ssize_t nread,
980                             size_t headersize,
981                             size_t smb_maxcnt);
982 void reply_readbraw(struct smb_request *req);
983 void reply_lockread(struct smb_request *req);
984 size_t setup_readX_header(char *outbuf, size_t smb_maxcnt);
985 void reply_read(struct smb_request *req);
986 void reply_read_and_X(struct smb_request *req);
987 void error_to_writebrawerr(struct smb_request *req);
988 void reply_writebraw(struct smb_request *req);
989 void reply_writeunlock(struct smb_request *req);
990 void reply_write(struct smb_request *req);
991 bool is_valid_writeX_buffer(struct smbXsrv_connection *xconn,
992                             const uint8_t *inbuf);
993 void reply_write_and_X(struct smb_request *req);
994 void reply_lseek(struct smb_request *req);
995 void reply_flush(struct smb_request *req);
996 void reply_exit(struct smb_request *req);
997 void reply_close(struct smb_request *req);
998 void reply_writeclose(struct smb_request *req);
999 void reply_lock(struct smb_request *req);
1000 void reply_unlock(struct smb_request *req);
1001 void reply_tdis(struct smb_request *req);
1002 void reply_echo(struct smb_request *req);
1003 void reply_printopen(struct smb_request *req);
1004 void reply_printclose(struct smb_request *req);
1005 void reply_printqueue(struct smb_request *req);
1006 void reply_printwrite(struct smb_request *req);
1007 void reply_mkdir(struct smb_request *req);
1008 void reply_rmdir(struct smb_request *req);
1009 NTSTATUS rename_internals_fsp(connection_struct *conn,
1010                         files_struct *fsp,
1011                         const struct smb_filename *smb_fname_dst_in,
1012                         const char *dst_original_lcomp,
1013                         uint32_t attrs,
1014                         bool replace_if_exists);
1015 NTSTATUS rename_internals(TALLOC_CTX *ctx,
1016                         connection_struct *conn,
1017                         struct smb_request *req,
1018                         struct smb_filename *smb_fname_src,
1019                         const char *src_original_lcomp,
1020                         struct smb_filename *smb_fname_dst,
1021                         const char *dst_original_lcomp,
1022                         uint32_t attrs,
1023                         bool replace_if_exists,
1024                         uint32_t access_mask);
1025 void reply_mv(struct smb_request *req);
1026 NTSTATUS copy_file(TALLOC_CTX *ctx,
1027                         connection_struct *conn,
1028                         struct smb_filename *smb_fname_src,
1029                         struct smb_filename *smb_fname_dst,
1030                         int ofun,
1031                         int count,
1032                         bool target_is_directory);
1033 void reply_copy(struct smb_request *req);
1034 uint64_t get_lock_pid(const uint8_t *data, int data_offset,
1035                     bool large_file_format);
1036 uint64_t get_lock_count(const uint8_t *data, int data_offset,
1037                         bool large_file_format);
1038 uint64_t get_lock_offset(const uint8_t *data, int data_offset,
1039                          bool large_file_format);
1040 void reply_lockingX(struct smb_request *req);
1041 void reply_readbmpx(struct smb_request *req);
1042 void reply_readbs(struct smb_request *req);
1043 void reply_setattrE(struct smb_request *req);
1044 void reply_writebmpx(struct smb_request *req);
1045 void reply_writebs(struct smb_request *req);
1046 void reply_getattrE(struct smb_request *req);
1047
1048 /* The following definitions come from smbd/seal.c  */
1049
1050 bool is_encrypted_packet(const uint8_t *inbuf);
1051 void srv_free_enc_buffer(struct smbXsrv_connection *xconn, char *buf);
1052 NTSTATUS srv_decrypt_buffer(struct smbXsrv_connection *xconn, char *buf);
1053 NTSTATUS srv_encrypt_buffer(struct smbXsrv_connection *xconn, char *buf,
1054                             char **buf_out);
1055 NTSTATUS srv_request_encryption_setup(connection_struct *conn,
1056                                         unsigned char **ppdata,
1057                                         size_t *p_data_size,
1058                                         unsigned char **pparam,
1059                                         size_t *p_param_size);
1060 NTSTATUS srv_encryption_start(connection_struct *conn);
1061 void server_encryption_shutdown(struct smbXsrv_connection *xconn);
1062
1063 /* The following definitions come from smbd/sec_ctx.c  */
1064
1065 bool unix_token_equal(const struct security_unix_token *t1, const struct security_unix_token *t2);
1066 bool push_sec_ctx(void);
1067 void set_sec_ctx(uid_t uid, gid_t gid, int ngroups, gid_t *groups, const struct security_token *token);
1068 void set_root_sec_ctx(void);
1069 bool pop_sec_ctx(void);
1070 void init_sec_ctx(void);
1071 const struct security_token *sec_ctx_active_token(void);
1072
1073 /* The following definitions come from smbd/server.c  */
1074
1075 struct memcache *smbd_memcache(void);
1076 bool snum_is_shared_printer(int snum);
1077 void delete_and_reload_printers(void);
1078 bool reload_services(struct smbd_server_connection *sconn,
1079                      bool (*snumused) (struct smbd_server_connection *, int),
1080                      bool test);
1081
1082 /* The following definitions come from smbd/server_exit.c  */
1083
1084 void smbd_exit_server(const char *reason) _NORETURN_;
1085 void smbd_exit_server_cleanly(const char *const reason) _NORETURN_;
1086
1087 /* The following definitions come from smbd/service.c  */
1088
1089 bool set_conn_connectpath(connection_struct *conn, const char *connectpath);
1090 bool canonicalize_connect_path(connection_struct *conn);
1091 NTSTATUS set_conn_force_user_group(connection_struct *conn, int snum);
1092 void set_current_case_sensitive(connection_struct *conn, uint16_t flags);
1093 bool chdir_current_service(connection_struct *conn);
1094 void load_registry_shares(void);
1095 int add_home_service(const char *service, const char *username, const char *homedir);
1096 int find_service(TALLOC_CTX *ctx, const char *service, char **p_service_out);
1097 connection_struct *make_connection_smb2(struct smbd_smb2_request *req,
1098                                         struct smbXsrv_tcon *tcon,
1099                                         int snum,
1100                                         const char *pdev,
1101                                         NTSTATUS *pstatus);
1102 connection_struct *make_connection(struct smb_request *req,
1103                                    NTTIME now,
1104                                    const char *service_in,
1105                                    const char *pdev, uint64_t vuid,
1106                                    NTSTATUS *status);
1107 void close_cnum(connection_struct *conn, uint64_t vuid);
1108
1109 /* The following definitions come from smbd/session.c  */
1110 struct sessionid;
1111 struct smbXsrv_session;
1112 bool session_init(void);
1113 bool session_claim(struct smbXsrv_session *session);
1114 void session_yield(struct smbXsrv_session *session);
1115 int list_sessions(TALLOC_CTX *mem_ctx, struct sessionid **session_list);
1116 int find_sessions(TALLOC_CTX *mem_ctx, const char *username,
1117                   const char *machine, struct sessionid **session_list);
1118
1119 /* The following definitions come from smbd/sesssetup.c  */
1120
1121 void reply_sesssetup_and_X(struct smb_request *req);
1122
1123 /* The following definitions come from smbd/share_access.c  */
1124
1125 bool token_contains_name_in_list(const char *username,
1126                                  const char *domain,
1127                                  const char *sharename,
1128                                  const struct security_token *token,
1129                                  const char **list);
1130 bool user_ok_token(const char *username, const char *domain,
1131                    const struct security_token *token, int snum);
1132 bool is_share_read_only_for_token(const char *username,
1133                                   const char *domain,
1134                                   const struct security_token *token,
1135                                   connection_struct *conn);
1136
1137 /* The following definitions come from smbd/srvstr.c  */
1138
1139 NTSTATUS srvstr_push_fn(const char *base_ptr, uint16_t smb_flags2, void *dest,
1140                       const char *src, int dest_len, int flags, size_t *ret_len);
1141 ssize_t message_push_string(uint8_t **outbuf, const char *str, int flags);
1142
1143 /* The following definitions come from smbd/statcache.c  */
1144
1145 void stat_cache_add( const char *full_orig_name,
1146                 const char *translated_path,
1147                 NTTIME twrp,
1148                 bool case_sensitive);
1149 bool stat_cache_lookup(connection_struct *conn,
1150                         bool posix_paths,
1151                         char **pp_name,
1152                         char **pp_dirpath,
1153                         char **pp_start,
1154                         NTTIME twrp,
1155                         SMB_STRUCT_STAT *pst);
1156 void smbd_send_stat_cache_delete_message(struct messaging_context *msg_ctx,
1157                                     const char *name);
1158 void send_stat_cache_delete_message(struct messaging_context *msg_ctx,
1159                                     const char *name);
1160 void stat_cache_delete(const char *name);
1161 struct TDB_DATA;
1162 unsigned int fast_string_hash(struct TDB_DATA *key);
1163 bool reset_stat_cache( void );
1164
1165 /* The following definitions come from smbd/statvfs.c  */
1166
1167 int sys_statvfs(const char *path, vfs_statvfs_struct *statbuf);
1168
1169 /* The following definitions come from smbd/trans2.c  */
1170
1171 NTSTATUS check_access_fsp(const struct files_struct *fsp,
1172                           uint32_t access_mask);
1173 uint64_t smb_roundup(connection_struct *conn, uint64_t val);
1174 bool samba_private_attr_name(const char *unix_ea_name);
1175 NTSTATUS get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn,
1176                         files_struct *fsp,
1177                         const struct smb_filename *smb_fname,
1178                         const char *ea_name,
1179                         struct ea_struct *pea);
1180 NTSTATUS get_ea_names_from_file(TALLOC_CTX *mem_ctx,
1181                         connection_struct *conn,
1182                         files_struct *fsp,
1183                         const struct smb_filename *smb_fname,
1184                         char ***pnames,
1185                         size_t *pnum_names);
1186 NTSTATUS set_ea(connection_struct *conn, files_struct *fsp,
1187                 const struct smb_filename *smb_fname, struct ea_list *ea_list);
1188 struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used);
1189 void send_trans2_replies(connection_struct *conn,
1190                         struct smb_request *req,
1191                         NTSTATUS status,
1192                          const char *params,
1193                          int paramsize,
1194                          const char *pdata,
1195                          int datasize,
1196                          int max_data_bytes);
1197 unsigned char *create_volume_objectid(connection_struct *conn, unsigned char objid[16]);
1198 NTSTATUS hardlink_internals(TALLOC_CTX *ctx,
1199                 connection_struct *conn,
1200                 struct smb_request *req,
1201                 bool overwrite_if_exists,
1202                 const struct smb_filename *smb_fname_old,
1203                 struct smb_filename *smb_fname_new);
1204 NTSTATUS smb_set_file_time(connection_struct *conn,
1205                            files_struct *fsp,
1206                            const struct smb_filename *smb_fname,
1207                            struct smb_file_time *ft,
1208                            bool setting_write_time);
1209 void reply_findclose(struct smb_request *req);
1210 void reply_findnclose(struct smb_request *req);
1211 void reply_trans2(struct smb_request *req);
1212 void reply_transs2(struct smb_request *req);
1213
1214 enum perm_type {
1215         PERM_NEW_FILE,
1216         PERM_NEW_DIR,
1217         PERM_EXISTING_FILE,
1218         PERM_EXISTING_DIR
1219 };
1220
1221 NTSTATUS unix_perms_from_wire(connection_struct *conn,
1222                               const SMB_STRUCT_STAT *psbuf,
1223                               uint32_t perms,
1224                               enum perm_type ptype,
1225                               mode_t *ret_perms);
1226
1227 /* The following definitions come from smbd/uid.c  */
1228
1229 bool change_to_guest(void);
1230 NTSTATUS check_user_share_access(connection_struct *conn,
1231                                 const struct auth_session_info *session_info,
1232                                 uint32_t *p_share_access,
1233                                 bool *p_readonly_share);
1234 bool change_to_user_and_service(connection_struct *conn, uint64_t vuid);
1235 bool change_to_user_and_service_by_fsp(struct files_struct *fsp);
1236 bool smbd_change_to_root_user(void);
1237 bool smbd_become_authenticated_pipe_user(struct auth_session_info *session_info);
1238 bool smbd_unbecome_authenticated_pipe_user(void);
1239 void become_root(void);
1240 void unbecome_root(void);
1241 void smbd_become_root(void);
1242 void smbd_unbecome_root(void);
1243 bool become_user_without_service(connection_struct *conn, uint64_t vuid);
1244 bool become_user_without_service_by_fsp(struct files_struct *fsp);
1245 bool become_user_without_service_by_session(connection_struct *conn,
1246                             const struct auth_session_info *session_info);
1247 bool unbecome_user_without_service(void);
1248 uid_t get_current_uid(connection_struct *conn);
1249 gid_t get_current_gid(connection_struct *conn);
1250 const struct security_unix_token *get_current_utok(connection_struct *conn);
1251 const struct security_token *get_current_nttok(connection_struct *conn);
1252
1253 /* The following definitions come from smbd/utmp.c  */
1254
1255 void sys_utmp_claim(const char *username, const char *hostname,
1256                     const char *id_str, int id_num);
1257 void sys_utmp_yield(const char *username, const char *hostname,
1258                     const char *id_str, int id_num);
1259
1260 /* The following definitions come from smbd/vfs.c  */
1261
1262 bool vfs_init_custom(connection_struct *conn, const char *vfs_object);
1263 bool smbd_vfs_init(connection_struct *conn);
1264 NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname);
1265 bool vfs_valid_pread_range(off_t offset, size_t length);
1266 bool vfs_valid_pwrite_range(off_t offset, size_t length);
1267 ssize_t vfs_pwrite_data(struct smb_request *req,
1268                         files_struct *fsp,
1269                         const char *buffer,
1270                         size_t N,
1271                         off_t offset);
1272 int vfs_allocate_file_space(files_struct *fsp, uint64_t len);
1273 int vfs_set_filelen(files_struct *fsp, off_t len);
1274 int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len);
1275 int vfs_fill_sparse(files_struct *fsp, off_t len);
1276 int vfs_set_blocking(files_struct *fsp, bool set);
1277 off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n);
1278 const char *vfs_readdirname(connection_struct *conn, void *p,
1279                             SMB_STRUCT_STAT *sbuf, char **talloced);
1280 int vfs_ChDir(connection_struct *conn,
1281                         const struct smb_filename *smb_fname);
1282 struct smb_filename *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn);
1283 NTSTATUS check_reduced_name(connection_struct *conn,
1284                         const struct smb_filename *cwd_fname,
1285                         const struct smb_filename *smb_fname);
1286 NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
1287                         const struct smb_filename *smb_fname,
1288                         struct smb_request *smbreq);
1289 int vfs_stat_smb_basename(struct connection_struct *conn,
1290                         const struct smb_filename *smb_fname_in,
1291                         SMB_STRUCT_STAT *psbuf);
1292 NTSTATUS vfs_stat_fsp(files_struct *fsp);
1293 NTSTATUS vfs_streaminfo(connection_struct *conn,
1294                         struct files_struct *fsp,
1295                         const struct smb_filename *smb_fname,
1296                         TALLOC_CTX *mem_ctx,
1297                         unsigned int *num_streams,
1298                         struct stream_struct **streams);
1299 void init_smb_file_time(struct smb_file_time *ft);
1300 int vfs_fake_fd(void);
1301
1302 /* The following definitions come from smbd/avahi_register.c */
1303
1304 void *avahi_start_register(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
1305                            uint16_t port);
1306
1307 /* The following definitions come from smbd/smb2_create.c */
1308
1309 NTSTATUS vfs_default_durable_cookie(struct files_struct *fsp,
1310                                     TALLOC_CTX *mem_ctx,
1311                                     DATA_BLOB *cookie_blob);
1312 NTSTATUS vfs_default_durable_disconnect(struct files_struct *fsp,
1313                                         const DATA_BLOB old_cookie,
1314                                         TALLOC_CTX *mem_ctx,
1315                                         DATA_BLOB *new_cookie);
1316 NTSTATUS vfs_default_durable_reconnect(struct connection_struct *conn,
1317                                        struct smb_request *smb1req,
1318                                        struct smbXsrv_open *op,
1319                                        const DATA_BLOB old_cookie,
1320                                        TALLOC_CTX *mem_ctx,
1321                                        files_struct **result,
1322                                        DATA_BLOB *new_cookie);
1323
1324 #endif /* _SMBD_PROTO_H_ */