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