r15450: Change profiling data macros to use stack variables rather than
[samba.git] / source / include / includes.h
1 #ifndef _INCLUDES_H
2 #define _INCLUDES_H
3 /* 
4    Unix SMB/CIFS implementation.
5    Machine customisation and include handling
6    Copyright (C) Andrew Tridgell 1994-1998
7    Copyright (C) 2002 by Martin Pool <mbp@samba.org>
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 2 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, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 /* work around broken krb5.h on sles9 */
25 #ifdef SIZEOF_LONG
26 #undef SIZEOF_LONG
27 #endif
28
29 #ifndef NO_CONFIG_H /* for some tests */
30 #include "config.h"
31 #endif
32
33 #ifndef __cplusplus
34 #define class #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
35 #define private #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
36 #define public #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
37 #define protected #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
38 #define template #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
39 #define this #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
40 #define new #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
41 #define delete #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
42 #define friend #error DONT_USE_CPLUSPLUS_RESERVED_NAMES
43 #endif
44
45 #include "local.h"
46
47 #ifdef AIX
48 #define DEFAULT_PRINTING PRINT_AIX
49 #define PRINTCAP_NAME "/etc/qconfig"
50 #endif
51
52 #ifdef HPUX
53 #define DEFAULT_PRINTING PRINT_HPUX
54 #endif
55
56 #ifdef QNX
57 #define DEFAULT_PRINTING PRINT_QNX
58 #endif
59
60 #ifdef SUNOS4
61 /* on SUNOS4 termios.h conflicts with sys/ioctl.h */
62 #undef HAVE_TERMIOS_H
63 #endif
64
65 #if (__GNUC__ >= 3 ) && (__GNUC_MINOR__ >= 1 )
66 /** Use gcc attribute to check printf fns.  a1 is the 1-based index of
67  * the parameter containing the format, and a2 the index of the first
68  * argument. Note that some gcc 2.x versions don't handle this
69  * properly **/
70 #define PRINTF_ATTRIBUTE(a1, a2) __attribute__ ((format (__printf__, a1, a2)))
71 #else
72 #define PRINTF_ATTRIBUTE(a1, a2)
73 #endif
74
75 #if defined(__GNUC__) && !defined(__cplusplus)
76 /** gcc attribute used on function parameters so that it does not emit
77  * warnings about them being unused. **/
78 #  define UNUSED(param) param __attribute__ ((unused))
79 #else
80 #  define UNUSED(param) param
81 /** Feel free to add definitions for other compilers here. */
82 #endif
83
84 #ifdef RELIANTUNIX
85 /*
86  * <unistd.h> has to be included before any other to get
87  * large file support on Reliant UNIX. Yes, it's broken :-).
88  */
89 #ifdef HAVE_UNISTD_H
90 #include <unistd.h>
91 #endif
92 #endif /* RELIANTUNIX */
93
94 #include <sys/types.h>
95
96 #ifdef TIME_WITH_SYS_TIME
97 #include <sys/time.h>
98 #include <time.h>
99 #else
100 #ifdef HAVE_SYS_TIME_H
101 #include <sys/time.h>
102 #else
103 #include <time.h>
104 #endif
105 #endif
106
107 #ifdef HAVE_SYS_RESOURCE_H
108 #include <sys/resource.h>
109 #endif
110
111 #ifdef HAVE_UNISTD_H
112 #include <unistd.h>
113 #endif
114
115 #include <stdio.h>
116 #include <stddef.h>
117
118 #ifdef HAVE_SYS_PARAM_H
119 #include <sys/param.h>
120 #endif
121
122 #ifdef HAVE_STDLIB_H
123 #include <stdlib.h>
124 #endif
125
126 #ifdef HAVE_SYS_SOCKET_H
127 #include <sys/socket.h>
128 #endif
129
130 #ifdef HAVE_UNIXSOCKET
131 #include <sys/un.h>
132 #endif
133
134 #ifdef HAVE_SYS_SYSCALL_H
135 #include <sys/syscall.h>
136 #elif HAVE_SYSCALL_H
137 #include <syscall.h>
138 #endif
139
140 #ifdef HAVE_STRING_H
141 #include <string.h>
142 #endif
143
144 #ifdef HAVE_STRINGS_H
145 #include <strings.h>
146 #endif
147
148 #ifdef HAVE_MEMORY_H
149 #include <memory.h>
150 #endif
151
152 #ifdef HAVE_MALLOC_H
153 #include <malloc.h>
154 #endif
155
156 #ifdef HAVE_FCNTL_H
157 #include <fcntl.h>
158 #else
159 #ifdef HAVE_SYS_FCNTL_H
160 #include <sys/fcntl.h>
161 #endif
162 #endif
163
164 #include <sys/stat.h>
165
166 #ifdef HAVE_LIMITS_H
167 #include <limits.h>
168 #endif
169
170 #ifdef HAVE_SYS_IOCTL_H
171 #include <sys/ioctl.h>
172 #endif
173
174 #ifdef HAVE_SYS_FILIO_H
175 #include <sys/filio.h>
176 #endif
177
178 #include <signal.h>
179
180 #ifdef HAVE_SYS_WAIT_H
181 #include <sys/wait.h>
182 #endif
183 #ifdef HAVE_CTYPE_H
184 #include <ctype.h>
185 #endif
186 #ifdef HAVE_GRP_H
187 #include <grp.h>
188 #endif
189 #ifdef HAVE_SYS_PRIV_H
190 #include <sys/priv.h>
191 #endif
192 #ifdef HAVE_SYS_ID_H
193 #include <sys/id.h>
194 #endif
195
196 #include <errno.h>
197
198 #ifdef HAVE_UTIME_H
199 #include <utime.h>
200 #endif
201
202 #ifdef HAVE_SYS_SELECT_H
203 #include <sys/select.h>
204 #endif
205
206 #ifdef HAVE_SYS_MODE_H
207 /* apparently AIX needs this for S_ISLNK */
208 #ifndef S_ISLNK
209 #include <sys/mode.h>
210 #endif
211 #endif
212
213 #ifdef HAVE_GLOB_H
214 #include <glob.h>
215 #endif
216
217 #include <pwd.h>
218
219 #ifdef HAVE_STDARG_H
220 #include <stdarg.h>
221 #else
222 #include <varargs.h>
223 #endif
224
225 #include <netinet/in.h>
226 #include <arpa/inet.h>
227 #include <netdb.h>
228
229 #ifdef HAVE_SYSLOG_H
230 #include <syslog.h>
231 #else
232 #ifdef HAVE_SYS_SYSLOG_H
233 #include <sys/syslog.h>
234 #endif
235 #endif
236
237 #include <sys/file.h>
238
239 #ifdef HAVE_NETINET_TCP_H
240 #include <netinet/tcp.h>
241 #endif
242
243 /*
244  * The next three defines are needed to access the IPTOS_* options
245  * on some systems.
246  */
247
248 #ifdef HAVE_NETINET_IN_SYSTM_H
249 #include <netinet/in_systm.h>
250 #endif
251
252 #ifdef HAVE_NETINET_IN_IP_H
253 #include <netinet/in_ip.h>
254 #endif
255
256 #ifdef HAVE_NETINET_IP_H
257 #include <netinet/ip.h>
258 #endif
259
260 #if defined(HAVE_TERMIOS_H)
261 /* POSIX terminal handling. */
262 #include <termios.h>
263 #elif defined(HAVE_TERMIO_H)
264 /* Older SYSV terminal handling - don't use if we can avoid it. */
265 #include <termio.h>
266 #elif defined(HAVE_SYS_TERMIO_H)
267 /* Older SYSV terminal handling - don't use if we can avoid it. */
268 #include <sys/termio.h>
269 #endif
270
271 #if HAVE_DIRENT_H
272 # include <dirent.h>
273 # define NAMLEN(dirent) strlen((dirent)->d_name)
274 #else
275 # define dirent direct
276 # define NAMLEN(dirent) (dirent)->d_namlen
277 # if HAVE_SYS_NDIR_H
278 #  include <sys/ndir.h>
279 # endif
280 # if HAVE_SYS_DIR_H
281 #  include <sys/dir.h>
282 # endif
283 # if HAVE_NDIR_H
284 #  include <ndir.h>
285 # endif
286 #endif
287
288 #ifdef HAVE_SYS_MMAN_H
289 #include <sys/mman.h>
290 #endif
291
292 #ifdef HAVE_NET_IF_H
293 #include <net/if.h>
294 #endif
295
296
297 #ifdef HAVE_SYS_MOUNT_H
298 #include <sys/mount.h>
299 #endif
300
301 #ifdef HAVE_SYS_VFS_H
302 #include <sys/vfs.h>
303 #endif
304
305 #ifdef HAVE_SYS_ACL_H
306 #include <sys/acl.h>
307 #endif
308
309 #ifdef HAVE_SYS_FS_S5PARAM_H 
310 #include <sys/fs/s5param.h>
311 #endif
312
313 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
314 #include <sys/filsys.h> 
315 #endif
316
317 #ifdef HAVE_SYS_STATFS_H
318 # include <sys/statfs.h>
319 #endif
320
321 #ifdef HAVE_DUSTAT_H              
322 #include <sys/dustat.h>
323 #endif
324
325 #ifdef HAVE_SYS_STATVFS_H          
326 #include <sys/statvfs.h>
327 #endif
328
329 #ifdef HAVE_SHADOW_H
330 /*
331  * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
332  * was included above.  However <rpc/rpc.h> includes <sys/xti.h> which defines
333  * them again without checking if they already exsist.  This generates
334  * two "Redefinition of macro" warnings for every single .c file that is
335  * compiled.
336  */
337 #if defined(HPUX) && defined(TCP_NODELAY)
338 #undef TCP_NODELAY
339 #endif
340 #if defined(HPUX) && defined(TCP_MAXSEG)
341 #undef TCP_MAXSEG
342 #endif
343 #include <shadow.h>
344 #endif
345
346 #ifdef HAVE_GETPWANAM
347 #include <sys/label.h>
348 #include <sys/audit.h>
349 #include <pwdadj.h>
350 #endif
351
352 #ifdef HAVE_SYS_SECURITY_H
353 #include <sys/security.h>
354 #include <prot.h>
355 #define PASSWORD_LENGTH 16
356 #endif  /* HAVE_SYS_SECURITY_H */
357
358 #ifdef HAVE_STROPTS_H
359 #include <stropts.h>
360 #endif
361
362 #ifdef HAVE_POLL_H
363 #include <poll.h>
364 #endif
365
366 #if defined(HAVE_RPC_RPC_H)
367 /*
368  * Check for AUTH_ERROR define conflict with rpc/rpc.h in prot.h.
369  */
370 #if defined(HAVE_SYS_SECURITY_H) && defined(HAVE_RPC_AUTH_ERROR_CONFLICT)
371 #undef AUTH_ERROR
372 #endif
373 /*
374  * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
375  * was included above.  However <rpc/rpc.h> includes <sys/xti.h> which defines
376  * them again without checking if they already exsist.  This generates
377  * two "Redefinition of macro" warnings for every single .c file that is
378  * compiled.
379  */
380 #if defined(HPUX) && defined(TCP_NODELAY)
381 #undef TCP_NODELAY
382 #endif
383 #if defined(HPUX) && defined(TCP_MAXSEG)
384 #undef TCP_MAXSEG
385 #endif
386 #include <rpc/rpc.h>
387 #endif
388
389 #if defined(HAVE_YP_GET_DEFAULT_DOMAIN) && defined(HAVE_SETNETGRENT) && defined(HAVE_ENDNETGRENT) && defined(HAVE_GETNETGRENT)
390 #define HAVE_NETGROUP 1
391 #endif
392
393 #if defined (HAVE_NETGROUP)
394 #if defined(HAVE_RPCSVC_YP_PROT_H)
395 /*
396  * HP-UX 11.X has TCP_NODELAY and TCP_MAXSEG defined in <netinet/tcp.h> which
397  * was included above.  However <rpc/rpc.h> includes <sys/xti.h> which defines
398  * them again without checking if they already exsist.  This generates
399  * two "Redefinition of macro" warnings for every single .c file that is
400  * compiled.
401  */
402 #if defined(HPUX) && defined(TCP_NODELAY)
403 #undef TCP_NODELAY
404 #endif
405 #if defined(HPUX) && defined(TCP_MAXSEG)
406 #undef TCP_MAXSEG
407 #endif
408 #include <rpcsvc/yp_prot.h>
409 #endif
410 #if defined(HAVE_RPCSVC_YPCLNT_H)
411 #include <rpcsvc/ypclnt.h>
412 #endif
413 #endif /* HAVE_NETGROUP */
414
415 #if defined(HAVE_SYS_IPC_H)
416 #include <sys/ipc.h>
417 #endif /* HAVE_SYS_IPC_H */
418
419 #if defined(HAVE_SYS_SHM_H)
420 #include <sys/shm.h>
421 #endif /* HAVE_SYS_SHM_H */
422
423 #ifdef HAVE_NATIVE_ICONV
424 #ifdef HAVE_ICONV
425 #include <iconv.h>
426 #endif
427 #ifdef HAVE_GICONV
428 #include <giconv.h>
429 #endif
430 #ifdef HAVE_BICONV
431 #include <biconv.h>
432 #endif
433 #endif
434
435 #if HAVE_KRB5_H
436 #include <krb5.h>
437 #else
438 #undef HAVE_KRB5
439 #endif
440
441 #if HAVE_LBER_H
442 #include <lber.h>
443 #ifndef LBER_USE_DER
444 #define LBER_USE_DER 0x01
445 #endif
446 #endif
447
448 #if HAVE_LDAP_H
449 #include <ldap.h>
450 #ifndef LDAP_CONST
451 #define LDAP_CONST const
452 #endif
453 #ifndef LDAP_OPT_SUCCESS
454 #define LDAP_OPT_SUCCESS 0
455 #endif
456 /* Solaris 8 and maybe other LDAP implementations spell this "..._INPROGRESS": */
457 #if defined(LDAP_SASL_BIND_INPROGRESS) && !defined(LDAP_SASL_BIND_IN_PROGRESS)
458 #define LDAP_SASL_BIND_IN_PROGRESS LDAP_SASL_BIND_INPROGRESS
459 #endif
460 /* Solaris 8 defines SSL_LDAP_PORT, not LDAPS_PORT and it only does so if
461    LDAP_SSL is defined - but SSL is not working. We just want the
462    port number! Let's just define LDAPS_PORT correct. */
463 #if !defined(LDAPS_PORT)
464 #define LDAPS_PORT 636
465 #endif
466 #else
467 #undef HAVE_LDAP
468 #endif
469
470 #if HAVE_GSSAPI_H
471 #include <gssapi.h>
472 #elif HAVE_GSSAPI_GSSAPI_H
473 #include <gssapi/gssapi.h>
474 #elif HAVE_GSSAPI_GSSAPI_GENERIC_H
475 #include <gssapi/gssapi_generic.h>
476 #endif
477
478 #if HAVE_COM_ERR_H
479 #include <com_err.h>
480 #endif
481
482 #if HAVE_SYS_ATTRIBUTES_H
483 #include <sys/attributes.h>
484 #endif
485
486 /* mutually exclusive (SuSE 8.2) */
487 #if HAVE_ATTR_XATTR_H
488 #include <attr/xattr.h>
489 #elif HAVE_SYS_XATTR_H
490 #include <sys/xattr.h>
491 #endif
492
493 #ifdef HAVE_SYS_EA_H
494 #include <sys/ea.h>
495 #endif
496
497 #ifdef HAVE_SYS_EXTATTR_H
498 #include <sys/extattr.h>
499 #endif
500
501 #ifdef HAVE_SYS_UIO_H
502 #include <sys/uio.h>
503 #endif
504
505 #if HAVE_LOCALE_H
506 #include <locale.h>
507 #endif
508
509 #if HAVE_LANGINFO_H
510 #include <langinfo.h>
511 #endif
512
513 #if defined(HAVE_AIO_H) && defined(WITH_AIO)
514 #include <aio.h>
515 #endif
516
517 /* skip valgrind headers on 64bit AMD boxes */
518 #ifndef HAVE_64BIT_LINUX
519 /* Special macros that are no-ops except when run under Valgrind on
520  * x86.  They've moved a little bit from valgrind 1.0.4 to 1.9.4 */
521 #if HAVE_VALGRIND_MEMCHECK_H
522         /* memcheck.h includes valgrind.h */
523 #include <valgrind/memcheck.h>
524 #elif HAVE_VALGRIND_H
525 #include <valgrind.h>
526 #endif
527 #endif
528
529 /* If we have --enable-developer and the valgrind header is present,
530  * then we're OK to use it.  Set a macro so this logic can be done only
531  * once. */
532 #if defined(DEVELOPER) && !defined(HAVE_64BIT_LINUX)
533 #if (HAVE_VALGRIND_H || HAVE_VALGRIND_VALGRIND_H)
534 #define VALGRIND
535 #endif
536 #endif
537
538
539 /* we support ADS if we want it and have krb5 and ldap libs */
540 #if defined(WITH_ADS) && defined(HAVE_KRB5) && defined(HAVE_LDAP)
541 #define HAVE_ADS
542 #endif
543
544 /*
545  * Define VOLATILE if needed.
546  */
547
548 #if defined(HAVE_VOLATILE)
549 #define VOLATILE volatile
550 #else
551 #define VOLATILE
552 #endif
553
554 /*
555  * Define additional missing types
556  */
557 #if defined(HAVE_SIG_ATOMIC_T_TYPE) && defined(AIX)
558 typedef sig_atomic_t SIG_ATOMIC_T;
559 #elif defined(HAVE_SIG_ATOMIC_T_TYPE) && !defined(AIX)
560 typedef sig_atomic_t VOLATILE SIG_ATOMIC_T;
561 #else
562 typedef int VOLATILE SIG_ATOMIC_T;
563 #endif
564
565 #ifndef HAVE_SOCKLEN_T_TYPE
566 #define HAVE_SOCKLEN_T_TYPE
567 typedef int socklen_t;
568 #endif
569
570
571 #ifndef uchar
572 #define uchar unsigned char
573 #endif
574
575 #ifdef HAVE_UNSIGNED_CHAR
576 #define schar signed char
577 #else
578 #define schar char
579 #endif
580
581 /*
582    Samba needs type definitions for int16, int32, uint16 and uint32.
583
584    Normally these are signed and unsigned 16 and 32 bit integers, but
585    they actually only need to be at least 16 and 32 bits
586    respectively. Thus if your word size is 8 bytes just defining them
587    as signed and unsigned int will work.
588 */
589
590 #ifndef uint8
591 #define uint8 unsigned char
592 #endif
593
594 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
595 #if (SIZEOF_SHORT == 4)
596 #define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
597 #else /* SIZEOF_SHORT != 4 */
598 #define int16 short
599 #endif /* SIZEOF_SHORT != 4 */
600 #endif
601
602 /*
603  * Note we duplicate the size tests in the unsigned 
604  * case as int16 may be a typedef from rpc/rpc.h
605  */
606
607 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
608 #if (SIZEOF_SHORT == 4)
609 #define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
610 #else /* SIZEOF_SHORT != 4 */
611 #define uint16 unsigned short
612 #endif /* SIZEOF_SHORT != 4 */
613 #endif
614
615 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
616 #if (SIZEOF_INT == 4)
617 #define int32 int
618 #elif (SIZEOF_LONG == 4)
619 #define int32 long
620 #elif (SIZEOF_SHORT == 4)
621 #define int32 short
622 #else
623 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
624 #define int32 int
625 #endif
626 #endif
627
628 /*
629  * Note we duplicate the size tests in the unsigned 
630  * case as int32 may be a typedef from rpc/rpc.h
631  */
632
633 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
634 #if (SIZEOF_INT == 4)
635 #define uint32 unsigned int
636 #elif (SIZEOF_LONG == 4)
637 #define uint32 unsigned long
638 #elif (SIZEOF_SHORT == 4)
639 #define uint32 unsigned short
640 #else
641 /* uggh - no 32 bit type?? probably a CRAY. just hope this works ... */
642 #define uint32 unsigned
643 #endif
644 #endif
645
646 /*
647  * check for 8 byte long long
648  */
649
650 #if !defined(uint64)
651 #if (SIZEOF_LONG == 8)
652 #define uint64 unsigned long
653 #elif (SIZEOF_LONG_LONG == 8)
654 #define uint64 unsigned long long
655 #endif  /* don't lie.  If we don't have it, then don't use it */
656 #endif
657
658
659 /*
660  * Types for devices, inodes and offsets.
661  */
662
663 #ifndef SMB_DEV_T
664 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)
665 #    define SMB_DEV_T dev64_t
666 #  else
667 #    define SMB_DEV_T dev_t
668 #  endif
669 #endif
670
671 #ifndef LARGE_SMB_DEV_T
672 #  if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)) || (defined(SIZEOF_DEV_T) && (SIZEOF_DEV_T == 8))
673 #    define LARGE_SMB_DEV_T 1
674 #  endif
675 #endif
676
677 #ifdef LARGE_SMB_DEV_T
678 #define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
679 #define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(((SMB_BIG_UINT)(IVAL((p),(ofs))))| (((SMB_BIG_UINT)(IVAL((p),(ofs)+4))) << 32)))
680 #else 
681 #define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),v),SIVAL((p),(ofs)+4,0))
682 #define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(IVAL((p),(ofs))))
683 #endif
684
685 /*
686  * Setup the correctly sized inode type.
687  */
688
689 #ifndef SMB_INO_T
690 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)
691 #    define SMB_INO_T ino64_t
692 #  else
693 #    define SMB_INO_T ino_t
694 #  endif
695 #endif
696
697 #ifndef LARGE_SMB_INO_T
698 #  if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_INO64_T)) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
699 #    define LARGE_SMB_INO_T 1
700 #  endif
701 #endif
702
703 #ifdef LARGE_SMB_INO_T
704 #define SINO_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
705 #define INO_T_VAL(p, ofs) ((SMB_INO_T)(((SMB_BIG_UINT)(IVAL(p,ofs)))| (((SMB_BIG_UINT)(IVAL(p,(ofs)+4))) << 32)))
706 #else 
707 #define SINO_T_VAL(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
708 #define INO_T_VAL(p, ofs) ((SMB_INO_T)(IVAL((p),(ofs))))
709 #endif
710
711 #ifndef SMB_OFF_T
712 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)
713 #    define SMB_OFF_T off64_t
714 #  else
715 #    define SMB_OFF_T off_t
716 #  endif
717 #endif
718
719 #if defined(HAVE_LONGLONG)
720 #define SMB_BIG_UINT unsigned long long
721 #define SMB_BIG_INT long long
722 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
723 #else
724 #define SMB_BIG_UINT unsigned long
725 #define SMB_BIG_INT long
726 #define SBIG_UINT(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
727 #endif
728
729 #define SMB_BIG_UINT_BITS (sizeof(SMB_BIG_UINT)*8)
730
731 /* this should really be a 64 bit type if possible */
732 #define br_off SMB_BIG_UINT
733
734 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
735
736 /*
737  * Set the define that tells us if we can do 64 bit
738  * NT SMB calls.
739  */
740
741 #ifndef LARGE_SMB_OFF_T
742 #  if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T)) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
743 #    define LARGE_SMB_OFF_T 1
744 #  endif
745 #endif
746
747 #ifdef LARGE_SMB_OFF_T
748 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
749 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,(v)&0xFFFFFFFF), SIVAL(p,ofs,(v)>>32))
750 #define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF) )))
751 #define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF)) | \
752                 (( ((SMB_BIG_UINT)(IVAL((buf),(off+4)))) & ((SMB_BIG_UINT)0xFFFFFFFF) ) << 32 ) )
753 #else 
754 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
755 #define SOFF_T_R(p, ofs, v) (SIVAL(p,(ofs)+4,v),SIVAL(p,ofs,0))
756 #define IVAL_TO_SMB_OFF_T(buf,off) ((SMB_OFF_T)(( ((uint32)(IVAL((buf),(off)))) & 0xFFFFFFFF )))
757 #define IVAL2_TO_SMB_BIG_UINT(buf,off) ( (((SMB_BIG_UINT)(IVAL((buf),(off)))) & ((SMB_BIG_UINT)0xFFFFFFFF)) | \
758                                 (( ((SMB_BIG_UINT)(IVAL((buf),(off+4)))) & ((SMB_BIG_UINT)0xFFFFFFFF) ) << 32 ) )
759 #endif
760
761 /*
762  * Type for stat structure.
763  */
764
765 #ifndef SMB_STRUCT_STAT
766 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STAT64) && defined(HAVE_OFF64_T)
767 #    define SMB_STRUCT_STAT struct stat64
768 #  else
769 #    define SMB_STRUCT_STAT struct stat
770 #  endif
771 #endif
772
773 /*
774  * Type for dirent structure.
775  */
776
777 #ifndef SMB_STRUCT_DIRENT
778 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIRENT64)
779 #    define SMB_STRUCT_DIRENT struct dirent64
780 #  else
781 #    define SMB_STRUCT_DIRENT struct dirent
782 #  endif
783 #endif
784
785 /*
786  * Type for DIR structure.
787  */
788
789 #ifndef SMB_STRUCT_DIR
790 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_DIR64)
791 #    define SMB_STRUCT_DIR DIR64
792 #  else
793 #    define SMB_STRUCT_DIR DIR
794 #  endif
795 #endif
796
797 /*
798  * Defines for 64 bit fcntl locks.
799  */
800
801 #ifndef SMB_STRUCT_FLOCK
802 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
803 #    define SMB_STRUCT_FLOCK struct flock64
804 #  else
805 #    define SMB_STRUCT_FLOCK struct flock
806 #  endif
807 #endif
808
809 #ifndef SMB_F_SETLKW
810 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
811 #    define SMB_F_SETLKW F_SETLKW64
812 #  else
813 #    define SMB_F_SETLKW F_SETLKW
814 #  endif
815 #endif
816
817 #ifndef SMB_F_SETLK
818 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
819 #    define SMB_F_SETLK F_SETLK64
820 #  else
821 #    define SMB_F_SETLK F_SETLK
822 #  endif
823 #endif
824
825 #ifndef SMB_F_GETLK
826 #  if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
827 #    define SMB_F_GETLK F_GETLK64
828 #  else
829 #    define SMB_F_GETLK F_GETLK
830 #  endif
831 #endif
832
833 /*
834  * Type for aiocb structure.
835  */
836
837 #ifndef SMB_STRUCT_AIOCB
838 #  if defined(WITH_AIO)
839 #    if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64)
840 #      define SMB_STRUCT_AIOCB struct aiocb64
841 #    else
842 #      define SMB_STRUCT_AIOCB struct aiocb
843 #    endif
844 #  else
845 #    define SMB_STRUCT_AIOCB int /* AIO not being used but we still need the define.... */
846 #  endif
847 #endif
848
849 #ifndef HAVE_STRUCT_TIMESPEC
850 struct timespec {
851         time_t tv_sec;            /* Seconds.  */
852         long tv_nsec;           /* Nanoseconds.  */
853 };
854 #endif
855
856 #ifndef MIN
857 #define MIN(a,b) ((a)<(b)?(a):(b))
858 #endif
859
860 #ifndef MAX
861 #define MAX(a,b) ((a)>(b)?(a):(b))
862 #endif
863
864 #ifndef HAVE_STRERROR
865 extern char *sys_errlist[];
866 #define strerror(i) sys_errlist[i]
867 #endif
868
869 #ifndef HAVE_ERRNO_DECL
870 extern int errno;
871 #endif
872
873 #ifdef HAVE_BROKEN_GETGROUPS
874 #define GID_T int
875 #else
876 #define GID_T gid_t
877 #endif
878
879 #ifndef NGROUPS_MAX
880 #define NGROUPS_MAX 32 /* Guess... */
881 #endif
882
883 #ifdef SOCKET_WRAPPER
884 #define SOCKET_WRAPPER_REPLACE
885 #include "include/socket_wrapper.h"
886 #endif
887
888 /* Our own pstrings and fstrings */
889 #include "pstring.h"
890
891 /* Lists, trees, caching, database... */
892 #include "xfile.h"
893 #include "intl.h"
894 #include "dlinklist.h"
895 #include "tdb/tdb.h"
896 #include "tdb/spinlock.h"
897 #include "tdb/tdbutil.h"
898
899 #include "talloc.h"
900 /* And a little extension. Abort on type mismatch */
901 #define talloc_get_type_abort(ptr, type) \
902         (type *)talloc_check_name_abort(ptr, #type)
903
904 #include "nt_status.h"
905 #include "ads.h"
906 #include "interfaces.h"
907 #include "trans2.h"
908 #include "nterr.h"
909 #include "ntioctl.h"
910 #include "messages.h"
911 #include "charset.h"
912 #include "dynconfig.h"
913
914 #include "util_getent.h"
915
916 #include "debugparse.h"
917
918 #include "version.h"
919
920 #include "privileges.h"
921
922 #include "smb.h"
923
924 #include "nameserv.h"
925
926 #include "secrets.h"
927
928 #include "byteorder.h"
929
930 #include "privileges.h"
931
932 #include "rpc_misc.h"
933
934 #include "rpc_dce.h"
935
936 #include "mapping.h"
937
938 #include "passdb.h"
939
940 #include "rpc_secdes.h"
941
942 #include "authdata.h"
943
944 #include "msdfs.h"
945
946 #include "rap.h"
947
948 #include "md5.h"
949 #include "hmacmd5.h"
950
951 #include "ntlmssp.h"
952
953 #include "auth.h"
954
955 #include "ntdomain.h"
956
957 #include "rpc_svcctl.h"
958 #include "rpc_ntsvcs.h"
959 #include "rpc_lsa.h"
960 #include "rpc_netlogon.h"
961 #include "reg_objects.h"
962 #include "rpc_reg.h"
963 #include "rpc_samr.h"
964 #include "rpc_srvsvc.h"
965 #include "rpc_wkssvc.h"
966 #include "rpc_spoolss.h"
967 #include "rpc_eventlog.h"
968 #include "rpc_dfs.h"
969 #include "rpc_ds.h"
970 #include "rpc_echo.h"
971 #include "rpc_shutdown.h"
972 #include "rpc_perfcount.h"
973 #include "rpc_perfcount_defs.h"
974
975 #include "nt_printing.h"
976
977 #include "idmap.h"
978
979 #include "client.h"
980
981 #ifdef WITH_SMBWRAPPER
982 #include "smbw.h"
983 #endif
984
985 #include "session.h"
986
987 #include "asn_1.h"
988
989 #include "popt.h"
990
991 #include "mangle.h"
992
993 #include "module.h"
994
995 #include "nsswitch/winbind_client.h"
996
997 #include "spnego.h"
998
999 #include "rpc_client.h"
1000
1001 #include "event.h"
1002
1003 /*
1004  * Type for wide character dirent structure.
1005  * Only d_name is defined by POSIX.
1006  */
1007
1008 typedef struct smb_wdirent {
1009         wpstring        d_name;
1010 } SMB_STRUCT_WDIRENT;
1011
1012 /*
1013  * Type for wide character passwd structure.
1014  */
1015
1016 typedef struct smb_wpasswd {
1017         wfstring       pw_name;
1018         char           *pw_passwd;
1019         uid_t          pw_uid;
1020         gid_t          pw_gid;
1021         wpstring       pw_gecos;
1022         wpstring       pw_dir;
1023         wpstring       pw_shell;
1024 } SMB_STRUCT_WPASSWD;
1025
1026 /* used in net.c */
1027 struct functable {
1028         const char *funcname;
1029         int (*fn)(int argc, const char **argv);
1030 };
1031
1032 struct functable2 {
1033         const char *funcname;
1034         int (*fn)(int argc, const char **argv);
1035         const char *helptext;
1036 };
1037
1038 /* Defines for wisXXX functions. */
1039 #define UNI_UPPER    0x1
1040 #define UNI_LOWER    0x2
1041 #define UNI_DIGIT    0x4
1042 #define UNI_XDIGIT   0x8
1043 #define UNI_SPACE    0x10
1044
1045 #include "nsswitch/winbind_nss.h"
1046
1047 /* forward declaration from printing.h to get around 
1048    header file dependencies */
1049
1050 struct printjob;
1051
1052 struct smb_ldap_privates;
1053
1054 /* forward declarations from smbldap.c */
1055
1056 #include "smbldap.h"
1057
1058 #include "smb_ldap.h"
1059
1060 /*
1061  * Reasons for cache flush.
1062  */
1063
1064 enum flush_reason_enum {
1065     SEEK_FLUSH,
1066     READ_FLUSH,
1067     WRITE_FLUSH,
1068     READRAW_FLUSH,
1069     OPLOCK_RELEASE_FLUSH,
1070     CLOSE_FLUSH,
1071     SYNC_FLUSH,
1072     SIZECHANGE_FLUSH,
1073     /* NUM_FLUSH_REASONS must remain the last value in the enumeration. */
1074     NUM_FLUSH_REASONS};
1075
1076 /***** automatically generated prototypes *****/
1077 #ifndef NO_PROTO_H
1078 #include "proto.h"
1079 #endif
1080
1081 /* We need this after proto.h to reference GetTimeOfDay(). */
1082 #include "smbprofile.h"
1083
1084 /* String routines */
1085
1086 #include "srvstr.h"
1087 #include "safe_string.h"
1088
1089 #ifdef __COMPAR_FN_T
1090 #define QSORT_CAST (__compar_fn_t)
1091 #endif
1092
1093 #ifndef QSORT_CAST
1094 #define QSORT_CAST (int (*)(const void *, const void *))
1095 #endif
1096
1097 #ifndef DEFAULT_PRINTING
1098 #ifdef HAVE_CUPS
1099 #define DEFAULT_PRINTING PRINT_CUPS
1100 #define PRINTCAP_NAME "cups"
1101 #elif defined(SYSV)
1102 #define DEFAULT_PRINTING PRINT_SYSV
1103 #define PRINTCAP_NAME "lpstat"
1104 #else
1105 #define DEFAULT_PRINTING PRINT_BSD
1106 #define PRINTCAP_NAME "/etc/printcap"
1107 #endif
1108 #endif
1109
1110 #ifndef PRINTCAP_NAME
1111 #define PRINTCAP_NAME "/etc/printcap"
1112 #endif
1113
1114 #ifndef SIGCLD
1115 #define SIGCLD SIGCHLD
1116 #endif
1117
1118 #ifndef SIGRTMIN
1119 #define SIGRTMIN 32
1120 #endif
1121
1122 #ifndef MAP_FILE
1123 #define MAP_FILE 0
1124 #endif
1125
1126 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
1127 #define OSF1_ENH_SEC 1
1128 #endif
1129
1130 #ifndef ALLOW_CHANGE_PASSWORD
1131 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
1132 #define ALLOW_CHANGE_PASSWORD 1
1133 #endif
1134 #endif
1135
1136 /* what is the longest significant password available on your system? 
1137  Knowing this speeds up password searches a lot */
1138 #ifndef PASSWORD_LENGTH
1139 #define PASSWORD_LENGTH 8
1140 #endif
1141
1142 #ifdef REPLACE_INET_NTOA
1143 #define inet_ntoa rep_inet_ntoa
1144 #endif
1145
1146 #ifndef HAVE_PIPE
1147 #define SYNC_DNS 1
1148 #endif
1149
1150 #ifndef SEEK_SET
1151 #define SEEK_SET 0
1152 #endif
1153
1154 #ifndef INADDR_LOOPBACK
1155 #define INADDR_LOOPBACK 0x7f000001
1156 #endif
1157
1158 #ifndef INADDR_NONE
1159 #define INADDR_NONE 0xffffffff
1160 #endif
1161
1162 #ifndef HAVE_CRYPT
1163 #define crypt ufc_crypt
1164 #endif
1165
1166 #ifndef O_ACCMODE
1167 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
1168 #endif
1169
1170 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
1171 #define ULTRIX_AUTH 1
1172 #endif
1173
1174 #ifndef HAVE_STRDUP
1175 char *strdup(const char *s);
1176 #endif
1177
1178 #ifndef HAVE_STRNDUP
1179 char *strndup(const char *s, size_t size);
1180 #endif
1181
1182 #ifndef HAVE_MEMMOVE
1183 void *memmove(void *dest,const void *src,int size);
1184 #endif
1185
1186 #ifndef HAVE_INITGROUPS
1187 int initgroups(char *name,gid_t id);
1188 #endif
1189
1190 #ifndef HAVE_RENAME
1191 int rename(const char *zfrom, const char *zto);
1192 #endif
1193
1194 #ifndef HAVE_MKTIME
1195 time_t mktime(struct tm *t);
1196 #endif
1197
1198 #ifndef HAVE_STRLCPY
1199 size_t strlcpy(char *d, const char *s, size_t bufsize);
1200 #endif
1201
1202 #ifndef HAVE_STRLCAT
1203 size_t strlcat(char *d, const char *s, size_t bufsize);
1204 #endif
1205
1206 #ifndef HAVE_FTRUNCATE
1207 int ftruncate(int f,long l);
1208 #endif
1209
1210 #ifndef HAVE_STRNDUP
1211 char *strndup(const char *s, size_t n);
1212 #endif
1213
1214 #ifndef HAVE_STRNLEN
1215 size_t strnlen(const char *s, size_t n);
1216 #endif
1217
1218 #ifndef HAVE_STRTOUL
1219 unsigned long strtoul(const char *nptr, char **endptr, int base);
1220 #endif
1221
1222 #ifndef HAVE_SETENV
1223 int setenv(const char *name, const char *value, int overwrite); 
1224 #endif
1225
1226 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
1227 /* stupid glibc */
1228 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1229 #endif
1230 #if (defined(USE_SETRESUID) && !defined(HAVE_SETRESGID_DECL))
1231 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
1232 #endif
1233 #ifndef HAVE_VASPRINTF_DECL
1234 int vasprintf(char **ptr, const char *format, va_list ap);
1235 #endif
1236
1237 #ifdef REPLACE_GETPASS
1238 #define getpass(prompt) getsmbpass((prompt))
1239 #endif
1240
1241 /*
1242  * Some older systems seem not to have MAXHOSTNAMELEN
1243  * defined.
1244  */
1245 #ifndef MAXHOSTNAMELEN
1246 #define MAXHOSTNAMELEN 254
1247 #endif
1248
1249 /* yuck, I'd like a better way of doing this */
1250 #define DIRP_SIZE (256 + 32)
1251
1252 /*
1253  * glibc on linux doesn't seem to have MSG_WAITALL
1254  * defined. I think the kernel has it though..
1255  */
1256
1257 #ifndef MSG_WAITALL
1258 #define MSG_WAITALL 0
1259 #endif
1260
1261 /* default socket options. Dave Miller thinks we should default to TCP_NODELAY
1262    given the socket IO pattern that Samba uses */
1263 #ifdef TCP_NODELAY
1264 #define DEFAULT_SOCKET_OPTIONS "TCP_NODELAY"
1265 #else
1266 #define DEFAULT_SOCKET_OPTIONS ""
1267 #endif
1268
1269 /* Load header file for dynamic linking stuff */
1270
1271 #ifdef HAVE_DLFCN_H
1272 #include <dlfcn.h>
1273 #endif
1274
1275 /* dmalloc -- free heap debugger (dmalloc.org).  This should be near
1276  * the *bottom* of include files so as not to conflict. */
1277 #ifdef ENABLE_DMALLOC
1278 #  include <dmalloc.h>
1279 #endif
1280
1281
1282 /* Some POSIX definitions for those without */
1283  
1284 #ifndef S_IFDIR
1285 #define S_IFDIR         0x4000
1286 #endif
1287 #ifndef S_ISDIR
1288 #define S_ISDIR(mode)   ((mode & 0xF000) == S_IFDIR)
1289 #endif
1290 #ifndef S_IRWXU
1291 #define S_IRWXU 00700           /* read, write, execute: owner */
1292 #endif
1293 #ifndef S_IRUSR
1294 #define S_IRUSR 00400           /* read permission: owner */
1295 #endif
1296 #ifndef S_IWUSR
1297 #define S_IWUSR 00200           /* write permission: owner */
1298 #endif
1299 #ifndef S_IXUSR
1300 #define S_IXUSR 00100           /* execute permission: owner */
1301 #endif
1302 #ifndef S_IRWXG
1303 #define S_IRWXG 00070           /* read, write, execute: group */
1304 #endif
1305 #ifndef S_IRGRP
1306 #define S_IRGRP 00040           /* read permission: group */
1307 #endif
1308 #ifndef S_IWGRP
1309 #define S_IWGRP 00020           /* write permission: group */
1310 #endif
1311 #ifndef S_IXGRP
1312 #define S_IXGRP 00010           /* execute permission: group */
1313 #endif
1314 #ifndef S_IRWXO
1315 #define S_IRWXO 00007           /* read, write, execute: other */
1316 #endif
1317 #ifndef S_IROTH
1318 #define S_IROTH 00004           /* read permission: other */
1319 #endif
1320 #ifndef S_IWOTH
1321 #define S_IWOTH 00002           /* write permission: other */
1322 #endif
1323 #ifndef S_IXOTH
1324 #define S_IXOTH 00001           /* execute permission: other */
1325 #endif
1326
1327 /* For sys_adminlog(). */
1328 #ifndef LOG_EMERG
1329 #define LOG_EMERG       0       /* system is unusable */
1330 #endif
1331
1332 #ifndef LOG_ALERT
1333 #define LOG_ALERT       1       /* action must be taken immediately */
1334 #endif
1335
1336 #ifndef LOG_CRIT
1337 #define LOG_CRIT        2       /* critical conditions */
1338 #endif
1339
1340 #ifndef LOG_ERR
1341 #define LOG_ERR         3       /* error conditions */
1342 #endif
1343
1344 #ifndef LOG_WARNING
1345 #define LOG_WARNING     4       /* warning conditions */
1346 #endif
1347
1348 #ifndef LOG_NOTICE
1349 #define LOG_NOTICE      5       /* normal but significant condition */
1350 #endif
1351
1352 #ifndef LOG_INFO
1353 #define LOG_INFO        6       /* informational */
1354 #endif
1355
1356 #ifndef LOG_DEBUG
1357 #define LOG_DEBUG       7       /* debug-level messages */
1358 #endif
1359
1360 #if HAVE_KERNEL_SHARE_MODES
1361 #ifndef LOCK_MAND 
1362 #define LOCK_MAND       32      /* This is a mandatory flock */
1363 #define LOCK_READ       64      /* ... Which allows concurrent read operations */
1364 #define LOCK_WRITE      128     /* ... Which allows concurrent write operations */
1365 #define LOCK_RW         192     /* ... Which allows concurrent read & write ops */
1366 #endif
1367 #endif
1368
1369 extern int DEBUGLEVEL;
1370
1371 #define MAX_SEC_CTX_DEPTH 8    /* Maximum number of security contexts */
1372
1373
1374 #ifdef GLIBC_HACK_FCNTL64
1375 /* this is a gross hack. 64 bit locking is completely screwed up on
1376    i386 Linux in glibc 2.1.95 (which ships with RedHat 7.0). This hack
1377    "fixes" the problem with the current 2.4.0test kernels 
1378 */
1379 #define fcntl fcntl64
1380 #undef F_SETLKW 
1381 #undef F_SETLK 
1382 #define F_SETLK 13
1383 #define F_SETLKW 14
1384 #endif
1385
1386
1387 /* Needed for sys_dlopen/sys_dlsym/sys_dlclose */
1388 #ifndef RTLD_GLOBAL
1389 #define RTLD_GLOBAL 0
1390 #endif
1391
1392 #ifndef RTLD_LAZY
1393 #define RTLD_LAZY 0
1394 #endif
1395
1396 #ifndef RTLD_NOW
1397 #define RTLD_NOW 0
1398 #endif
1399
1400 /* needed for some systems without iconv. Doesn't really matter
1401    what error code we use */
1402 #ifndef EILSEQ
1403 #define EILSEQ EIO
1404 #endif
1405
1406 /* add varargs prototypes with printf checking */
1407 /*PRINTFLIKE2 */
1408 int fdprintf(int , const char *, ...) PRINTF_ATTRIBUTE(2,3);
1409 /*PRINTFLIKE1 */
1410 int d_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
1411 /*PRINTFLIKE2 */
1412 int d_fprintf(FILE *f, const char *, ...) PRINTF_ATTRIBUTE(2,3);
1413 #ifndef HAVE_SNPRINTF_DECL
1414 /*PRINTFLIKE3 */
1415 int snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
1416 #endif
1417 #ifndef HAVE_ASPRINTF_DECL
1418 /*PRINTFLIKE2 */
1419 int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
1420 #endif
1421
1422 /* Fix prototype problem with non-C99 compliant snprintf implementations, esp
1423    HPUX 11.  Don't change the sense of this #if statement.  Read the comments
1424    in lib/snprint.c if you think you need to.  See also bugzilla bug 174. */
1425
1426 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
1427 #define snprintf smb_snprintf
1428 #define vsnprintf smb_vsnprintf
1429
1430 /* PRINTFLIKE3 */
1431 int smb_snprintf(char *str,size_t count,const char *fmt,...);
1432 int smb_vsnprintf (char *str, size_t count, const char *fmt, va_list args);
1433
1434 #endif
1435
1436 /* PRINTFLIKE2 */
1437 void sys_adminlog(int priority, const char *format_str, ...) PRINTF_ATTRIBUTE(2,3);
1438
1439 /* PRINTFLIKE2 */
1440 int pstr_sprintf(pstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1441 /* PRINTFLIKE2 */
1442 int fstr_sprintf(fstring s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
1443
1444 int d_vfprintf(FILE *f, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1445
1446 int smb_xvasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
1447
1448 /* we used to use these fns, but now we have good replacements
1449    for snprintf and vsnprintf */
1450 #define slprintf snprintf
1451 #define vslprintf vsnprintf
1452
1453 /* we need to use __va_copy() on some platforms */
1454 #ifdef HAVE_VA_COPY
1455 #define VA_COPY(dest, src) va_copy(dest, src)
1456 #else
1457 #ifdef HAVE___VA_COPY
1458 #define VA_COPY(dest, src) __va_copy(dest, src)
1459 #else
1460 #define VA_COPY(dest, src) (dest) = (src)
1461 #endif
1462 #endif
1463
1464 #ifndef HAVE_TIMEGM
1465 time_t timegm(struct tm *tm);
1466 #endif
1467
1468 /*
1469  * Veritas File System.  Often in addition to native.
1470  * Quotas different.
1471  */
1472 #if defined(HAVE_SYS_FS_VX_QUOTA_H)
1473 #define VXFS_QUOTA
1474 #endif
1475
1476 #if defined(HAVE_KRB5)
1477
1478 krb5_error_code smb_krb5_parse_name(krb5_context context,
1479                                 const char *name, /* in unix charset */
1480                                 krb5_principal *principal);
1481
1482 krb5_error_code smb_krb5_unparse_name(krb5_context context,
1483                                 krb5_const_principal principal,
1484                                 char **unix_name);
1485
1486 #ifndef HAVE_KRB5_SET_REAL_TIME
1487 krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds);
1488 #endif
1489
1490 #ifndef HAVE_KRB5_SET_DEFAULT_TGS_KTYPES
1491 krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc);
1492 #endif
1493
1494 #if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY)
1495 krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, krb5_auth_context auth_context, krb5_keyblock *keyblock);
1496 #endif
1497
1498 #ifndef HAVE_KRB5_FREE_UNPARSED_NAME
1499 void krb5_free_unparsed_name(krb5_context ctx, char *val);
1500 #endif
1501
1502 /* Samba wrapper function for krb5 functionality. */
1503 void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr);
1504 int create_kerberos_key_from_string(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
1505 int create_kerberos_key_from_string_direct(krb5_context context, krb5_principal host_princ, krb5_data *password, krb5_keyblock *key, krb5_enctype enctype);
1506 BOOL get_auth_data_from_tkt(TALLOC_CTX *mem_ctx, DATA_BLOB *auth_data, krb5_ticket *tkt);
1507 krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt);
1508 krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters);
1509 krb5_error_code get_kerberos_allowed_etypes(krb5_context context, krb5_enctype **enctypes);
1510 void free_kerberos_etypes(krb5_context context, krb5_enctype *enctypes);
1511 BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote);
1512 krb5_error_code smb_krb5_kt_free_entry(krb5_context context, krb5_keytab_entry *kt_entry);
1513 krb5_principal kerberos_fetch_salt_princ_for_host_princ(krb5_context context, krb5_principal host_princ, int enctype);
1514 void kerberos_set_creds_enctype(krb5_creds *pcreds, int enctype);
1515 BOOL kerberos_compatible_enctypes(krb5_context context, krb5_enctype enctype1, krb5_enctype enctype2);
1516 void kerberos_free_data_contents(krb5_context context, krb5_data *pdata);
1517 NTSTATUS decode_pac_data(TALLOC_CTX *mem_ctx,
1518                          DATA_BLOB *pac_data_blob,
1519                          krb5_context context, 
1520                          krb5_keyblock *service_keyblock,
1521                          krb5_const_principal client_principal,
1522                          time_t tgs_authtime,
1523                          PAC_DATA **pac_data);
1524 void smb_krb5_checksum_from_pac_sig(krb5_checksum *cksum, 
1525                                     PAC_SIGNATURE_DATA *sig);
1526 krb5_error_code smb_krb5_verify_checksum(krb5_context context,
1527                                          krb5_keyblock *keyblock,
1528                                          krb5_keyusage usage,
1529                                          krb5_checksum *cksum,
1530                                          uint8 *data,
1531                                          size_t length);
1532 time_t get_authtime_from_tkt(krb5_ticket *tkt);
1533 void smb_krb5_free_ap_req(krb5_context context, 
1534                           krb5_ap_req *ap_req);
1535 krb5_error_code smb_krb5_get_keyinfo_from_ap_req(krb5_context context, 
1536                                                  const krb5_data *inbuf, 
1537                                                  krb5_kvno *kvno, 
1538                                                  krb5_enctype *enctype);
1539 krb5_error_code krb5_rd_req_return_keyblock_from_keytab(krb5_context context,
1540                                                         krb5_auth_context *auth_context,
1541                                                         const krb5_data *inbuf,
1542                                                         krb5_const_principal server,
1543                                                         krb5_keytab keytab,
1544                                                         krb5_flags *ap_req_options,
1545                                                         krb5_ticket **ticket, 
1546                                                         krb5_keyblock **keyblock);
1547 krb5_error_code smb_krb5_parse_name_norealm(krb5_context context, 
1548                                             const char *name, 
1549                                             krb5_principal *principal);
1550 BOOL smb_krb5_principal_compare_any_realm(krb5_context context, 
1551                                           krb5_const_principal princ1, 
1552                                           krb5_const_principal princ2);
1553 int cli_krb5_get_ticket(const char *principal, time_t time_offset, 
1554                         DATA_BLOB *ticket, DATA_BLOB *session_key_krb5, uint32 extra_ap_opts, const char *ccname);
1555 PAC_LOGON_INFO *get_logon_info_from_pac(PAC_DATA *pac_data);
1556 krb5_error_code smb_krb5_renew_ticket(const char *ccache_string, const char *client_string, const char *service_string, time_t *new_start_time);
1557 krb5_error_code kpasswd_err_to_krb5_err(krb5_error_code res_code);
1558 krb5_error_code smb_krb5_gen_netbios_krb5_address(smb_krb5_addresses **kerb_addr);
1559 krb5_error_code smb_krb5_free_addresses(krb5_context context, smb_krb5_addresses *addr);
1560 NTSTATUS krb5_to_nt_status(krb5_error_code kerberos_error);
1561 krb5_error_code nt_status_to_krb5(NTSTATUS nt_status);
1562 #endif /* HAVE_KRB5 */
1563
1564
1565 #ifdef HAVE_LDAP
1566
1567 /* function declarations not included in proto.h */
1568 LDAP *ldap_open_with_timeout(const char *server, int port, unsigned int to);
1569
1570 #endif  /* HAVE_LDAP */
1571
1572
1573 /* TRUE and FALSE are part of the C99 standard and gcc, but
1574    unfortunately many vendor compilers don't support them.  Use True
1575    and False instead. */
1576
1577 #ifdef TRUE
1578 #undef TRUE
1579 #endif
1580 #define TRUE __ERROR__XX__DONT_USE_TRUE
1581
1582 #ifdef FALSE
1583 #undef FALSE
1584 #endif
1585 #define FALSE __ERROR__XX__DONT_USE_FALSE
1586
1587 /* If we have blacklisted mmap() try to avoid using it accidentally by
1588    undefining the HAVE_MMAP symbol. */
1589
1590 #ifdef MMAP_BLACKLIST
1591 #undef HAVE_MMAP
1592 #endif
1593
1594 #define CONST_DISCARD(type, ptr)      ((type) ((void *) (ptr)))
1595 #define CONST_ADD(type, ptr)          ((type) ((const void *) (ptr)))
1596
1597 #ifndef NORETURN_ATTRIBUTE
1598 #if (__GNUC__ >= 3)
1599 #define NORETURN_ATTRIBUTE __attribute__ ((noreturn))
1600 #else
1601 #define NORETURN_ATTRIBUTE
1602 #endif
1603 #endif
1604
1605 void smb_panic( const char *why ) NORETURN_ATTRIBUTE ;
1606 void dump_core(void) NORETURN_ATTRIBUTE ;
1607 void exit_server(const char *const reason) NORETURN_ATTRIBUTE ;
1608 void exit_server_cleanly(const char *const reason) NORETURN_ATTRIBUTE ;
1609 void exit_server_fault(void) NORETURN_ATTRIBUTE ;
1610
1611 #endif /* _INCLUDES_H */