2f25778ab9f6ebde165fbbf8503d2c0f82beb775
[samba.git] / source3 / include / proto.h
1 /*
2  * Unix SMB/CIFS implementation.
3  * collected prototypes header
4  *
5  * frozen from "make proto" in May 2008
6  *
7  * Copyright (C) Michael Adam 2008
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #ifndef _PROTO_H_
24 #define _PROTO_H_
25
26 #include <sys/types.h>
27 #include <regex.h>
28
29 #include "lib/util/access.h"
30
31 /* The following definitions come from lib/adt_tree.c  */
32
33 /* The following definitions come from lib/audit.c  */
34
35 const char *audit_category_str(uint32_t category);
36 const char *audit_param_str(uint32_t category);
37 const char *audit_description_str(uint32_t category);
38 bool get_audit_category_from_param(const char *param, uint32_t *audit_category);
39 const char *audit_policy_str(TALLOC_CTX *mem_ctx, uint32_t policy);
40
41 /* The following definitions come from lib/charcnv.c  */
42
43 void gfree_charcnv(void);
44 size_t ucs2_align(const void *base_ptr, const void *p, int flags);
45 size_t push_ascii(void *dest, const char *src, size_t dest_len, int flags);
46 size_t push_ascii_fstring(void *dest, const char *src);
47 size_t push_ascii_nstring(void *dest, const char *src);
48 size_t pull_ascii(char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
49 size_t pull_ascii_fstring(char *dest, const void *src);
50 size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src);
51 size_t push_string_check_fn(void *dest, const char *src,
52                             size_t dest_len, int flags);
53 size_t push_string_base(const char *base, uint16_t flags2,
54                         void *dest, const char *src,
55                         size_t dest_len, int flags);
56 size_t pull_string_talloc(TALLOC_CTX *ctx,
57                         const void *base_ptr,
58                         uint16_t smb_flags2,
59                         char **ppdest,
60                         const void *src,
61                         size_t src_len,
62                         int flags);
63 size_t dos_PutUniCode(char *dst,const char *src, size_t len, bool null_terminate);
64 int rpcstr_push_talloc(TALLOC_CTX *ctx, smb_ucs2_t **dest, const char *src);
65
66 /* The following definitions come from lib/dmallocmsg.c  */
67
68 void register_dmalloc_msgs(struct messaging_context *msg_ctx);
69
70 /* The following definitions come from lib/dprintf.c  */
71
72 void display_set_stderr(void);
73
74 /* The following definitions come from lib/errmap_unix.c  */
75
76 NTSTATUS map_nt_error_from_unix(int unix_error);
77 int map_errno_from_nt_status(NTSTATUS status);
78
79 /* The following definitions come from lib/file_id.c  */
80
81 struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_STAT *sbuf);
82
83 NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx,
84                        struct connection_struct *conn,
85                        struct files_struct **_fsp);
86
87 #include "source3/lib/interface.h"
88
89 /* The following definitions come from lib/ldap_debug_handler.c  */
90
91 void init_ldap_debugging(void);
92
93 /* The following definitions come from lib/ldap_escape.c  */
94
95 char *escape_ldap_string(TALLOC_CTX *mem_ctx, const char *s);
96 char *escape_rdn_val_string_alloc(const char *s);
97
98 /* The following definitions come from lib/ms_fnmatch.c  */
99
100 int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
101                bool is_case_sensitive);
102
103 /* The following definitions come from lib/recvfile.c  */
104
105 ssize_t sys_recvfile(int fromfd,
106                         int tofd,
107                         off_t offset,
108                         size_t count);
109 ssize_t sys_recvfile(int fromfd,
110                         int tofd,
111                         off_t offset,
112                         size_t count);
113 ssize_t drain_socket(int sockfd, size_t count);
114
115 /* The following definitions come from lib/sendfile.c  */
116
117 ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, off_t offset, size_t count);
118
119 /* The following definitions come from lib/server_mutex.c  */
120
121 struct named_mutex *grab_named_mutex(TALLOC_CTX *mem_ctx, const char *name,
122                                      int timeout);
123
124 /* The following definitions come from lib/sharesec.c  */
125
126 NTSTATUS share_info_db_init(void);
127 struct security_descriptor *get_share_security( TALLOC_CTX *ctx, const char *servicename,
128                               size_t *psize);
129 NTSTATUS set_share_security(const char *share_name,
130                             struct security_descriptor *psd);
131 NTSTATUS delete_share_security(const char *servicename);
132 bool share_access_check(const struct security_token *token,
133                         const char *sharename,
134                         uint32_t desired_access,
135                         uint32_t *pgranted);
136 bool parse_usershare_acl(TALLOC_CTX *ctx, const char *acl_str, struct security_descriptor **ppsd);
137
138 /* The following definitions come from lib/smbrun.c  */
139
140 int smbrun_no_sanitize(const char *cmd, int *outfd, char * const *env);
141 int smbrun(const char *cmd, int *outfd, char * const *env);
142 int smbrunsecret(const char *cmd, const char *secret);
143
144 /* The following definitions come from lib/substitute.c  */
145
146 bool set_local_machine_name(const char *local_name, bool perm);
147 const char *get_local_machine_name(void);
148 bool set_remote_machine_name(const char *remote_name, bool perm);
149 const char *get_remote_machine_name(void);
150 void sub_set_smb_name(const char *name);
151 void set_current_user_info(const char *smb_name, const char *unix_name,
152                            const char *domain);
153 void sub_set_socket_ids(const char *peeraddr, const char *peername,
154                         const char *sockaddr);
155 const char *get_current_username(void);
156 void standard_sub_basic(const char *smb_name, const char *domain_name,
157                         char *str, size_t len);
158 char *talloc_sub_basic(TALLOC_CTX *mem_ctx, const char *smb_name,
159                        const char *domain_name, const char *str);
160 char *talloc_sub_specified(TALLOC_CTX *mem_ctx,
161                         const char *input_string,
162                         const char *username,
163                         const char *grpname,
164                         const char *domain,
165                         uid_t uid,
166                         gid_t gid);
167 char *talloc_sub_advanced(TALLOC_CTX *mem_ctx,
168                           const char *servicename, const char *user,
169                           const char *connectpath, gid_t gid,
170                           const char *str);
171 char *talloc_sub_full(TALLOC_CTX *mem_ctx,
172                           const char *servicename, const char *user,
173                           const char *connectpath, gid_t gid,
174                           const char *smb_name, const char *domain_name,
175                           const char *str);
176
177 /* The following definitions come from lib/sysquotas.c  */
178
179 int sys_get_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
180 int sys_set_quota(const char *path, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
181
182 /* The following definitions come from lib/sysquotas_*.c  */
183
184 int sys_get_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
185 int sys_set_vfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
186
187 int sys_get_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
188 int sys_set_xfs_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
189
190 int sys_get_jfs2_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
191 int sys_set_jfs2_quota(const char *path, const char *bdev, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *dp);
192
193 int sys_get_nfs_quota(const char *path, const char *bdev,
194                       enum SMB_QUOTA_TYPE qtype,
195                       unid_t id, SMB_DISK_QUOTA *dp);
196 int sys_set_nfs_quota(const char *path, const char *bdev,
197                       enum SMB_QUOTA_TYPE qtype,
198                       unid_t id, SMB_DISK_QUOTA *dp);
199
200 /* The following definitions come from lib/system.c  */
201
202 ssize_t sys_send(int s, const void *msg, size_t len, int flags);
203 ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
204 int sys_fcntl_ptr(int fd, int cmd, void *arg);
205 int sys_fcntl_long(int fd, int cmd, long arg);
206 int sys_fcntl_int(int fd, int cmd, int arg);
207 void update_stat_ex_mtime(struct stat_ex *dst, struct timespec write_ts);
208 void update_stat_ex_itime(struct stat_ex *dst, struct timespec itime);
209 void update_stat_ex_create_time(struct stat_ex *dst, struct timespec create_time);
210 void update_stat_ex_file_id(struct stat_ex *dst, uint64_t file_id);
211 void update_stat_ex_from_saved_stat(struct stat_ex *dst,
212                                     const struct stat_ex *src);
213 int sys_stat(const char *fname, SMB_STRUCT_STAT *sbuf,
214              bool fake_dir_create_times);
215 int sys_fstat(int fd, SMB_STRUCT_STAT *sbuf,
216               bool fake_dir_create_times);
217 int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf,
218               bool fake_dir_create_times);
219 int sys_posix_fallocate(int fd, off_t offset, off_t len);
220 int sys_fallocate(int fd, uint32_t mode, off_t offset, off_t len);
221 void kernel_flock(int fd, uint32_t share_access, uint32_t access_mask);
222 DIR *sys_fdopendir(int fd);
223 int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev);
224 int sys_mknodat(int dirfd, const char *path, mode_t mode, SMB_DEV_T dev);
225 char *sys_getwd(void);
226 void set_effective_capability(enum smbd_capability capability);
227 void drop_effective_capability(enum smbd_capability capability);
228 long sys_random(void);
229 void sys_srandom(unsigned int seed);
230 int groups_max(void);
231 int sys_getgroups(int setlen, gid_t *gidset);
232 int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset);
233 uint32_t unix_dev_major(SMB_DEV_T dev);
234 uint32_t unix_dev_minor(SMB_DEV_T dev);
235 char *sys_realpath(const char *path);
236 #if 0
237 int sys_get_number_of_cores(void);
238 #endif
239
240 bool sys_have_proc_fds(void);
241 const char *sys_proc_fd_path(int fd, char *buf, int bufsize);
242
243 struct stat;
244 void init_stat_ex_from_stat (struct stat_ex *dst,
245                             const struct stat *src,
246                             bool fake_dir_create_times);
247
248 /* The following definitions come from lib/system_smbd.c  */
249
250 bool getgroups_unix_user(TALLOC_CTX *mem_ctx, const char *user,
251                          gid_t primary_gid,
252                          gid_t **ret_groups, uint32_t *p_ngroups);
253
254 /* The following definitions come from lib/tallocmsg.c  */
255
256 void register_msg_pool_usage(TALLOC_CTX *mem_ctx,
257                              struct messaging_context *msg_ctx);
258
259 /* The following definitions come from lib/time.c  */
260
261 void push_dos_date(uint8_t *buf, int offset, time_t unixdate, int zone_offset);
262 void push_dos_date2(uint8_t *buf,int offset,time_t unixdate, int zone_offset);
263 void push_dos_date3(uint8_t *buf,int offset,time_t unixdate, int zone_offset);
264 uint32_t convert_time_t_to_uint32_t(time_t t);
265 time_t convert_uint32_t_to_time_t(uint32_t u);
266 bool nt_time_is_zero(const NTTIME *nt);
267 time_t generalized_to_unix_time(const char *str);
268 int get_server_zone_offset(void);
269 int set_server_zone_offset(time_t t);
270 char *timeval_string(TALLOC_CTX *ctx, const struct timeval *tp, bool hires);
271 char *current_timestring(TALLOC_CTX *ctx, bool hires);
272 void srv_put_dos_date(char *buf,int offset,time_t unixdate);
273 void srv_put_dos_date2(char *buf,int offset, time_t unixdate);
274 void srv_put_dos_date3(char *buf,int offset,time_t unixdate);
275 void round_timespec(enum timestamp_set_resolution res, struct timespec *ts);
276 void put_long_date_timespec(enum timestamp_set_resolution res, char *p, struct timespec ts);
277 void put_long_date_full_timespec(enum timestamp_set_resolution res,
278                                  char *p,
279                                  const struct timespec *ts);
280 struct timespec pull_long_date_full_timespec(const char *p);
281 void put_long_date(char *p, time_t t);
282 void dos_filetime_timespec(struct timespec *tsp);
283 time_t make_unix_date(const void *date_ptr, int zone_offset);
284 time_t make_unix_date2(const void *date_ptr, int zone_offset);
285 time_t make_unix_date3(const void *date_ptr, int zone_offset);
286 time_t srv_make_unix_date(const void *date_ptr);
287 time_t srv_make_unix_date2(const void *date_ptr);
288 time_t srv_make_unix_date3(const void *date_ptr);
289 struct timespec interpret_long_date(const char *p);
290 void TimeInit(void);
291 void get_process_uptime(struct timeval *ret_time);
292 void get_startup_time(struct timeval *ret_time);
293 time_t nt_time_to_unix_abs(const NTTIME *nt);
294 void unix_to_nt_time_abs(NTTIME *nt, time_t t);
295 const char *time_to_asc(const time_t t);
296 const char *display_time(NTTIME nttime);
297 bool nt_time_is_set(const NTTIME *nt);
298
299 /* The following definitions come from lib/username.c  */
300
301 void flush_pwnam_cache(void);
302 char *get_user_home_dir(TALLOC_CTX *mem_ctx, const char *user);
303 struct passwd *Get_Pwnam_alloc(TALLOC_CTX *mem_ctx, const char *user);
304
305 /* The following definitions come from lib/util_names.c  */
306 const char *get_global_sam_name(void);
307 const char *my_sam_name(void);
308
309 /* The following definitions come from lib/util.c  */
310
311 enum protocol_types get_Protocol(void);
312 void set_Protocol(enum protocol_types  p);
313 void gfree_names(void);
314 void gfree_all( void );
315 const char *my_netbios_names(int i);
316 bool set_netbios_aliases(const char **str_array);
317 bool init_names(void);
318 bool file_exist_stat(const char *fname,SMB_STRUCT_STAT *sbuf,
319                      bool fake_dir_create_times);
320 bool socket_exist(const char *fname);
321 uint64_t get_file_size_stat(const SMB_STRUCT_STAT *sbuf);
322 bool check_same_dev_ino(const SMB_STRUCT_STAT *sbuf1,
323                         const SMB_STRUCT_STAT *sbuf2);
324 bool check_same_stat(const SMB_STRUCT_STAT *sbuf1,
325                         const SMB_STRUCT_STAT *sbuf2);
326 void show_msg(const char *buf);
327 int set_message_bcc(char *buf,int num_bytes);
328 ssize_t message_push_blob(uint8_t **outbuf, DATA_BLOB blob);
329 char *unix_clean_name(TALLOC_CTX *ctx, const char *s);
330 char *clean_name(TALLOC_CTX *ctx, const char *s);
331 ssize_t write_data_at_offset(int fd, const char *buffer, size_t N, off_t pos);
332 NTSTATUS init_before_fork(void);
333 NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
334                            struct tevent_context *ev_ctx,
335                            bool parent_longlived,
336                            const char *comment);
337 NTSTATUS smbd_reinit_after_fork(struct messaging_context *msg_ctx,
338                                 struct tevent_context *ev_ctx,
339                                 bool parent_longlived,
340                                 const char *comment);
341 void *malloc_(size_t size);
342 void *Realloc(void *p, size_t size, bool free_old_on_error);
343 void add_to_large_array(TALLOC_CTX *mem_ctx, size_t element_size,
344                         void *element, void *_array, uint32_t *num_elements,
345                         ssize_t *array_size);
346 char *get_myname(TALLOC_CTX *ctx);
347 char *get_mydnsdomname(TALLOC_CTX *ctx);
348 char *automount_lookup(TALLOC_CTX *ctx, const char *user_name);
349 char *automount_lookup(TALLOC_CTX *ctx, const char *user_name);
350 bool process_exists(const struct server_id pid);
351 const char *uidtoname(uid_t uid);
352 char *gidtoname(gid_t gid);
353 uid_t nametouid(const char *name);
354 gid_t nametogid(const char *name);
355 void smb_panic_s3(const char *why);
356 const char *readdirname(DIR *p);
357 bool is_in_path(const char *name, name_compare_entry *namelist, bool case_sensitive);
358 void set_namearray(name_compare_entry **ppname_array, const char *namelist);
359 void free_namearray(name_compare_entry *name_array);
360 bool fcntl_lock(int fd, int op, off_t offset, off_t count, int type);
361 bool fcntl_getlock(int fd, int op, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid);
362 int map_process_lock_to_ofd_lock(int op);
363 bool is_myname(const char *s);
364 void ra_lanman_string( const char *native_lanman );
365 const char *get_remote_arch_str(void);
366 enum remote_arch_types get_remote_arch_from_str(const char *remote_arch_string);
367 void set_remote_arch(enum remote_arch_types type);
368 enum remote_arch_types get_remote_arch(void);
369 bool remote_arch_cache_update(const struct GUID *client_guid);
370 bool remote_arch_cache_delete(const struct GUID *client_guid);
371 const char *tab_depth(int level, int depth);
372 int str_checksum(const char *s);
373 void zero_free(void *p, size_t size);
374 int set_maxfiles(int requested_max);
375 int smb_mkstemp(char *name_template);
376 void *smb_xmalloc_array(size_t size, unsigned int count);
377 char *myhostname(void);
378 char *myhostname_upper(void);
379 #include "lib/util_path.h"
380 bool parent_dirname(TALLOC_CTX *mem_ctx, const char *dir, char **parent,
381                     const char **name);
382 bool parent_smb_fname(TALLOC_CTX *mem_ctx,
383                       const struct smb_filename *path,
384                       struct smb_filename **_parent,
385                       struct smb_filename  **_name);
386 bool ms_has_wild(const char *s);
387 bool ms_has_wild_w(const smb_ucs2_t *s);
388 bool mask_match(const char *string, const char *pattern, bool is_case_sensitive);
389 bool mask_match_search(const char *string, const char *pattern, bool is_case_sensitive);
390 bool mask_match_list(const char *string, char **list, int listLen, bool is_case_sensitive);
391 #include "lib/util/unix_match.h"
392 bool name_to_fqdn(fstring fqdn, const char *name);
393 uint32_t map_share_mode_to_deny_mode(uint32_t share_access, uint32_t private_options);
394
395 #include "lib/util_procid.h"
396
397 struct server_id interpret_pid(const char *pid_string);
398 bool is_offset_safe(const char *buf_base, size_t buf_len, char *ptr, size_t off);
399 char *get_safe_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off);
400 char *get_safe_str_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off);
401 int get_safe_SVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval);
402 int get_safe_IVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval);
403 bool split_domain_user(TALLOC_CTX *mem_ctx,
404                        const char *full_name,
405                        char **domain,
406                        char **user);
407 const char *strip_hostname(const char *s);
408 bool any_nt_status_not_ok(NTSTATUS err1, NTSTATUS err2, NTSTATUS *result);
409 int timeval_to_msec(struct timeval t);
410 char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname);
411 bool is_executable(const char *fname);
412 bool map_open_params_to_ntcreate(const char *smb_base_fname,
413                                  int deny_mode, int open_func,
414                                  uint32_t *paccess_mask,
415                                  uint32_t *pshare_mode,
416                                  uint32_t *pcreate_disposition,
417                                  uint32_t *pcreate_options,
418                                  uint32_t *pprivate_flags);
419 struct security_unix_token *copy_unix_token(TALLOC_CTX *ctx, const struct security_unix_token *tok);
420 struct security_unix_token *root_unix_token(TALLOC_CTX *mem_ctx);
421 char *utok_string(TALLOC_CTX *mem_ctx, const struct security_unix_token *tok);
422 bool dir_check_ftype(uint32_t mode, uint32_t dirtype);
423
424 /* The following definitions come from lib/util_builtin.c  */
425
426 bool lookup_builtin_rid(TALLOC_CTX *mem_ctx, uint32_t rid, const char **name);
427 bool lookup_builtin_name(const char *name, uint32_t *rid);
428 const char *builtin_domain_name(void);
429 bool sid_check_is_builtin(const struct dom_sid *sid);
430 bool sid_check_is_in_builtin(const struct dom_sid *sid);
431 bool sid_check_is_wellknown_builtin(const struct dom_sid *sid);
432
433 /* The following definitions come from lib/util_nscd.c  */
434
435 void smb_nscd_flush_user_cache(void);
436 void smb_nscd_flush_group_cache(void);
437
438 /* The following definitions come from lib/util_nttoken.c  */
439
440 struct security_token *dup_nt_token(TALLOC_CTX *mem_ctx, const struct security_token *ptoken);
441 NTSTATUS merge_nt_token(TALLOC_CTX *mem_ctx,
442                         const struct security_token *token_1,
443                         const struct security_token *token_2,
444                         struct security_token **token_out);
445 bool token_sid_in_ace(const struct security_token *token, const struct security_ace *ace);
446
447 /* The following definitions come from lib/util_sec.c  */
448
449 void sec_init(void);
450 uid_t sec_initial_uid(void);
451 gid_t sec_initial_gid(void);
452 bool root_mode(void);
453 bool non_root_mode(void);
454 void gain_root_privilege(void);
455 void gain_root_group_privilege(void);
456 void set_effective_uid(uid_t uid);
457 void set_effective_gid(gid_t gid);
458 void save_re_uid(void);
459 void restore_re_uid_fromroot(void);
460 void restore_re_uid(void);
461 void save_re_gid(void);
462 void restore_re_gid(void);
463 int set_re_uid(void);
464 void become_user_permanently(uid_t uid, gid_t gid);
465 int set_thread_credentials(uid_t uid,
466                         gid_t gid,
467                         size_t setlen,
468                         const gid_t *gidset);
469 bool is_setuid_root(void) ;
470
471 /* The following definitions come from lib/util_sid.c  */
472
473 char *sid_to_fstring(fstring sidstr_out, const struct dom_sid *sid);
474 bool sid_linearize(uint8_t *outbuf, size_t len, const struct dom_sid *sid);
475 bool non_mappable_sid(struct dom_sid *sid);
476 char *sid_binstring_hex_talloc(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
477 struct netr_SamInfo3;
478 NTSTATUS sid_array_from_info3(TALLOC_CTX *mem_ctx,
479                               const struct netr_SamInfo3 *info3,
480                               struct dom_sid **user_sids,
481                               uint32_t *num_user_sids,
482                               bool include_user_group_rid);
483
484 /* The following definitions come from lib/util_sock.c  */
485
486 bool is_broadcast_addr(const struct sockaddr *pss);
487 bool is_loopback_ip_v4(struct in_addr ip);
488 bool is_loopback_addr(const struct sockaddr *pss);
489 bool is_zero_addr(const struct sockaddr_storage *pss);
490 void zero_ip_v4(struct in_addr *ip);
491 void in_addr_to_sockaddr_storage(struct sockaddr_storage *ss,
492                 struct in_addr ip);
493 bool same_net(const struct sockaddr *ip1,
494                 const struct sockaddr *ip2,
495                 const struct sockaddr *mask);
496 bool sockaddr_equal(const struct sockaddr *ip1,
497                 const struct sockaddr *ip2);
498 bool is_address_any(const struct sockaddr *psa);
499 uint16_t get_sockaddr_port(const struct sockaddr_storage *pss);
500 char *print_sockaddr(char *dest,
501                         size_t destlen,
502                         const struct sockaddr_storage *psa);
503 char *print_canonical_sockaddr(TALLOC_CTX *ctx,
504                         const struct sockaddr_storage *pss);
505 bool is_a_socket(int fd);
506 void set_socket_options(int fd, const char *options);
507 NTSTATUS read_fd_with_timeout(int fd, char *buf,
508                                   size_t mincnt, size_t maxcnt,
509                                   unsigned int time_out,
510                                   size_t *size_ret);
511 NTSTATUS read_data_ntstatus(int fd, char *buffer, size_t N);
512
513 NTSTATUS read_smb_length_return_keepalive(int fd, char *inbuf,
514                                           unsigned int timeout,
515                                           size_t *len);
516 NTSTATUS receive_smb_raw(int fd,
517                         char *buffer,
518                         size_t buflen,
519                         unsigned int timeout,
520                         size_t maxlen,
521                         size_t *p_len);
522 int open_socket_in(int type,
523                 uint16_t port,
524                 int dlevel,
525                 const struct sockaddr_storage *psock,
526                 bool rebind);
527 NTSTATUS open_socket_out(const struct sockaddr_storage *pss, uint16_t port,
528                          int timeout, int *pfd);
529 struct tevent_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
530                                         struct tevent_context *ev,
531                                         const struct sockaddr_storage *pss,
532                                         uint16_t port,
533                                         int timeout);
534 NTSTATUS open_socket_out_recv(struct tevent_req *req, int *pfd);
535 struct tevent_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx,
536                                               struct tevent_context *ev,
537                                               struct timeval wait_time,
538                                               const struct sockaddr_storage *pss,
539                                               uint16_t port,
540                                               int timeout);
541 NTSTATUS open_socket_out_defer_recv(struct tevent_req *req, int *pfd);
542 const char *get_peer_addr(int fd, char *addr, size_t addr_len);
543
544 struct tsocket_address;
545
546 int get_remote_hostname(const struct tsocket_address *remote_address,
547                         char **name,
548                         TALLOC_CTX *mem_ctx);
549
550 int create_pipe_sock(const char *socket_dir,
551                      const char *socket_name,
552                      mode_t dir_perms);
553 const char *get_mydnsfullname(void);
554 bool is_myname_or_ipaddr(const char *s);
555 int poll_one_fd(int fd, int events, int timeout, int *revents);
556 int poll_intr_one_fd(int fd, int events, int timeout, int *revents);
557
558 /* The following definitions come from lib/util_str.c  */
559
560 bool next_token(const char **ptr, char *buff, const char *sep, size_t bufsize);
561 bool strnequal(const char *s1,const char *s2,size_t n);
562 bool strcsequal(const char *s1,const char *s2);
563 bool strnorm(char *s, int case_default);
564 char *skip_string(const char *base, size_t len, char *buf);
565 size_t str_charnum(const char *s);
566 bool trim_char(char *s,char cfront,char cback);
567 bool strhasupper(const char *s);
568 bool strhaslower(const char *s);
569 bool in_list(const char *s, const char *list, bool casesensitive);
570 void fstring_sub(char *s,const char *pattern,const char *insert);
571 char *realloc_string_sub2(char *string,
572                         const char *pattern,
573                         const char *insert,
574                         bool remove_unsafe_characters,
575                         bool allow_trailing_dollar);
576 char *realloc_string_sub(char *string,
577                         const char *pattern,
578                         const char *insert);
579 char *talloc_string_sub2(TALLOC_CTX *mem_ctx, const char *src,
580                         const char *pattern,
581                         const char *insert,
582                         bool remove_unsafe_characters,
583                         bool replace_once,
584                         bool allow_trailing_dollar);
585 char *talloc_string_sub(TALLOC_CTX *mem_ctx,
586                         const char *src,
587                         const char *pattern,
588                         const char *insert);
589 void all_string_sub(char *s,const char *pattern,const char *insert, size_t len);
590 char *talloc_all_string_sub(TALLOC_CTX *ctx,
591                                 const char *src,
592                                 const char *pattern,
593                                 const char *insert);
594 char *octal_string(int i);
595 char *string_truncate(char *s, unsigned int length);
596 char *strchr_m(const char *src, char c);
597 char *strrchr_m(const char *s, char c);
598 char *strnrchr_m(const char *s, char c, unsigned int n);
599 char *strstr_m(const char *src, const char *findstr);
600 bool strlower_m(char *s);
601 bool strupper_m(char *s);
602 size_t strlen_m(const char *s);
603 size_t strlen_m_term(const char *s);
604 size_t strlen_m_term_null(const char *s);
605 int fstr_sprintf(fstring s, const char *fmt, ...);
606
607 uint64_t STR_TO_SMB_BIG_UINT(const char *nptr, const char **entptr);
608 uint64_t conv_str_size(const char * str);
609 int asprintf_strupper_m(char **strp, const char *fmt, ...)
610                         PRINTF_ATTRIBUTE(2,3);
611 char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...)
612                                  PRINTF_ATTRIBUTE(2,3);
613 char *talloc_asprintf_strlower_m(TALLOC_CTX *t, const char *fmt, ...)
614                                  PRINTF_ATTRIBUTE(2,3);
615 bool validate_net_name( const char *name,
616                 const char *invalid_chars,
617                 int max_len);
618 char *escape_shell_string(const char *src);
619 ssize_t full_path_tos(const char *dir, const char *name,
620                       char *tmpbuf, size_t tmpbuf_len,
621                       char **pdst, char **to_free);
622
623 /* The following definitions come from lib/version.c  */
624
625 const char *samba_version_string(void);
626
627 /* The following definitions come from lib/wins_srv.c  */
628
629 bool wins_srv_is_dead(struct in_addr wins_ip, struct in_addr src_ip);
630 void wins_srv_alive(struct in_addr wins_ip, struct in_addr src_ip);
631 void wins_srv_died(struct in_addr wins_ip, struct in_addr src_ip);
632 unsigned wins_srv_count(void);
633 char **wins_srv_tags(void);
634 void wins_srv_tags_free(char **list);
635 struct in_addr wins_srv_ip_tag(const char *tag, struct in_addr src_ip);
636 bool wins_server_tag_ips(const char *tag, TALLOC_CTX *mem_ctx,
637                          struct in_addr **pservers, size_t *pnum_servers);
638 unsigned wins_srv_count_tag(const char *tag);
639
640 #ifndef ASN1_MAX_OIDS
641 #define ASN1_MAX_OIDS 20
642 #endif
643 bool spnego_parse_negTokenInit(TALLOC_CTX *ctx,
644                                DATA_BLOB blob,
645                                char *OIDs[ASN1_MAX_OIDS],
646                                char **principal,
647                                DATA_BLOB *secblob);
648 DATA_BLOB spnego_gen_krb5_wrap(TALLOC_CTX *ctx, const DATA_BLOB ticket, const uint8_t tok_id[2]);
649
650 /* The following definitions come from libsmb/conncache.c  */
651
652 NTSTATUS check_negative_conn_cache( const char *domain, const char *server);
653 void add_failed_connection_entry(const char *domain, const char *server, NTSTATUS result) ;
654 void flush_negative_conn_cache_for_domain(const char *domain);
655
656 /* The following definitions come from libsmb/errormap.c  */
657
658 NTSTATUS dos_to_ntstatus(uint8_t eclass, uint32_t ecode);
659
660 /* The following definitions come from libsmb/namecache.c  */
661
662 bool namecache_store(const char *name,
663                         int name_type,
664                         size_t num_names,
665                         struct samba_sockaddr *sa_list);
666 bool namecache_fetch(TALLOC_CTX *ctx,
667                         const char *name,
668                         int name_type,
669                         struct samba_sockaddr **sa_list,
670                         size_t *num_names);
671 bool namecache_delete(const char *name, int name_type);
672 void namecache_flush(void);
673 bool namecache_status_store(const char *keyname, int keyname_type,
674                 int name_type, const struct sockaddr_storage *keyip,
675                 const char *srvname);
676 bool namecache_status_fetch(const char *keyname,
677                                 int keyname_type,
678                                 int name_type,
679                                 const struct sockaddr_storage *keyip,
680                                 char *srvname_out);
681
682 /* The following definitions come from libsmb/namequery_dc.c  */
683
684 bool get_dc_name(const char *domain,
685                 const char *realm,
686                 fstring srv_name,
687                 struct sockaddr_storage *ss_out);
688
689 /* The following definitions come from libsmb/smberr.c  */
690
691 const char *smb_dos_err_name(uint8_t e_class, uint16_t num);
692 const char *get_dos_error_msg(WERROR result);
693 const char *smb_dos_err_class(uint8_t e_class);
694 WERROR map_werror_from_unix(int error);
695
696 /* The following definitions come from libsmb/trusts_util.c  */
697
698 struct netlogon_creds_cli_context;
699 struct messaging_context;
700 struct dcerpc_binding_handle;
701 char *trust_pw_new_value(TALLOC_CTX *mem_ctx,
702                          enum netr_SchannelType sec_channel_type,
703                          int security);
704 NTSTATUS trust_pw_change(struct netlogon_creds_cli_context *context,
705                          struct messaging_context *msg_ctx,
706                          struct dcerpc_binding_handle *b,
707                          const char *domain,
708                          const char *dcname,
709                          bool force);
710
711 /* The following definitions come from lib/sessionid_tdb.c  */
712 struct sessionid;
713 NTSTATUS sessionid_traverse_read(int (*fn)(const char *key,
714                                            struct sessionid *session,
715                                            void *private_data),
716                                  void *private_data);
717
718 /* The following definitions come from lib/avahi.c */
719
720 struct AvahiPoll *tevent_avahi_poll(TALLOC_CTX *mem_ctx,
721                                     struct tevent_context *ev);
722
723 /* The following definitions come from libsmb/smbsock_connect.c */
724
725 struct tevent_req *smbsock_connect_send(TALLOC_CTX *mem_ctx,
726                                         struct tevent_context *ev,
727                                         const struct sockaddr_storage *addr,
728                                         uint16_t port,
729                                         const char *called_name,
730                                         int called_type,
731                                         const char *calling_name,
732                                         int calling_type);
733 NTSTATUS smbsock_connect_recv(struct tevent_req *req, int *sock,
734                               uint16_t *ret_port);
735 NTSTATUS smbsock_connect(const struct sockaddr_storage *addr, uint16_t port,
736                          const char *called_name, int called_type,
737                          const char *calling_name, int calling_type,
738                          int *pfd, uint16_t *ret_port, int sec_timeout);
739
740 struct tevent_req *smbsock_any_connect_send(TALLOC_CTX *mem_ctx,
741                                             struct tevent_context *ev,
742                                             const struct sockaddr_storage *addrs,
743                                             const char **called_names,
744                                             int *called_types,
745                                             const char **calling_names,
746                                             int *calling_types,
747                                             size_t num_addrs, uint16_t port);
748 NTSTATUS smbsock_any_connect_recv(struct tevent_req *req, int *pfd,
749                                   size_t *chosen_index, uint16_t *chosen_port);
750 NTSTATUS smbsock_any_connect(const struct sockaddr_storage *addrs,
751                              const char **called_names,
752                              int *called_types,
753                              const char **calling_names,
754                              int *calling_types,
755                              size_t num_addrs,
756                              uint16_t port,
757                              int sec_timeout,
758                              int *pfd, size_t *chosen_index,
759                              uint16_t *chosen_port);
760
761 /* The following definitions come from lib/util_wellknown.c  */
762
763 bool sid_check_is_wellknown_domain(const struct dom_sid *sid, const char **name);
764 bool sid_check_is_in_wellknown_domain(const struct dom_sid *sid);
765 bool lookup_wellknown_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid,
766                           const char **domain, const char **name);
767 bool lookup_wellknown_name(TALLOC_CTX *mem_ctx, const char *name,
768                            struct dom_sid *sid, const char **domain);
769
770 /* The following definitions come from lib/util_specialsids.c  */
771 bool sid_check_is_asserted_identity(const struct dom_sid *sid);
772 bool sid_check_is_in_asserted_identity(const struct dom_sid *sid);
773 const char *asserted_identity_domain_name(void);
774
775 /* The following definitions come from lib/filename_util.c */
776
777 NTSTATUS get_full_smb_filename(TALLOC_CTX *ctx, const struct smb_filename *smb_fname,
778                               char **full_name);
779 struct smb_filename *synthetic_smb_fname(TALLOC_CTX *mem_ctx,
780                                          const char *base_name,
781                                          const char *stream_name,
782                                          const SMB_STRUCT_STAT *psbuf,
783                                          NTTIME twrp,
784                                          uint32_t flags);
785 struct smb_filename *full_path_from_dirfsp_atname(
786         TALLOC_CTX *mem_ctx,
787         const struct files_struct *dirfsp,
788         const struct smb_filename *atname);
789 struct smb_filename *synthetic_smb_fname_split(TALLOC_CTX *ctx,
790                                                 const char *fname,
791                                                 bool posix_path);
792 const char *smb_fname_str_dbg(const struct smb_filename *smb_fname);
793 const char *fsp_str_dbg(const struct files_struct *fsp);
794 const char *fsp_fnum_dbg(const struct files_struct *fsp);
795 struct smb_filename *cp_smb_filename(TALLOC_CTX *mem_ctx,
796                                      const struct smb_filename *in);
797 struct smb_filename *cp_smb_filename_nostream(TALLOC_CTX *mem_ctx,
798                                      const struct smb_filename *in);
799 bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname);
800 bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname);
801 bool is_named_stream(const struct smb_filename *smb_fname);
802 bool is_invalid_windows_ea_name(const char *name);
803 bool ea_list_has_invalid_name(struct ea_list *ea_list);
804 bool split_stream_filename(TALLOC_CTX *ctx,
805                         const char *filename_in,
806                         char **filename_out,
807                         char **streamname_out);
808
809 /* The following definitions come from lib/dummyroot.c */
810
811 void become_root(void);
812 void unbecome_root(void);
813
814 /* The following definitions come from lib/smbd_shim.c */
815
816 int find_service(TALLOC_CTX *ctx, const char *service_in, char **p_service_out);
817 void send_stat_cache_delete_message(struct messaging_context *msg_ctx,
818                                     const char *name);
819 NTSTATUS can_delete_directory_fsp(files_struct *fsp);
820 bool change_to_root_user(void);
821 bool become_authenticated_pipe_user(struct auth_session_info *session_info);
822 bool unbecome_authenticated_pipe_user(void);
823
824 void contend_level2_oplocks_begin(files_struct *fsp,
825                                   enum level2_contention_type type);
826 void contend_level2_oplocks_end(files_struct *fsp,
827                                 enum level2_contention_type type);
828
829 /* The following definitions come from lib/per_thread_cwd.c */
830
831 void per_thread_cwd_check(void);
832 bool per_thread_cwd_supported(void);
833 void per_thread_cwd_disable(void);
834 void per_thread_cwd_activate(void);
835
836 #endif /*  _PROTO_H_  */