82487c4e2245bcb70c3145a4e6db91f1ef243e31
[samba.git] / source / include / includes.h
1 #ifndef _INCLUDES_H
2 #define _INCLUDES_H
3 /* 
4    Unix SMB/Netbios implementation.
5    Version 1.9.
6    Machine customisation and include handling
7    Copyright (C) Andrew Tridgell 1994-1998
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 #ifndef NO_CONFIG_H /* for some tests */
25 #include "config.h"
26 #endif
27
28 #include "local.h"
29
30 #ifdef AIX
31 #define DEFAULT_PRINTING PRINT_AIX
32 #define PRINTCAP_NAME "/etc/qconfig"
33 #endif
34
35 #ifdef HPUX
36 #define DEFAULT_PRINTING PRINT_HPUX
37 #endif
38
39 #ifdef QNX
40 #define DEFAULT_PRINTING PRINT_QNX
41 #endif
42
43 #ifdef SUNOS4
44 /* on SUNOS4 termios.h conflicts with sys/ioctl.h */
45 #undef HAVE_TERMIOS_H
46 #endif
47
48
49 #if defined(HAVE_RPC_RPC_H)
50 #include <rpc/rpc.h>
51 #endif
52
53 #include <sys/types.h>
54
55 #ifdef TIME_WITH_SYS_TIME
56 #include <sys/time.h>
57 #include <time.h>
58 #else
59 #ifdef HAVE_SYS_TIME_H
60 #include <sys/time.h>
61 #else
62 #include <time.h>
63 #endif
64 #endif
65
66 #ifdef HAVE_SYS_RESOURCE_H
67 #include <sys/resource.h>
68 #endif
69
70 #ifdef HAVE_UNISTD_H
71 #include <unistd.h>
72 #endif
73
74 #include <stdio.h>
75 #include <stddef.h>
76
77 #ifdef HAVE_SYS_PARAM_H
78 #include <sys/param.h>
79 #endif
80
81 #ifdef HAVE_STDLIB_H
82 #include <stdlib.h>
83 #endif
84
85 #ifdef HAVE_SYS_SOCKET_H
86 #include <sys/socket.h>
87 #endif
88
89 #ifdef HAVE_SYS_SYSCALL_H
90 #include <sys/syscall.h>
91 #elif HAVE_SYSCALL_H
92 #include <syscall.h>
93 #endif
94
95 #ifdef HAVE_STRING_H
96 #include <string.h>
97 #endif
98
99 #ifdef HAVE_STRINGS_H
100 #include <strings.h>
101 #endif
102
103 #ifdef HAVE_MEMORY_H
104 #include <memory.h>
105 #endif
106
107 #ifdef MEM_MAN
108 #include "../mem_man/mem_man.h"
109 #else
110 #ifdef HAVE_MALLOC_H
111 #include <malloc.h>
112 #endif
113 #endif
114
115 #ifdef HAVE_FCNTL_H
116 #include <fcntl.h>
117 #else
118 #ifdef HAVE_SYS_FCNTL_H
119 #include <sys/fcntl.h>
120 #endif
121 #endif
122
123 #include <sys/stat.h>
124
125 #ifdef HAVE_LIMITS_H
126 #include <limits.h>
127 #endif
128
129 #ifdef HAVE_SYS_IOCTL_H
130 #include <sys/ioctl.h>
131 #endif
132
133 #ifdef HAVE_SYS_FILIO_H
134 #include <sys/filio.h>
135 #endif
136
137 #include <signal.h>
138
139 #ifdef HAVE_SYS_WAIT_H
140 #include <sys/wait.h>
141 #endif
142 #ifdef HAVE_CTYPE_H
143 #include <ctype.h>
144 #endif
145 #ifdef HAVE_GRP_H
146 #include <grp.h>
147 #endif
148 #ifdef HAVE_SYS_ID_H
149 #include <sys/id.h>
150 #endif
151
152 #include <errno.h>
153
154 #ifdef HAVE_UTIME_H
155 #include <utime.h>
156 #endif
157
158 #ifdef HAVE_SYS_SELECT_H
159 #include <sys/select.h>
160 #endif
161
162 #ifdef HAVE_SYS_MODE_H
163 /* apparently AIX needs this for S_ISLNK */
164 #ifndef S_ISLNK
165 #include <sys/mode.h>
166 #endif
167 #endif
168
169 #ifdef HAVE_GLOB_H
170 #include <glob.h>
171 #endif
172
173 #include <pwd.h>
174 #include <grp.h>
175
176 #ifdef HAVE_STDARG_H
177 #include <stdarg.h>
178 #else
179 #include <varargs.h>
180 #endif
181
182 #include <netinet/in.h>
183 #include <arpa/inet.h>
184 #include <netdb.h>
185 #include <syslog.h>
186 #include <sys/file.h>
187
188 #ifdef HAVE_NETINET_TCP_H
189 #include <netinet/tcp.h>
190 #endif
191
192 #ifdef HAVE_TERMIOS_H
193 #include <termios.h>
194 #endif
195
196 #if HAVE_DIRENT_H
197 # include <dirent.h>
198 # define NAMLEN(dirent) strlen((dirent)->d_name)
199 #else
200 # define dirent direct
201 # define NAMLEN(dirent) (dirent)->d_namlen
202 # if HAVE_SYS_NDIR_H
203 #  include <sys/ndir.h>
204 # endif
205 # if HAVE_SYS_DIR_H
206 #  include <sys/dir.h>
207 # endif
208 # if HAVE_NDIR_H
209 #  include <ndir.h>
210 # endif
211 #endif
212
213 #ifdef HAVE_SHARED_MMAP
214 #include <sys/mman.h>
215 #endif
216
217 #ifdef HAVE_SYSV_IPC
218 #include <sys/ipc.h>
219 #include <sys/shm.h>
220 #include <sys/sem.h>
221 #endif
222
223 #if 0
224 /*
225  *  I have removed this as it prevents compilation under SCO Server
226  *  3.2. If you need to add it back in then please add a comment as to
227  *  why it's needed and what OS it's needed for so we can work out how
228  *  to test for it properly (tridge) */
229 #ifdef HAVE_NET_ROUTE_H
230 #include <net/route.h>
231 #endif
232 #endif
233
234 #ifdef HAVE_NET_IF_H
235 #include <net/if.h>
236 #endif
237
238
239 #ifdef HAVE_SYS_MOUNT_H
240 #include <sys/mount.h>
241 #endif
242
243 #ifdef HAVE_SYS_VFS_H
244 #include <sys/vfs.h>
245 #endif
246
247 #ifdef HAVE_SYS_ACL_H
248 #include <sys/acl.h>
249 #endif
250
251 #ifdef HAVE_SYS_FS_S5PARAM_H 
252 #include <sys/fs/s5param.h>
253 #endif
254
255 #if defined (HAVE_SYS_FILSYS_H) && !defined (_CRAY)
256 #include <sys/filsys.h> 
257 #endif
258
259 #ifdef HAVE_SYS_STATFS_H
260 # include <sys/statfs.h>
261 #endif
262
263 #ifdef HAVE_DUSTAT_H              
264 #include <sys/dustat.h>
265 #endif
266
267 #ifdef HAVE_SYS_STATVFS_H          
268 #include <sys/statvfs.h>
269 #endif
270
271 #ifdef HAVE_SHADOW_H
272 #include <shadow.h>
273 #endif
274
275 #ifdef HAVE_GETPWANAM
276 #include <sys/label.h>
277 #include <sys/audit.h>
278 #include <pwdadj.h>
279 #endif
280
281 #ifdef HAVE_SYS_SECURITY_H
282 #include <sys/security.h>
283 #include <prot.h>
284 #define PASSWORD_LENGTH 16
285 #endif  /* HAVE_SYS_SECURITY_H */
286
287 #ifdef HAVE_COMPAT_H
288 #include <compat.h>
289 #endif
290
291 #ifdef HAVE_STROPTS_H
292 #include <stropts.h>
293 #endif
294
295 #ifdef HAVE_POLL_H
296 #include <poll.h>
297 #endif
298
299 #ifdef HAVE_SYS_CAPABILITY_H
300 #include <sys/capability.h>
301 #endif
302
303 #if defined(HAVE_RPC_RPC_H)
304 #include <rpc/rpc.h>
305 #endif
306
307 #if defined(HAVE_YP_GET_DEFAULT_DOMAIN) && defined(HAVE_SETNETGRENT) && defined(HAVE_ENDNETGRENT) && defined(HAVE_GETNETGRENT)
308 #define HAVE_NETGROUP 1
309 #endif
310
311 #if defined (HAVE_NETGROUP)
312 #if defined(HAVE_RPCSVC_YP_PROT_H)
313 #include <rpcsvc/yp_prot.h>
314 #endif
315 #if defined(HAVE_RPCSVC_YPCLNT_H)
316 #include <rpcsvc/ypclnt.h>
317 #endif
318 #endif /* HAVE_NETGROUP */
319
320 #ifndef uchar
321 #define uchar unsigned char
322 #endif
323
324 #ifdef HAVE_UNSIGNED_CHAR
325 #define schar signed char
326 #else
327 #define schar char
328 #endif
329
330 /*
331    Samba needs type definitions for int16, int32, uint16 and uint32.
332
333    Normally these are signed and unsigned 16 and 32 bit integers, but
334    they actually only need to be at least 16 and 32 bits
335    respectively. Thus if your word size is 8 bytes just defining them
336    as signed and unsigned int will work.
337 */
338
339 #ifndef uint8
340 #define uint8 unsigned char
341 #endif
342
343 #if !defined(int16) && !defined(HAVE_INT16_FROM_RPC_RPC_H)
344 #if (SIZEOF_SHORT == 4)
345 #define int16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
346 #else /* SIZEOF_SHORT != 4 */
347 #define int16 short
348 #endif /* SIZEOF_SHORT != 4 */
349 #endif
350
351 /*
352  * Note we duplicate the size tests in the unsigned 
353  * case as int16 may be a typedef from rpc/rpc.h
354  */
355
356 #if !defined(uint16) && !defined(HAVE_UINT16_FROM_RPC_RPC_H)
357 #if (SIZEOF_SHORT == 4)
358 #define uint16 __ERROR___CANNOT_DETERMINE_TYPE_FOR_INT16;
359 #else /* SIZEOF_SHORT != 4 */
360 #define uint16 unsigned short
361 #endif /* SIZEOF_SHORT != 4 */
362 #endif
363
364 #if !defined(int32) && !defined(HAVE_INT32_FROM_RPC_RPC_H)
365 #if (SIZEOF_INT == 4)
366 #define int32 int
367 #elif (SIZEOF_LONG == 4)
368 #define int32 long
369 #elif (SIZEOF_SHORT == 4)
370 #define int32 short
371 #endif
372 #endif
373
374 /*
375  * Note we duplicate the size tests in the unsigned 
376  * case as int32 may be a typedef from rpc/rpc.h
377  */
378
379 #if !defined(uint32) && !defined(HAVE_UINT32_FROM_RPC_RPC_H)
380 #if (SIZEOF_INT == 4)
381 #define uint32 unsigned int
382 #elif (SIZEOF_LONG == 4)
383 #define uint32 unsigned long
384 #elif (SIZEOF_SHORT == 4)
385 #define uint32 unsigned short
386 #endif
387 #endif
388
389 /*
390  * Types for devices, inodes and offsets.
391  */
392
393 #ifndef SMB_DEV_T
394 #define SMB_DEV_T dev_t
395 #endif
396
397 /*
398  * Setup the correctly sized inode type.
399  */
400
401 #ifndef SMB_INO_T
402 #  ifdef HAVE_INO64_T
403 #    define SMB_INO_T ino64_t
404 #  else
405 #    define SMB_INO_T ino_t
406 #  endif
407 #endif
408
409 #ifndef LARGE_SMB_INO_T
410 #  if defined(HAVE_INO64_T) || (defined(SIZEOF_INO_T) && (SIZEOF_INO_T == 8))
411 #    define LARGE_SMB_INO_T 1
412 #  endif
413 #endif
414
415 #ifdef LARGE_SMB_INO_T
416 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
417 #else 
418 #define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
419 #endif
420
421 #ifndef SMB_OFF_T
422 #  ifdef HAVE_OFF64_T
423 #    define SMB_OFF_T off64_t
424 #  else
425 #    define SMB_OFF_T off_t
426 #  endif
427 #endif
428
429 #define SMB_OFF_T_BITS (sizeof(SMB_OFF_T)*8)
430
431 /*
432  * Set the define that tells us if we can do 64 bit
433  * NT SMB calls.
434  */
435
436 #ifndef LARGE_SMB_OFF_T
437 #  if defined(HAVE_OFF64_T) || (defined(SIZEOF_OFF_T) && (SIZEOF_OFF_T == 8))
438 #    define LARGE_SMB_OFF_T 1
439 #  endif
440 #endif
441
442 #ifdef LARGE_SMB_OFF_T
443 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
444 #else 
445 #define SOFF_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
446 #endif
447
448 /*
449  * Type for stat structure.
450  */
451
452 #ifndef SMB_STRUCT_STAT
453 #  if defined(HAVE_STAT64) && defined(HAVE_OFF64_T)
454 #    define SMB_STRUCT_STAT struct stat64
455 #  else
456 #    define SMB_STRUCT_STAT struct stat
457 #  endif
458 #endif
459
460 /*
461  * Defines for 64 bit fcntl locks.
462  */
463
464 #ifndef SMB_STRUCT_FLOCK
465 #  if defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
466 #    define SMB_STRUCT_FLOCK struct flock64
467 #  else
468 #    define SMB_STRUCT_FLOCK struct flock
469 #  endif
470 #endif
471
472 #ifndef SMB_F_SETLKW
473 #  if defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
474 #    define SMB_F_SETLKW F_SETLKW64
475 #  else
476 #    define SMB_F_SETLKW F_SETLKW
477 #  endif
478 #endif
479
480 #ifndef SMB_F_SETLK
481 #  if defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
482 #    define SMB_F_SETLK F_SETLK64
483 #  else
484 #    define SMB_F_SETLK F_SETLK
485 #  endif
486 #endif
487
488 #ifndef SMB_F_GETLK
489 #  if defined(HAVE_STRUCT_FLOCK64) && defined(HAVE_OFF64_T)
490 #    define SMB_F_GETLK F_GETLK64
491 #  else
492 #    define SMB_F_GETLK F_GETLK
493 #  endif
494 #endif
495
496 #if defined(HAVE_LONGLONG)
497 #define SMB_BIG_UINT unsigned long long
498 #define SMB_BIG_INT long long
499 #else
500 #define SMB_BIG_UINT unsigned long
501 #define SMB_BIG_INT long
502 #endif
503
504 #ifndef MIN
505 #define MIN(a,b) ((a)<(b)?(a):(b))
506 #endif
507
508 #ifndef MAX
509 #define MAX(a,b) ((a)>(b)?(a):(b))
510 #endif
511
512 #ifndef HAVE_STRERROR
513 extern char *sys_errlist[];
514 #define strerror(i) sys_errlist[i]
515 #endif
516
517 #ifndef HAVE_STRCHR
518 # define strchr                 index
519 # define strrchr                rindex
520 #endif
521
522 #ifndef HAVE_ERRNO_DECL
523 extern int errno;
524 #endif
525
526 #ifdef HAVE_BROKEN_GETGROUPS
527 #define GID_T int
528 #else
529 #define GID_T gid_t
530 #endif
531
532
533 /* Lists, trees, caching, datbase... */
534 #include "ubi_sLinkList.h"
535 #include "ubi_dLinkList.h"
536 #include "dlinklist.h"
537
538 #ifndef UBI_BINTREE_H
539 #include "ubi_Cache.h"
540 #endif /* UBI_BINTREE_H */
541
542 #include "debugparse.h"
543
544 #include "version.h"
545 #include "smb.h"
546 #include "smbw.h"
547 #include "nameserv.h"
548
549 #include "byteorder.h"
550
551 #include "kanji.h"
552 #include "charset.h"
553
554 #include "nterr.h"
555
556 #ifndef MAXCODEPAGELINES
557 #define MAXCODEPAGELINES 256
558 #endif
559
560 /***** automatically generated prototypes *****/
561 #include "proto.h"
562
563 #ifdef strcpy
564 #undef strcpy
565 #endif /* strcpy */
566 #define strcpy(dest,src) __ERROR__XX__NEVER_USE_STRCPY___;
567
568 #ifdef strcat
569 #undef strcat
570 #endif /* strcat */
571 #define strcat(dest,src) __ERROR__XX__NEVER_USE_STRCAT___;
572
573 #ifdef sprintf
574 #undef sprintf
575 #endif /* sprintf */
576 #define sprintf __ERROR__XX__NEVER_USE_SPRINTF__;
577
578 #define pstrcpy(d,s) safe_strcpy((d),(s),sizeof(pstring)-1)
579 #define pstrcat(d,s) safe_strcat((d),(s),sizeof(pstring)-1)
580 #define fstrcpy(d,s) safe_strcpy((d),(s),sizeof(fstring)-1)
581 #define fstrcat(d,s) safe_strcat((d),(s),sizeof(fstring)-1)
582
583 #ifdef __COMPAR_FN_T
584 #define QSORT_CAST (__compar_fn_t)
585 #endif
586
587 #ifndef QSORT_CAST
588 #define QSORT_CAST (int (*)(const void *, const void *))
589 #endif
590
591 /* this guess needs to be improved (tridge) */
592 #if defined(STAT_STATVFS) && !defined(SYSV)
593 #define SYSV 1
594 #endif
595
596 #ifndef DEFAULT_PRINTING
597 #ifdef SYSV
598 #define DEFAULT_PRINTING PRINT_SYSV
599 #define PRINTCAP_NAME "lpstat"
600 #else
601 #define DEFAULT_PRINTING PRINT_BSD
602 #define PRINTCAP_NAME "/etc/printcap"
603 #endif
604 #endif
605
606 #ifndef PRINTCAP_NAME
607 #define PRINTCAP_NAME "/etc/printcap"
608 #endif
609
610 #ifndef SIGCLD
611 #define SIGCLD SIGCHLD
612 #endif
613
614 #if (defined(HAVE_SYSV_IPC) || defined(HAVE_SHARED_MMAP))
615 #define FAST_SHARE_MODES 1
616 #endif
617
618 #ifndef MAP_FILE
619 #define MAP_FILE 0
620 #endif
621
622 #ifdef HAVE_SYSV_IPC
623 #ifndef HAVE_UNION_SEMUN
624 union semun {
625         int val;
626         struct semid_ds *buf;
627         unsigned short *array;
628 };
629 #endif
630 #endif
631
632 #if (!defined(WITH_NISPLUS) && !defined(WITH_LDAP))
633 #define USE_SMBPASS_DB 1
634 #define USE_SMBUNIX_DB 1
635 #endif
636
637 #if defined(HAVE_PUTPRPWNAM) && defined(AUTH_CLEARTEXT_SEG_CHARS)
638 #define OSF1_ENH_SEC 1
639 #endif
640
641 #if defined(HAVE_PAM_AUTHENTICATE) && defined(HAVE_SECURITY_PAM_APPL_H)
642 #define HAVE_PAM 1
643 #endif
644
645 #ifndef ALLOW_CHANGE_PASSWORD
646 #if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
647 #define ALLOW_CHANGE_PASSWORD 1
648 #endif
649 #endif
650
651 /* what is the longest significant password available on your system? 
652  Knowing this speeds up password searches a lot */
653 #ifndef PASSWORD_LENGTH
654 #define PASSWORD_LENGTH 8
655 #endif
656
657 #ifdef REPLACE_INET_NTOA
658 #define inet_ntoa rep_inet_ntoa
659 #endif
660
661 #ifndef HAVE_PIPE
662 #define SYNC_DNS 1
663 #endif
664
665 #ifndef MAXPATHLEN
666 #define MAXPATHLEN 256
667 #endif
668
669 #ifndef SEEK_SET
670 #define SEEK_SET 0
671 #endif
672
673 #ifndef INADDR_LOOPBACK
674 #define INADDR_LOOPBACK 0x7f000001
675 #endif
676
677 #ifndef INADDR_NONE
678 #define INADDR_NONE 0xffffffff
679 #endif
680
681 #ifndef HAVE_CRYPT
682 #define crypt ufc_crypt
683 #endif
684
685 #ifndef O_ACCMODE
686 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
687 #endif
688
689 #if defined(HAVE_CRYPT16) && defined(HAVE_GETAUTHUID)
690 #define ULTRIX_AUTH 1
691 #endif
692
693 #ifdef HAVE_LIBREADLINE
694 #  ifdef HAVE_READLINE_READLINE_H
695 #    include <readline/readline.h>
696 #    ifdef HAVE_READLINE_HISTORY_H
697 #      include <readline/history.h>
698 #    endif
699 #  else
700 #    ifdef HAVE_READLINE_H
701 #      include <readline.h>
702 #      ifdef HAVE_HISTORY_H
703 #        include <history.h>
704 #      endif
705 #    else
706 #      undef HAVE_LIBREADLINE
707 #    endif
708 #  endif
709 #endif
710
711 #ifndef HAVE_STRDUP
712 char *strdup(const char *s);
713 #endif
714
715 #ifndef HAVE_MEMMOVE
716 void *memmove(void *dest,const void *src,int size);
717 #endif
718
719 #ifndef HAVE_INITGROUPS
720 int initgroups(char *name,gid_t id);
721 #endif
722
723 #ifndef HAVE_RENAME
724 int rename(const char *zfrom, const char *zto);
725 #endif
726
727 #ifndef HAVE_MKTIME
728 time_t mktime(struct tm *t);
729 #endif
730
731 #ifndef HAVE_FTRUNCATE
732 int ftruncate(int f,long l);
733 #endif
734
735 #if (defined(HAVE_SETRESUID) && !defined(HAVE_SETRESUID_DECL))
736 /* stupid glibc */
737 int setresuid(uid_t ruid, uid_t euid, uid_t suid);
738 int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
739 #endif
740
741 #if (defined(HAVE_CRYPT) && !defined(HAVE_CRYPT_DECL) && !defined(KRB4_AUTH))
742 /* stupid glibc */
743 int crypt(const char *key, const char *salt);
744 #endif
745
746 #if !defined(HAVE_BZERO) && defined(HAVE_MEMSET)
747 #define bzero(a,b) memset((a),'\0',(b))
748 #endif
749
750 #ifdef REPLACE_GETPASS
751 #define getpass(prompt) getsmbpass((prompt))
752 #endif
753
754 /* yuck, I'd like a better way of doing this */
755 #define DIRP_SIZE (256 + 32)
756
757 #endif /* _INCLUDES_H */