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