use double for dummy arrays to ensure alignment
[kai/samba.git] / source / smbwrapper / wrapped.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.0
4    SMB wrapper functions
5    Copyright (C) Andrew Tridgell 1998
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 /* NOTE: This file WILL produce compiler warnings. They are unavoidable */
23
24 #include "config.h"
25 #include <sys/types.h>
26 #include <errno.h>
27 #include "realcalls.h"
28
29  int open(char *name, int flags, mode_t mode)
30 {
31         if (smbw_path(name)) {
32                 return smbw_open(name, flags, mode);
33         }
34
35         return real_open(name, flags, mode);
36 }
37
38 #ifdef HAVE__OPEN
39  int _open(char *name, int flags, mode_t mode) 
40 {
41         return open(name, flags, mode);
42 }
43 #elif HAVE___OPEN
44  int __open(char *name, int flags, mode_t mode) 
45 {
46         return open(name, flags, mode);
47 }
48 #endif
49
50
51 #ifdef HAVE_OPEN64
52  int open64(char *name, int flags, mode_t mode)
53 {
54         if (smbw_path(name)) {
55                 return smbw_open(name, flags, mode);
56         }
57
58         return real_open64(name, flags, mode);
59 }
60 #endif
61
62 #ifndef NO_OPEN64_ALIAS
63 #ifdef HAVE__OPEN64
64  int _open64(char *name, int flags, mode_t mode) 
65 {
66         return open64(name, flags, mode);
67 }
68 #elif HAVE___OPEN64
69  int __open64(char *name, int flags, mode_t mode) 
70 {
71         return open64(name, flags, mode);
72 }
73 #endif
74 #endif
75
76 #ifdef HAVE_PREAD
77  ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
78 {
79         if (smbw_fd(fd)) {
80                 return smbw_pread(fd, buf, size, ofs);
81         }
82
83         return real_pread(fd, buf, size, ofs);
84 }
85 #endif
86
87 #ifdef HAVE_PREAD64
88  ssize_t pread64(int fd, void *buf, size_t size, off64_t ofs)
89 {
90         if (smbw_fd(fd)) {
91                 return smbw_pread(fd, buf, size, ofs);
92         }
93
94         return real_pread64(fd, buf, size, ofs);
95 }
96 #endif
97
98 #ifdef HAVE_PWRITE
99  ssize_t pwrite(int fd, void *buf, size_t size, off_t ofs)
100 {
101         if (smbw_fd(fd)) {
102                 return smbw_pwrite(fd, buf, size, ofs);
103         }
104
105         return real_pwrite(fd, buf, size, ofs);
106 }
107 #endif
108
109 #ifdef HAVE_PWRITE64
110  ssize_t pwrite64(int fd, void *buf, size_t size, off64_t ofs)
111 {
112         if (smbw_fd(fd)) {
113                 return smbw_pwrite(fd, buf, size, ofs);
114         }
115
116         return real_pwrite64(fd, buf, size, ofs);
117 }
118 #endif
119
120
121  int chdir(char *name)
122 {
123         return smbw_chdir(name);
124 }
125
126 #ifdef HAVE___CHDIR
127  int __chdir(char *name)
128 {
129         return chdir(name);
130 }
131 #elif HAVE__CHDIR
132  int _chdir(char *name)
133 {
134         return chdir(name);
135 }
136 #endif
137
138
139  int close(int fd)
140 {
141         if (smbw_fd(fd)) {
142                 return smbw_close(fd);
143         }
144
145         return real_close(fd);
146 }
147
148 #ifdef HAVE___CLOSE
149  int __close(int fd)
150 {
151         return close(fd);
152 }
153 #elif HAVE__CLOSE
154  int _close(int fd)
155 {
156         return close(fd);
157 }
158 #endif
159
160
161  int fchdir(int fd)
162 {
163         if (smbw_fd(fd)) {
164                 return smbw_fchdir(fd);
165         }
166
167         return real_fchdir(fd);
168 }
169
170 #ifdef HAVE___FCHDIR
171  int __fchdir(int fd)
172 {
173         return fchdir(fd);
174 }
175 #elif HAVE__FCHDIR
176  int _fchdir(int fd)
177 {
178         return fchdir(fd);
179 }
180 #endif
181
182
183  int fcntl(int fd, int cmd, long arg)
184 {
185         if (smbw_fd(fd)) {
186                 return smbw_fcntl(fd, cmd, arg);
187         }
188
189         return real_fcntl(fd, cmd, arg);
190 }
191
192
193 #ifdef HAVE___FCNTL
194  int __fcntl(int fd, int cmd, long arg)
195 {
196         return fcntl(fd, cmd, arg);
197 }
198 #elif HAVE__FCNTL
199  int _fcntl(int fd, int cmd, long arg)
200 {
201         return fcntl(fd, cmd, arg);
202 }
203 #endif
204
205
206
207 #ifdef real_getdents
208  int getdents(int fd, void *dirp, unsigned int count)
209 {
210         if (smbw_fd(fd)) {
211                 return smbw_getdents(fd, dirp, count);
212         }
213
214         return real_getdents(fd, dirp, count);
215 }
216 #endif
217
218 #ifdef HAVE___GETDENTS
219  int __getdents(int fd, void *dirp, unsigned int count)
220 {
221         return getdents(fd, dirp, count);
222 }
223 #elif HAVE__GETDENTS
224  int _getdents(int fd, void *dirp, unsigned int count)
225 {
226         return getdents(fd, dirp, count);
227 }
228 #endif
229
230
231  off_t lseek(int fd, off_t offset, int whence)
232 {
233         if (smbw_fd(fd)) {
234                 return smbw_lseek(fd, offset, whence);
235         }
236
237         return real_lseek(fd, offset, whence);
238 }
239
240 #ifdef HAVE___LSEEK
241  off_t __lseek(int fd, off_t offset, int whence)
242 {
243         return lseek(fd, offset, whence);
244 }
245 #elif HAVE__LSEEK
246  off_t _lseek(int fd, off_t offset, int whence)
247 {
248         return lseek(fd, offset, whence);
249 }
250 #endif
251
252
253  ssize_t read(int fd, void *buf, size_t count)
254 {
255         if (smbw_fd(fd)) {
256                 return smbw_read(fd, buf, count);
257         }
258
259         return real_read(fd, buf, count);
260 }
261
262 #ifdef HAVE___READ
263  ssize_t __read(int fd, void *buf, size_t count)
264 {
265         return read(fd, buf, count);
266 }
267 #elif HAVE__READ
268  ssize_t _read(int fd, void *buf, size_t count)
269 {
270         return read(fd, buf, count);
271 }
272 #endif
273
274
275  ssize_t write(int fd, void *buf, size_t count)
276 {
277         if (smbw_fd(fd)) {
278                 return smbw_write(fd, buf, count);
279         }
280
281         return real_write(fd, buf, count);
282 }
283
284 #ifdef HAVE___WRITE
285  ssize_t __write(int fd, void *buf, size_t count)
286 {
287         return write(fd, buf, count);
288 }
289 #elif HAVE__WRITE
290  ssize_t _write(int fd, void *buf, size_t count)
291 {
292         return write(fd, buf, count);
293 }
294 #endif
295
296
297
298  int access(char *name, int mode)
299 {
300         if (smbw_path(name)) {
301                 return smbw_access(name, mode);
302         }
303
304         return real_access(name, mode);
305 }
306
307
308
309  int chmod(char *name,mode_t mode)
310 {
311         if (smbw_path(name)) {
312                 return smbw_chmod(name, mode);
313         }
314
315         return real_chmod(name, mode);
316 }
317
318
319
320  int chown(char *name,uid_t owner, gid_t group)
321 {
322         if (smbw_path(name)) {
323                 return smbw_chown(name, owner, group);
324         }
325
326         return real_chown(name, owner, group);
327 }
328
329
330  char *getcwd(char *buf, size_t size)
331 {
332         return (char *)smbw_getcwd(buf, size);
333 }
334
335
336
337
338  int mkdir(char *name, mode_t mode)
339 {
340         if (smbw_path(name)) {
341                 return smbw_mkdir(name, mode);
342         }
343
344         return real_mkdir(name, mode);
345 }
346
347
348 #if HAVE___FXSTAT
349  int __fxstat(int vers, int fd, void *st)
350 {
351         double xx[32];
352         int ret;
353
354         if (smbw_fd(fd)) {
355                 return smbw_fstat(fd, st);
356         }
357
358         ret = real_fstat(fd, xx);
359         xstat_convert(vers, st, xx);
360         return ret;
361 }
362 #endif
363
364 #if HAVE___XSTAT
365  int __xstat(int vers, char *name, void *st)
366 {
367         double xx[32];
368         int ret;
369
370         if (smbw_path(name)) {
371                 return smbw_stat(name, st);
372         }
373
374         ret = real_stat(name, xx);
375         xstat_convert(vers, st, xx);
376         return ret;
377 }
378 #endif
379
380
381 #if HAVE___LXSTAT
382  int __lxstat(int vers, char *name, void *st)
383 {
384         double xx[32];
385         int ret;
386
387         if (smbw_path(name)) {
388                 return smbw_stat(name, st);
389         }
390
391         ret = real_lstat(name, xx);
392         xstat_convert(vers, st, xx);
393         return ret;
394 }
395 #endif
396
397
398  int stat(char *name, void *st)
399 {
400 #if HAVE___XSTAT
401         return __xstat(0, name, st);
402 #else
403         if (smbw_path(name)) {
404                 return smbw_stat(name, st);
405         }
406         return real_stat(name, st);
407 #endif
408 }
409
410  int lstat(char *name, void *st)
411 {
412 #if HAVE___LXSTAT
413         return __lxstat(0, name, st);
414 #else
415         if (smbw_path(name)) {
416                 return smbw_stat(name, st);
417         }
418         return real_lstat(name, st);
419 #endif
420 }
421
422  int fstat(int fd, void *st)
423 {
424 #if HAVE___LXSTAT
425         return __fxstat(0, fd, st);
426 #else
427         if (smbw_fd(fd)) {
428                 return smbw_fstat(fd, st);
429         }
430         return real_fstat(fd, st);
431 #endif
432 }
433
434
435  int unlink(char *name)
436 {
437         if (smbw_path(name)) {
438                 return smbw_unlink(name);
439         }
440
441         return real_unlink(name);
442 }
443
444
445 #ifdef HAVE_UTIME
446  int utime(char *name,void *tvp)
447 {
448         if (smbw_path(name)) {
449                 return smbw_utime(name, tvp);
450         }
451
452         return real_utime(name, tvp);
453 }
454 #endif
455
456 #ifdef HAVE_UTIMES
457  int utimes(char *name,void *tvp)
458 {
459         if (smbw_path(name)) {
460                 return smbw_utimes(name, tvp);
461         }
462
463         return real_utimes(name, tvp);
464 }
465 #endif
466
467  int readlink(char *path, char *buf, size_t bufsize)
468 {
469         if (smbw_path(path)) {
470                 return smbw_readlink(path, buf, bufsize);
471         }
472
473         return real_readlink(path, buf, bufsize);
474 }
475
476
477  int rename(char *oldname,char *newname)
478 {
479         int p1, p2;
480         p1 = smbw_path(oldname); 
481         p2 = smbw_path(newname); 
482         if (p1 ^ p2) {
483                 /* can't cross filesystem boundaries */
484                 errno = EXDEV;
485                 return -1;
486         }
487         if (p1 && p2) {
488                 return smbw_rename(oldname, newname);
489         }
490
491         return real_rename(oldname, newname);
492 }
493
494  int rmdir(char *name)
495 {
496         if (smbw_path(name)) {
497                 return smbw_rmdir(name);
498         }
499
500         return real_rmdir(name);
501 }
502
503
504  int symlink(char *topath,char *frompath)
505 {
506         int p1, p2;
507         p1 = smbw_path(topath); 
508         p2 = smbw_path(frompath); 
509         if (p1 || p2) {
510                 /* can't handle symlinks */
511                 errno = EPERM;
512                 return -1;
513         }
514
515         return real_symlink(topath, frompath);
516 }
517
518  int dup(int fd)
519 {
520         if (smbw_fd(fd)) {
521                 return smbw_dup(fd);
522         }
523
524         return real_dup(fd);
525 }
526
527  int dup2(int oldfd, int newfd)
528 {
529         if (smbw_fd(newfd)) {
530                 close(newfd);
531         }
532
533         if (smbw_fd(oldfd)) {
534                 return smbw_dup2(oldfd, newfd);
535         }
536
537         return real_dup2(oldfd, newfd);
538 }
539
540 #ifdef real_opendir
541  void *opendir(char *name)
542 {
543         if (smbw_path(name)) {
544                 return (void *)smbw_opendir(name);
545         }
546
547         return (void *)real_opendir(name);
548 }
549 #endif
550
551 #ifdef real_readdir
552  void *readdir(void *dir)
553 {
554         if (smbw_dirp(dir)) {
555                 return (void *)smbw_readdir(dir);
556         }
557
558         return (void *)real_readdir(dir);
559 }
560 #endif
561
562 #ifdef real_closedir
563  int closedir(void *dir)
564 {
565         if (smbw_dirp(dir)) {
566                 return smbw_closedir(dir);
567         }
568
569         return real_closedir(dir);
570 }
571 #endif
572
573 #ifdef real_telldir
574  off_t telldir(void *dir)
575 {
576         if (smbw_dirp(dir)) {
577                 return smbw_telldir(dir);
578         }
579
580         return real_telldir(dir);
581 }
582 #endif
583
584 #ifdef real_seekdir
585  int seekdir(void *dir, off_t offset)
586 {
587         if (smbw_dirp(dir)) {
588                 smbw_seekdir(dir, offset);
589                 return 0;
590         }
591
592         real_seekdir(dir, offset);
593         return 0;
594 }
595 #endif
596
597
598 #ifndef NO_ACL_WRAPPER
599  int  acl(char  *pathp,  int  cmd,  int  nentries, void *aclbufp)
600 {
601         if (smbw_path(pathp)) {
602                 return smbw_acl(pathp, cmd, nentries, aclbufp);
603         }
604
605         return real_acl(pathp, cmd, nentries, aclbufp);
606 }
607 #endif
608
609 #ifndef NO_FACL_WRAPPER
610  int  facl(int fd,  int  cmd,  int  nentries, void *aclbufp)
611 {
612         if (smbw_fd(fd)) {
613                 return smbw_facl(fd, cmd, nentries, aclbufp);
614         }
615
616         return real_facl(fd, cmd, nentries, aclbufp);
617 }
618 #endif
619
620  int creat(char *path, mode_t mode)
621 {
622         extern int creat_bits;
623         return open(path, creat_bits, mode);
624 }
625
626 #ifdef HAVE_CREAT64
627  int creat64(char *path, mode_t mode)
628 {
629         extern int creat_bits;
630         return open64(path, creat_bits, mode);
631 }
632 #endif
633
634 #ifdef HAVE_STAT64
635   int stat64(char *name, void *st64)
636 {
637         if (smbw_path(name)) {
638                 double xx[32];
639                 int ret = stat(name, xx);
640                 stat64_convert(xx, st64);
641                 return ret;
642         }
643         return real_stat64(name, st64);
644 }
645
646   int fstat64(int fd, void *st64)
647 {
648         if (smbw_fd(fd)) {
649                 double xx[32];
650                 int ret = fstat(fd, xx);
651                 stat64_convert(xx, st64);
652                 return ret;
653         }
654         return real_fstat64(fd, st64);
655 }
656
657   int lstat64(char *name, void *st64)
658 {
659         if (smbw_path(name)) {
660                 double xx[32];
661                 int ret = lstat(name, xx);
662                 stat64_convert(xx, st64);
663                 return ret;
664         }
665         return real_lstat64(name, st64);
666 }
667 #endif
668
669 #ifdef HAVE_LLSEEK
670   offset_t llseek(int fd, offset_t ofs, int whence)
671 {
672         if (smbw_fd(fd)) {
673                 return lseek(fd, ofs, whence);
674         }
675         return real_llseek(fd, ofs, whence);
676 }
677 #endif
678
679 #ifdef HAVE_READDIR64
680  void *readdir64(void *dir)
681 {
682         if (smbw_dirp(dir)) {
683                 static double xx[70];
684                 void *d;
685                 d = (void *)readdir(dir);
686                 if (!d) return NULL;
687                 dirent64_convert(d, xx);
688                 return xx;
689         }
690         return (void *)real_readdir64(dir);
691 }
692 #endif
693
694  int fork(void)
695 {
696         return smbw_fork();
697 }
698