2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Jeremy Allison 1998-2005
6 Copyright (C) Timur Bakeyev 2005
7 Copyright (C) Bjoern Jacke 2006-2007
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 3 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "system/syslog.h"
25 #include "system/capability.h"
27 #ifdef HAVE_SYS_PRCTL_H
28 #include <sys/prctl.h>
32 The idea is that this file will eventually have wrappers around all
33 important system calls in samba. The aims are:
35 - to enable easier porting by putting OS dependent stuff in here
37 - to allow for hooks into other "pseudo-filesystems"
39 - to allow easier integration of things like the japanese extensions
41 - to support the philosophy of Samba to expose the features of
42 the OS within the SMB model. In general whatever file/printer/variable
43 expansions/etc make sense to the OS should be acceptable to Samba.
48 /*******************************************************************
49 A wrapper for memalign
50 ********************************************************************/
52 void *sys_memalign( size_t align, size_t size )
54 #if defined(HAVE_POSIX_MEMALIGN)
56 int ret = posix_memalign( &p, align, size );
61 #elif defined(HAVE_MEMALIGN)
62 return memalign( align, size );
64 /* On *BSD systems memaligns doesn't exist, but memory will
65 * be aligned on allocations of > pagesize. */
66 #if defined(SYSCONF_SC_PAGESIZE)
67 size_t pagesize = (size_t)sysconf(_SC_PAGESIZE);
68 #elif defined(HAVE_GETPAGESIZE)
69 size_t pagesize = (size_t)getpagesize();
71 size_t pagesize = (size_t)-1;
73 if (pagesize == (size_t)-1) {
74 DEBUG(0,("memalign functionalaity not available on this platform!\n"));
77 if (size < pagesize) {
80 return SMB_MALLOC(size);
84 /*******************************************************************
85 A wrapper for usleep in case we don't have one.
86 ********************************************************************/
88 int sys_usleep(long usecs)
95 * We need this braindamage as the glibc usleep
96 * is not SPEC1170 complient... grumble... JRA.
99 if(usecs < 0 || usecs > 999999) {
107 #else /* HAVE_USLEEP */
109 * Fake it with select...
112 tval.tv_usec = usecs/1000;
113 select(0,NULL,NULL,NULL,&tval);
115 #endif /* HAVE_USLEEP */
118 /*******************************************************************
119 A read wrapper that will deal with EINTR.
120 ********************************************************************/
122 ssize_t sys_read(int fd, void *buf, size_t count)
127 ret = read(fd, buf, count);
128 #if defined(EWOULDBLOCK)
129 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
131 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
136 /*******************************************************************
137 A write wrapper that will deal with EINTR.
138 ********************************************************************/
140 ssize_t sys_write(int fd, const void *buf, size_t count)
145 ret = write(fd, buf, count);
146 #if defined(EWOULDBLOCK)
147 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
149 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
154 /*******************************************************************
155 A writev wrapper that will deal with EINTR.
156 ********************************************************************/
158 ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
163 /* Try to confuse write_data_iov a bit */
164 if ((random() % 5) == 0) {
165 return sys_write(fd, iov[0].iov_base, iov[0].iov_len);
167 if (iov[0].iov_len > 1) {
168 return sys_write(fd, iov[0].iov_base,
169 (random() % (iov[0].iov_len-1)) + 1);
174 ret = writev(fd, iov, iovcnt);
175 #if defined(EWOULDBLOCK)
176 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
178 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
183 /*******************************************************************
184 A pread wrapper that will deal with EINTR and 64-bit file offsets.
185 ********************************************************************/
187 #if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
188 ssize_t sys_pread(int fd, void *buf, size_t count, SMB_OFF_T off)
193 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PREAD64)
194 ret = pread64(fd, buf, count, off);
196 ret = pread(fd, buf, count, off);
198 } while (ret == -1 && errno == EINTR);
203 /*******************************************************************
204 A write wrapper that will deal with EINTR and 64-bit file offsets.
205 ********************************************************************/
207 #if defined(HAVE_PWRITE) || defined(HAVE_PWRITE64)
208 ssize_t sys_pwrite(int fd, const void *buf, size_t count, SMB_OFF_T off)
213 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_PWRITE64)
214 ret = pwrite64(fd, buf, count, off);
216 ret = pwrite(fd, buf, count, off);
218 } while (ret == -1 && errno == EINTR);
223 /*******************************************************************
224 A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
225 ********************************************************************/
227 ssize_t sys_send(int s, const void *msg, size_t len, int flags)
232 ret = send(s, msg, len, flags);
233 #if defined(EWOULDBLOCK)
234 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
236 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
241 /*******************************************************************
242 A sendto wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
243 ********************************************************************/
245 ssize_t sys_sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen)
250 ret = sendto(s, msg, len, flags, to, tolen);
251 #if defined(EWOULDBLOCK)
252 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
254 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
259 /*******************************************************************
260 A recv wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
261 ********************************************************************/
263 ssize_t sys_recv(int fd, void *buf, size_t count, int flags)
268 ret = recv(fd, buf, count, flags);
269 #if defined(EWOULDBLOCK)
270 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
272 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
277 /*******************************************************************
278 A recvfrom wrapper that will deal with EINTR.
279 ********************************************************************/
281 ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
286 ret = recvfrom(s, buf, len, flags, from, fromlen);
287 #if defined(EWOULDBLOCK)
288 } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
290 } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
295 /*******************************************************************
296 A fcntl wrapper that will deal with EINTR.
297 ********************************************************************/
299 int sys_fcntl_ptr(int fd, int cmd, void *arg)
304 ret = fcntl(fd, cmd, arg);
305 } while (ret == -1 && errno == EINTR);
309 /*******************************************************************
310 A fcntl wrapper that will deal with EINTR.
311 ********************************************************************/
313 int sys_fcntl_long(int fd, int cmd, long arg)
318 ret = fcntl(fd, cmd, arg);
319 } while (ret == -1 && errno == EINTR);
323 /****************************************************************************
324 Get/Set all the possible time fields from a stat struct as a timespec.
325 ****************************************************************************/
327 static struct timespec get_atimespec(const struct stat *pst)
329 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
332 /* Old system - no ns timestamp. */
333 ret.tv_sec = pst->st_atime;
337 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
339 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
341 ret.tv_sec = pst->st_atime;
342 ret.tv_nsec = pst->st_atimensec;
344 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
346 ret.tv_sec = pst->st_atime;
347 ret.tv_nsec = pst->st_atime_n;
349 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
351 ret.tv_sec = pst->st_atime;
352 ret.tv_nsec = pst->st_uatime * 1000;
354 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
355 return pst->st_atimespec;
357 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
362 static struct timespec get_mtimespec(const struct stat *pst)
364 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
367 /* Old system - no ns timestamp. */
368 ret.tv_sec = pst->st_mtime;
372 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
374 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
376 ret.tv_sec = pst->st_mtime;
377 ret.tv_nsec = pst->st_mtimensec;
379 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
381 ret.tv_sec = pst->st_mtime;
382 ret.tv_nsec = pst->st_mtime_n;
384 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
386 ret.tv_sec = pst->st_mtime;
387 ret.tv_nsec = pst->st_umtime * 1000;
389 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
390 return pst->st_mtimespec;
392 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
397 static struct timespec get_ctimespec(const struct stat *pst)
399 #if !defined(HAVE_STAT_HIRES_TIMESTAMPS)
402 /* Old system - no ns timestamp. */
403 ret.tv_sec = pst->st_ctime;
407 #if defined(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
409 #elif defined(HAVE_STRUCT_STAT_ST_MTIMENSEC)
411 ret.tv_sec = pst->st_ctime;
412 ret.tv_nsec = pst->st_ctimensec;
414 #elif defined(HAVE_STRUCT_STAT_ST_MTIME_N)
416 ret.tv_sec = pst->st_ctime;
417 ret.tv_nsec = pst->st_ctime_n;
419 #elif defined(HAVE_STRUCT_STAT_ST_UMTIME)
421 ret.tv_sec = pst->st_ctime;
422 ret.tv_nsec = pst->st_uctime * 1000;
424 #elif defined(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
425 return pst->st_ctimespec;
427 #error CONFIGURE_ERROR_IN_DETECTING_TIMESPEC_IN_STAT
432 /****************************************************************************
433 Return the best approximation to a 'create time' under UNIX from a stat
435 ****************************************************************************/
437 static struct timespec calc_create_time_stat(const struct stat *st)
439 struct timespec ret, ret1;
440 struct timespec c_time = get_ctimespec(st);
441 struct timespec m_time = get_mtimespec(st);
442 struct timespec a_time = get_atimespec(st);
444 ret = timespec_compare(&c_time, &m_time) < 0 ? c_time : m_time;
445 ret1 = timespec_compare(&ret, &a_time) < 0 ? ret : a_time;
447 if(!null_timespec(ret1)) {
452 * One of ctime, mtime or atime was zero (probably atime).
453 * Just return MIN(ctime, mtime).
458 /****************************************************************************
459 Return the best approximation to a 'create time' under UNIX from a stat_ex
461 ****************************************************************************/
463 static struct timespec calc_create_time_stat_ex(const struct stat_ex *st)
465 struct timespec ret, ret1;
466 struct timespec c_time = st->st_ex_ctime;
467 struct timespec m_time = st->st_ex_mtime;
468 struct timespec a_time = st->st_ex_atime;
470 ret = timespec_compare(&c_time, &m_time) < 0 ? c_time : m_time;
471 ret1 = timespec_compare(&ret, &a_time) < 0 ? ret : a_time;
473 if(!null_timespec(ret1)) {
478 * One of ctime, mtime or atime was zero (probably atime).
479 * Just return MIN(ctime, mtime).
484 /****************************************************************************
485 Return the 'create time' from a stat struct if it exists (birthtime) or else
486 use the best approximation.
487 ****************************************************************************/
489 static void make_create_timespec(const struct stat *pst, struct stat_ex *dst,
490 bool fake_dir_create_times)
492 if (S_ISDIR(pst->st_mode) && fake_dir_create_times) {
493 dst->st_ex_btime.tv_sec = 315493200L; /* 1/1/1980 */
494 dst->st_ex_btime.tv_nsec = 0;
497 dst->st_ex_calculated_birthtime = false;
499 #if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC)
500 dst->st_ex_btime = pst->st_birthtimespec;
501 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIMENSEC)
502 dst->st_ex_btime.tv_sec = pst->st_birthtime;
503 dst->st_ex_btime.tv_nsec = pst->st_birthtimenspec;
504 #elif defined(HAVE_STRUCT_STAT_ST_BIRTHTIME)
505 dst->st_ex_btime.tv_sec = pst->st_birthtime;
506 dst->st_ex_btime.tv_nsec = 0;
508 dst->st_ex_btime = calc_create_time_stat(pst);
509 dst->st_ex_calculated_birthtime = true;
512 /* Deal with systems that don't initialize birthtime correctly.
513 * Pointed out by SATOH Fumiyasu <fumiyas@osstech.jp>.
515 if (null_timespec(dst->st_ex_btime)) {
516 dst->st_ex_btime = calc_create_time_stat(pst);
517 dst->st_ex_calculated_birthtime = true;
521 /****************************************************************************
522 If we update a timestamp in a stat_ex struct we may have to recalculate
523 the birthtime. For now only implement this for write time, but we may
524 also need to do it for atime and ctime. JRA.
525 ****************************************************************************/
527 void update_stat_ex_mtime(struct stat_ex *dst,
528 struct timespec write_ts)
530 dst->st_ex_mtime = write_ts;
532 /* We may have to recalculate btime. */
533 if (dst->st_ex_calculated_birthtime) {
534 dst->st_ex_btime = calc_create_time_stat_ex(dst);
538 void update_stat_ex_create_time(struct stat_ex *dst,
539 struct timespec create_time)
541 dst->st_ex_btime = create_time;
542 dst->st_ex_calculated_birthtime = false;
545 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)
546 static void init_stat_ex_from_stat (struct stat_ex *dst,
547 const struct stat64 *src,
548 bool fake_dir_create_times)
550 static void init_stat_ex_from_stat (struct stat_ex *dst,
551 const struct stat *src,
552 bool fake_dir_create_times)
555 dst->st_ex_dev = src->st_dev;
556 dst->st_ex_ino = src->st_ino;
557 dst->st_ex_mode = src->st_mode;
558 dst->st_ex_nlink = src->st_nlink;
559 dst->st_ex_uid = src->st_uid;
560 dst->st_ex_gid = src->st_gid;
561 dst->st_ex_rdev = src->st_rdev;
562 dst->st_ex_size = src->st_size;
563 dst->st_ex_atime = get_atimespec(src);
564 dst->st_ex_mtime = get_mtimespec(src);
565 dst->st_ex_ctime = get_ctimespec(src);
566 make_create_timespec(src, dst, fake_dir_create_times);
567 #ifdef HAVE_STAT_ST_BLKSIZE
568 dst->st_ex_blksize = src->st_blksize;
570 dst->st_ex_blksize = STAT_ST_BLOCKSIZE;
573 #ifdef HAVE_STAT_ST_BLOCKS
574 dst->st_ex_blocks = src->st_blocks;
576 dst->st_ex_blocks = src->st_size / dst->st_ex_blksize + 1;
579 #ifdef HAVE_STAT_ST_FLAGS
580 dst->st_ex_flags = src->st_flags;
582 dst->st_ex_flags = 0;
586 /*******************************************************************
587 A stat() wrapper that will deal with 64 bit filesizes.
588 ********************************************************************/
590 int sys_stat(const char *fname, SMB_STRUCT_STAT *sbuf,
591 bool fake_dir_create_times)
594 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_STAT64)
595 struct stat64 statbuf;
596 ret = stat64(fname, &statbuf);
599 ret = stat(fname, &statbuf);
602 /* we always want directories to appear zero size */
603 if (S_ISDIR(statbuf.st_mode)) {
606 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
611 /*******************************************************************
612 An fstat() wrapper that will deal with 64 bit filesizes.
613 ********************************************************************/
615 int sys_fstat(int fd, SMB_STRUCT_STAT *sbuf, bool fake_dir_create_times)
618 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FSTAT64)
619 struct stat64 statbuf;
620 ret = fstat64(fd, &statbuf);
623 ret = fstat(fd, &statbuf);
626 /* we always want directories to appear zero size */
627 if (S_ISDIR(statbuf.st_mode)) {
630 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
635 /*******************************************************************
636 An lstat() wrapper that will deal with 64 bit filesizes.
637 ********************************************************************/
639 int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf,
640 bool fake_dir_create_times)
643 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSTAT64)
644 struct stat64 statbuf;
645 ret = lstat64(fname, &statbuf);
648 ret = lstat(fname, &statbuf);
651 /* we always want directories to appear zero size */
652 if (S_ISDIR(statbuf.st_mode)) {
655 init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times);
660 /*******************************************************************
661 An posix_fallocate() wrapper that will deal with 64 bit filesizes.
662 ********************************************************************/
663 int sys_posix_fallocate(int fd, SMB_OFF_T offset, SMB_OFF_T len)
665 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_POSIX_FALLOCATE64) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
666 return posix_fallocate64(fd, offset, len);
667 #elif defined(HAVE_POSIX_FALLOCATE) && !defined(HAVE_BROKEN_POSIX_FALLOCATE)
668 return posix_fallocate(fd, offset, len);
669 #elif defined(F_RESVSP64)
670 /* this handles XFS on IRIX */
672 SMB_OFF_T new_len = offset + len;
676 /* unlikely to get a too large file on a 64bit system but ... */
680 fl.l_whence = SEEK_SET;
684 ret=fcntl(fd, F_RESVSP64, &fl);
689 /* Make sure the file gets enlarged after we allocated space: */
691 if (new_len > sbuf.st_size)
692 ftruncate64(fd, new_len);
699 /*******************************************************************
700 An fallocate() function that matches the semantics of the Linux one.
701 ********************************************************************/
703 #ifdef HAVE_LINUX_FALLOC_H
704 #include <linux/falloc.h>
707 int sys_fallocate(int fd, enum vfs_fallocate_mode mode, SMB_OFF_T offset, SMB_OFF_T len)
709 #if defined(HAVE_LINUX_FALLOCATE64) || defined(HAVE_LINUX_FALLOCATE)
712 case VFS_FALLOCATE_EXTEND_SIZE:
715 case VFS_FALLOCATE_KEEP_SIZE:
716 lmode = FALLOC_FL_KEEP_SIZE;
722 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LINUX_FALLOCATE64)
723 return fallocate64(fd, lmode, offset, len);
724 #elif defined(HAVE_LINUX_FALLOCATE)
725 return fallocate(fd, lmode, offset, len);
728 /* TODO - plumb in fallocate from other filesysetms like VXFS etc. JRA. */
734 /*******************************************************************
735 An ftruncate() wrapper that will deal with 64 bit filesizes.
736 ********************************************************************/
738 int sys_ftruncate(int fd, SMB_OFF_T offset)
740 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_FTRUNCATE64)
741 return ftruncate64(fd, offset);
743 return ftruncate(fd, offset);
747 /*******************************************************************
748 An lseek() wrapper that will deal with 64 bit filesizes.
749 ********************************************************************/
751 SMB_OFF_T sys_lseek(int fd, SMB_OFF_T offset, int whence)
753 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OFF64_T) && defined(HAVE_LSEEK64)
754 return lseek64(fd, offset, whence);
756 return lseek(fd, offset, whence);
760 /*******************************************************************
761 An fseek() wrapper that will deal with 64 bit filesizes.
762 ********************************************************************/
764 int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence)
766 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEK64)
767 return fseek64(fp, offset, whence);
768 #elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FSEEKO64)
769 return fseeko64(fp, offset, whence);
771 return fseek(fp, offset, whence);
775 /*******************************************************************
776 An ftell() wrapper that will deal with 64 bit filesizes.
777 ********************************************************************/
779 SMB_OFF_T sys_ftell(FILE *fp)
781 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELL64)
782 return (SMB_OFF_T)ftell64(fp);
783 #elif defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(LARGE_SMB_OFF_T) && defined(HAVE_FTELLO64)
784 return (SMB_OFF_T)ftello64(fp);
786 return (SMB_OFF_T)ftell(fp);
790 /*******************************************************************
791 A creat() wrapper that will deal with 64 bit filesizes.
792 ********************************************************************/
794 int sys_creat(const char *path, mode_t mode)
796 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CREAT64)
797 return creat64(path, mode);
800 * If creat64 isn't defined then ensure we call a potential open64.
803 return sys_open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
807 /*******************************************************************
808 An open() wrapper that will deal with 64 bit filesizes.
809 ********************************************************************/
811 int sys_open(const char *path, int oflag, mode_t mode)
813 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPEN64)
814 return open64(path, oflag, mode);
816 return open(path, oflag, mode);
820 /*******************************************************************
821 An fopen() wrapper that will deal with 64 bit filesizes.
822 ********************************************************************/
824 FILE *sys_fopen(const char *path, const char *type)
826 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FOPEN64)
827 return fopen64(path, type);
829 return fopen(path, type);
834 /*******************************************************************
835 A flock() wrapper that will perform the kernel flock.
836 ********************************************************************/
838 void kernel_flock(int fd, uint32 share_mode, uint32 access_mask)
840 #if HAVE_KERNEL_SHARE_MODES
842 if (share_mode == FILE_SHARE_WRITE) {
843 kernel_mode = LOCK_MAND|LOCK_WRITE;
844 } else if (share_mode == FILE_SHARE_READ) {
845 kernel_mode = LOCK_MAND|LOCK_READ;
846 } else if (share_mode == FILE_SHARE_NONE) {
847 kernel_mode = LOCK_MAND;
850 flock(fd, kernel_mode);
858 /*******************************************************************
859 An opendir wrapper that will deal with 64 bit filesizes.
860 ********************************************************************/
862 SMB_STRUCT_DIR *sys_opendir(const char *name)
864 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_OPENDIR64)
865 return opendir64(name);
867 return opendir(name);
871 /*******************************************************************
872 An fdopendir wrapper that will deal with 64 bit filesizes.
873 Ugly hack - we need dirfd for this to work correctly in the
875 ********************************************************************/
877 SMB_STRUCT_DIR *sys_fdopendir(int fd)
879 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_FDOPENDIR64) && defined(HAVE_DIRFD)
880 return fdopendir64(fd);
881 #elif defined(HAVE_FDOPENDIR) && defined(HAVE_DIRFD)
882 return fdopendir(fd);
889 /*******************************************************************
890 A readdir wrapper that will deal with 64 bit filesizes.
891 ********************************************************************/
893 SMB_STRUCT_DIRENT *sys_readdir(SMB_STRUCT_DIR *dirp)
895 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_READDIR64)
896 return readdir64(dirp);
898 return readdir(dirp);
902 /*******************************************************************
903 A seekdir wrapper that will deal with 64 bit filesizes.
904 ********************************************************************/
906 void sys_seekdir(SMB_STRUCT_DIR *dirp, long offset)
908 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_SEEKDIR64)
909 seekdir64(dirp, offset);
911 seekdir(dirp, offset);
915 /*******************************************************************
916 A telldir wrapper that will deal with 64 bit filesizes.
917 ********************************************************************/
919 long sys_telldir(SMB_STRUCT_DIR *dirp)
921 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_TELLDIR64)
922 return (long)telldir64(dirp);
924 return (long)telldir(dirp);
928 /*******************************************************************
929 A rewinddir wrapper that will deal with 64 bit filesizes.
930 ********************************************************************/
932 void sys_rewinddir(SMB_STRUCT_DIR *dirp)
934 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_REWINDDIR64)
941 /*******************************************************************
942 A close wrapper that will deal with 64 bit filesizes.
943 ********************************************************************/
945 int sys_closedir(SMB_STRUCT_DIR *dirp)
947 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_CLOSEDIR64)
948 return closedir64(dirp);
950 return closedir(dirp);
954 /*******************************************************************
955 An mknod() wrapper that will deal with 64 bit filesizes.
956 ********************************************************************/
958 int sys_mknod(const char *path, mode_t mode, SMB_DEV_T dev)
960 #if defined(HAVE_MKNOD) || defined(HAVE_MKNOD64)
961 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_MKNOD64) && defined(HAVE_DEV64_T)
962 return mknod64(path, mode, dev);
964 return mknod(path, mode, dev);
967 /* No mknod system call. */
973 /*******************************************************************
974 The wait() calls vary between systems
975 ********************************************************************/
977 int sys_waitpid(pid_t pid,int *status,int options)
980 return waitpid(pid,status,options);
981 #else /* HAVE_WAITPID */
982 return wait4(pid, status, options, NULL);
983 #endif /* HAVE_WAITPID */
986 /*******************************************************************
987 System wrapper for getwd
988 ********************************************************************/
990 char *sys_getwd(char *s)
994 wd = (char *)getcwd(s, PATH_MAX);
996 wd = (char *)getwd(s);
1001 #if defined(HAVE_POSIX_CAPABILITIES)
1003 /**************************************************************************
1004 Try and abstract process capabilities (for systems that have them).
1005 ****************************************************************************/
1007 /* Set the POSIX capabilities needed for the given purpose into the effective
1008 * capability set of the current process. Make sure they are always removed
1009 * from the inheritable set, because there is no circumstance in which our
1010 * children should inherit our elevated privileges.
1012 static bool set_process_capability(enum smbd_capability capability,
1015 cap_value_t cap_vals[2] = {0};
1016 int num_cap_vals = 0;
1020 #if defined(HAVE_PRCTL) && defined(PR_GET_KEEPCAPS) && defined(PR_SET_KEEPCAPS)
1021 /* On Linux, make sure that any capabilities we grab are sticky
1022 * across UID changes. We expect that this would allow us to keep both
1023 * the effective and permitted capability sets, but as of circa 2.6.16,
1024 * only the permitted set is kept. It is a bug (which we work around)
1025 * that the effective set is lost, but we still require the effective
1028 if (!prctl(PR_GET_KEEPCAPS)) {
1029 prctl(PR_SET_KEEPCAPS, 1);
1033 cap = cap_get_proc();
1035 DEBUG(0,("set_process_capability: cap_get_proc failed: %s\n",
1040 switch (capability) {
1041 case KERNEL_OPLOCK_CAPABILITY:
1042 #ifdef CAP_NETWORK_MGT
1043 /* IRIX has CAP_NETWORK_MGT for oplocks. */
1044 cap_vals[num_cap_vals++] = CAP_NETWORK_MGT;
1047 case DMAPI_ACCESS_CAPABILITY:
1048 #ifdef CAP_DEVICE_MGT
1049 /* IRIX has CAP_DEVICE_MGT for DMAPI access. */
1050 cap_vals[num_cap_vals++] = CAP_DEVICE_MGT;
1052 /* Linux has CAP_MKNOD for DMAPI access. */
1053 cap_vals[num_cap_vals++] = CAP_MKNOD;
1056 case LEASE_CAPABILITY:
1058 cap_vals[num_cap_vals++] = CAP_LEASE;
1063 SMB_ASSERT(num_cap_vals <= ARRAY_SIZE(cap_vals));
1065 if (num_cap_vals == 0) {
1070 cap_set_flag(cap, CAP_EFFECTIVE, num_cap_vals, cap_vals,
1071 enable ? CAP_SET : CAP_CLEAR);
1073 /* We never want to pass capabilities down to our children, so make
1074 * sure they are not inherited.
1076 cap_set_flag(cap, CAP_INHERITABLE, num_cap_vals, cap_vals, CAP_CLEAR);
1078 if (cap_set_proc(cap) == -1) {
1079 DEBUG(0, ("set_process_capability: cap_set_proc failed: %s\n",
1089 #endif /* HAVE_POSIX_CAPABILITIES */
1091 /****************************************************************************
1092 Gain the oplock capability from the kernel if possible.
1093 ****************************************************************************/
1095 void set_effective_capability(enum smbd_capability capability)
1097 #if defined(HAVE_POSIX_CAPABILITIES)
1098 set_process_capability(capability, True);
1099 #endif /* HAVE_POSIX_CAPABILITIES */
1102 void drop_effective_capability(enum smbd_capability capability)
1104 #if defined(HAVE_POSIX_CAPABILITIES)
1105 set_process_capability(capability, False);
1106 #endif /* HAVE_POSIX_CAPABILITIES */
1109 /**************************************************************************
1110 Wrapper for random().
1111 ****************************************************************************/
1113 long sys_random(void)
1115 #if defined(HAVE_RANDOM)
1116 return (long)random();
1117 #elif defined(HAVE_RAND)
1118 return (long)rand();
1120 DEBUG(0,("Error - no random function available !\n"));
1125 /**************************************************************************
1126 Wrapper for srandom().
1127 ****************************************************************************/
1129 void sys_srandom(unsigned int seed)
1131 #if defined(HAVE_SRANDOM)
1133 #elif defined(HAVE_SRAND)
1136 DEBUG(0,("Error - no srandom function available !\n"));
1142 #define NGROUPS_MAX 32 /* Guess... */
1145 /**************************************************************************
1146 Returns equivalent to NGROUPS_MAX - using sysconf if needed.
1147 ****************************************************************************/
1149 int groups_max(void)
1151 #if defined(SYSCONF_SC_NGROUPS_MAX)
1152 int ret = sysconf(_SC_NGROUPS_MAX);
1153 return (ret == -1) ? NGROUPS_MAX : ret;
1159 /**************************************************************************
1160 Wrap setgroups and getgroups for systems that declare getgroups() as
1161 returning an array of gid_t, but actuall return an array of int.
1162 ****************************************************************************/
1164 #if defined(HAVE_BROKEN_GETGROUPS)
1166 #ifdef HAVE_BROKEN_GETGROUPS
1172 static int sys_broken_getgroups(int setlen, gid_t *gidset)
1179 return getgroups(setlen, &gid);
1183 * Broken case. We need to allocate a
1184 * GID_T array of size setlen.
1193 setlen = groups_max();
1195 if((group_list = SMB_MALLOC_ARRAY(GID_T, setlen)) == NULL) {
1196 DEBUG(0,("sys_getgroups: Malloc fail.\n"));
1200 if((ngroups = getgroups(setlen, group_list)) < 0) {
1201 int saved_errno = errno;
1202 SAFE_FREE(group_list);
1203 errno = saved_errno;
1207 for(i = 0; i < ngroups; i++)
1208 gidset[i] = (gid_t)group_list[i];
1210 SAFE_FREE(group_list);
1214 static int sys_broken_setgroups(int setlen, gid_t *gidset)
1222 if (setlen < 0 || setlen > groups_max()) {
1228 * Broken case. We need to allocate a
1229 * GID_T array of size setlen.
1232 if((group_list = SMB_MALLOC_ARRAY(GID_T, setlen)) == NULL) {
1233 DEBUG(0,("sys_setgroups: Malloc fail.\n"));
1237 for(i = 0; i < setlen; i++)
1238 group_list[i] = (GID_T) gidset[i];
1240 if(setgroups(setlen, group_list) != 0) {
1241 int saved_errno = errno;
1242 SAFE_FREE(group_list);
1243 errno = saved_errno;
1247 SAFE_FREE(group_list);
1251 #endif /* HAVE_BROKEN_GETGROUPS */
1253 /* This is a list of systems that require the first GID passed to setgroups(2)
1254 * to be the effective GID. If your system is one of these, add it here.
1256 #if defined (FREEBSD) || defined (DARWINOS)
1257 #define USE_BSD_SETGROUPS
1260 #if defined(USE_BSD_SETGROUPS)
1261 /* Depending on the particular BSD implementation, the first GID that is
1262 * passed to setgroups(2) will either be ignored or will set the credential's
1263 * effective GID. In either case, the right thing to do is to guarantee that
1264 * gidset[0] is the effective GID.
1266 static int sys_bsd_setgroups(gid_t primary_gid, int setlen, const gid_t *gidset)
1268 gid_t *new_gidset = NULL;
1272 /* setgroups(2) will fail with EINVAL if we pass too many groups. */
1275 /* No group list, just make sure we are setting the efective GID. */
1277 return setgroups(1, &primary_gid);
1280 /* If the primary gid is not the first array element, grow the array
1281 * and insert it at the front.
1283 if (gidset[0] != primary_gid) {
1284 new_gidset = SMB_MALLOC_ARRAY(gid_t, setlen + 1);
1285 if (new_gidset == NULL) {
1289 memcpy(new_gidset + 1, gidset, (setlen * sizeof(gid_t)));
1290 new_gidset[0] = primary_gid;
1295 DEBUG(3, ("forced to truncate group list from %d to %d\n",
1300 #if defined(HAVE_BROKEN_GETGROUPS)
1301 ret = sys_broken_setgroups(setlen, new_gidset ? new_gidset : gidset);
1303 ret = setgroups(setlen, new_gidset ? new_gidset : gidset);
1308 SAFE_FREE(new_gidset);
1315 #endif /* USE_BSD_SETGROUPS */
1317 /**************************************************************************
1318 Wrapper for getgroups. Deals with broken (int) case.
1319 ****************************************************************************/
1321 int sys_getgroups(int setlen, gid_t *gidset)
1323 #if defined(HAVE_BROKEN_GETGROUPS)
1324 return sys_broken_getgroups(setlen, gidset);
1326 return getgroups(setlen, gidset);
1330 /**************************************************************************
1331 Wrapper for setgroups. Deals with broken (int) case and BSD case.
1332 ****************************************************************************/
1334 int sys_setgroups(gid_t UNUSED(primary_gid), int setlen, gid_t *gidset)
1336 #if !defined(HAVE_SETGROUPS)
1339 #endif /* HAVE_SETGROUPS */
1341 #if defined(USE_BSD_SETGROUPS)
1342 return sys_bsd_setgroups(primary_gid, setlen, gidset);
1343 #elif defined(HAVE_BROKEN_GETGROUPS)
1344 return sys_broken_setgroups(setlen, gidset);
1346 return setgroups(setlen, gidset);
1350 /**************************************************************************
1351 Extract a command into an arg list.
1352 ****************************************************************************/
1354 static char **extract_args(TALLOC_CTX *mem_ctx, const char *command)
1363 if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) {
1364 DEBUG(0, ("talloc failed\n"));
1368 if(!(ptr = strtok_r(trunc_cmd, " \t", &saveptr))) {
1369 TALLOC_FREE(trunc_cmd);
1378 for( argcl = 1; ptr; ptr = strtok_r(NULL, " \t", &saveptr))
1381 TALLOC_FREE(trunc_cmd);
1383 if (!(argl = TALLOC_ARRAY(mem_ctx, char *, argcl + 1))) {
1388 * Now do the extraction.
1391 if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) {
1395 ptr = strtok_r(trunc_cmd, " \t", &saveptr);
1398 if (!(argl[i++] = talloc_strdup(argl, ptr))) {
1402 while((ptr = strtok_r(NULL, " \t", &saveptr)) != NULL) {
1404 if (!(argl[i++] = talloc_strdup(argl, ptr))) {
1410 TALLOC_FREE(trunc_cmd);
1414 DEBUG(0, ("talloc failed\n"));
1415 TALLOC_FREE(trunc_cmd);
1421 /**************************************************************************
1422 Wrapper for popen. Safer as it doesn't search a path.
1423 Modified from the glibc sources.
1424 modified by tridge to return a file descriptor. We must kick our FILE* habit
1425 ****************************************************************************/
1427 typedef struct _popen_list
1431 struct _popen_list *next;
1434 static popen_list *popen_chain;
1436 int sys_popen(const char *command)
1438 int parent_end, child_end;
1440 popen_list *entry = NULL;
1443 if (pipe(pipe_fds) < 0)
1446 parent_end = pipe_fds[0];
1447 child_end = pipe_fds[1];
1454 if((entry = SMB_MALLOC_P(popen_list)) == NULL)
1457 ZERO_STRUCTP(entry);
1460 * Extract the command and args into a NULL terminated array.
1463 if(!(argl = extract_args(NULL, command)))
1466 entry->child_pid = sys_fork();
1468 if (entry->child_pid == -1) {
1472 if (entry->child_pid == 0) {
1478 int child_std_end = STDOUT_FILENO;
1482 if (child_end != child_std_end) {
1483 dup2 (child_end, child_std_end);
1488 * POSIX.2: "popen() shall ensure that any streams from previous
1489 * popen() calls that remain open in the parent process are closed
1490 * in the new child process."
1493 for (p = popen_chain; p; p = p->next)
1496 execv(argl[0], argl);
1507 /* Link into popen_chain. */
1508 entry->next = popen_chain;
1509 popen_chain = entry;
1510 entry->fd = parent_end;
1523 /**************************************************************************
1524 Wrapper for pclose. Modified from the glibc sources.
1525 ****************************************************************************/
1527 int sys_pclose(int fd)
1530 popen_list **ptr = &popen_chain;
1531 popen_list *entry = NULL;
1535 /* Unlink from popen_chain. */
1536 for ( ; *ptr != NULL; ptr = &(*ptr)->next) {
1537 if ((*ptr)->fd == fd) {
1539 *ptr = (*ptr)->next;
1545 if (status < 0 || close(entry->fd) < 0)
1549 * As Samba is catching and eating child process
1550 * exits we don't really care about the child exit
1551 * code, a -1 with errno = ECHILD will do fine for us.
1555 wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0);
1556 } while (wait_pid == -1 && errno == EINTR);
1565 /**************************************************************************
1566 Wrapper for Admin Logs.
1567 ****************************************************************************/
1569 void sys_adminlog(int priority, const char *format_str, ...)
1573 char *msgbuf = NULL;
1575 va_start( ap, format_str );
1576 ret = vasprintf( &msgbuf, format_str, ap );
1582 #if defined(HAVE_SYSLOG)
1583 syslog( priority, "%s", msgbuf );
1585 DEBUG(0,("%s", msgbuf ));
1590 /******** Solaris EA helper function prototypes ********/
1591 #ifdef HAVE_ATTROPEN
1592 #define SOLARIS_ATTRMODE S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP
1593 static int solaris_write_xattr(int attrfd, const char *value, size_t size);
1594 static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size);
1595 static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size);
1596 static int solaris_unlinkat(int attrdirfd, const char *name);
1597 static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode);
1598 static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode);
1601 /**************************************************************************
1602 Wrappers for extented attribute calls. Based on the Linux package with
1603 support for IRIX and (Net|Free)BSD also. Expand as other systems have them.
1604 ****************************************************************************/
1606 ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size)
1608 #if defined(HAVE_GETXATTR)
1609 #ifndef XATTR_ADD_OPT
1610 return getxattr(path, name, value, size);
1613 return getxattr(path, name, value, size, 0, options);
1615 #elif defined(HAVE_GETEA)
1616 return getea(path, name, value, size);
1617 #elif defined(HAVE_EXTATTR_GET_FILE)
1620 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1621 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1622 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1624 * The BSD implementation has a nasty habit of silently truncating
1625 * the returned value to the size of the buffer, so we have to check
1626 * that the buffer is large enough to fit the returned value.
1628 if((retval=extattr_get_file(path, attrnamespace, attrname, NULL, 0)) >= 0) {
1633 if((retval=extattr_get_file(path, attrnamespace, attrname, value, size)) >= 0)
1637 DEBUG(10,("sys_getxattr: extattr_get_file() failed with: %s\n", strerror(errno)));
1639 #elif defined(HAVE_ATTR_GET)
1640 int retval, flags = 0;
1641 int valuelength = (int)size;
1642 char *attrname = strchr(name,'.') + 1;
1644 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1646 retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
1648 return retval ? retval : valuelength;
1649 #elif defined(HAVE_ATTROPEN)
1651 int attrfd = solaris_attropen(path, name, O_RDONLY, 0);
1653 ret = solaris_read_xattr(attrfd, value, size);
1663 ssize_t sys_lgetxattr (const char *path, const char *name, void *value, size_t size)
1665 #if defined(HAVE_LGETXATTR)
1666 return lgetxattr(path, name, value, size);
1667 #elif defined(HAVE_GETXATTR) && defined(XATTR_ADD_OPT)
1668 int options = XATTR_NOFOLLOW;
1669 return getxattr(path, name, value, size, 0, options);
1670 #elif defined(HAVE_LGETEA)
1671 return lgetea(path, name, value, size);
1672 #elif defined(HAVE_EXTATTR_GET_LINK)
1675 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1676 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1677 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1679 if((retval=extattr_get_link(path, attrnamespace, attrname, NULL, 0)) >= 0) {
1684 if((retval=extattr_get_link(path, attrnamespace, attrname, value, size)) >= 0)
1688 DEBUG(10,("sys_lgetxattr: extattr_get_link() failed with: %s\n", strerror(errno)));
1690 #elif defined(HAVE_ATTR_GET)
1691 int retval, flags = ATTR_DONTFOLLOW;
1692 int valuelength = (int)size;
1693 char *attrname = strchr(name,'.') + 1;
1695 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1697 retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
1699 return retval ? retval : valuelength;
1700 #elif defined(HAVE_ATTROPEN)
1702 int attrfd = solaris_attropen(path, name, O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
1704 ret = solaris_read_xattr(attrfd, value, size);
1714 ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
1716 #if defined(HAVE_FGETXATTR)
1717 #ifndef XATTR_ADD_OPT
1718 return fgetxattr(filedes, name, value, size);
1721 return fgetxattr(filedes, name, value, size, 0, options);
1723 #elif defined(HAVE_FGETEA)
1724 return fgetea(filedes, name, value, size);
1725 #elif defined(HAVE_EXTATTR_GET_FD)
1728 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
1729 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
1730 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
1732 if((retval=extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0)) >= 0) {
1737 if((retval=extattr_get_fd(filedes, attrnamespace, attrname, value, size)) >= 0)
1741 DEBUG(10,("sys_fgetxattr: extattr_get_fd() failed with: %s\n", strerror(errno)));
1743 #elif defined(HAVE_ATTR_GETF)
1744 int retval, flags = 0;
1745 int valuelength = (int)size;
1746 char *attrname = strchr(name,'.') + 1;
1748 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
1750 retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
1752 return retval ? retval : valuelength;
1753 #elif defined(HAVE_ATTROPEN)
1755 int attrfd = solaris_openat(filedes, name, O_RDONLY|O_XATTR, 0);
1757 ret = solaris_read_xattr(attrfd, value, size);
1767 #if defined(HAVE_EXTATTR_LIST_FILE)
1769 #define EXTATTR_PREFIX(s) (s), (sizeof((s))-1)
1777 { EXTATTR_NAMESPACE_SYSTEM, EXTATTR_PREFIX("system.") },
1778 { EXTATTR_NAMESPACE_USER, EXTATTR_PREFIX("user.") },
1786 static ssize_t bsd_attr_list (int type, extattr_arg arg, char *list, size_t size)
1788 ssize_t list_size, total_size = 0;
1791 /* Iterate through extattr(2) namespaces */
1792 for(t = 0; t < (sizeof(extattr)/sizeof(extattr[0])); t++) {
1794 #if defined(HAVE_EXTATTR_LIST_FILE)
1796 list_size = extattr_list_file(arg.path, extattr[t].space, list, size);
1799 #if defined(HAVE_EXTATTR_LIST_LINK)
1801 list_size = extattr_list_link(arg.path, extattr[t].space, list, size);
1804 #if defined(HAVE_EXTATTR_LIST_FD)
1806 list_size = extattr_list_fd(arg.filedes, extattr[t].space, list, size);
1813 /* Some error happend. Errno should be set by the previous call */
1819 /* XXX: Call with an empty buffer may be used to calculate
1820 necessary buffer size. Unfortunately, we can't say, how
1821 many attributes were returned, so here is the potential
1822 problem with the emulation.
1825 /* Take the worse case of one char attribute names -
1826 two bytes per name plus one more for sanity.
1828 total_size += list_size + (list_size/2 + 1)*extattr[t].len;
1831 /* Count necessary offset to fit namespace prefixes */
1833 for(i = 0; i < list_size; i += list[i] + 1)
1834 len += extattr[t].len;
1836 total_size += list_size + len;
1837 /* Buffer is too small to fit the results */
1838 if(total_size > size) {
1842 /* Shift results back, so we can prepend prefixes */
1843 buf = (char *)memmove(list + len, list, list_size);
1845 for(i = 0; i < list_size; i += len + 1) {
1847 strncpy(list, extattr[t].name, extattr[t].len + 1);
1848 list += extattr[t].len;
1849 strncpy(list, buf + i + 1, len);
1860 #if defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1861 static char attr_buffer[ATTR_MAX_VALUELEN];
1863 static ssize_t irix_attr_list(const char *path, int filedes, char *list, size_t size, int flags)
1865 int retval = 0, index;
1866 attrlist_cursor_t *cursor = 0;
1868 attrlist_t * al = (attrlist_t *)attr_buffer;
1870 size_t ent_size, left = size;
1875 retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1877 retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1879 for (index = 0; index < al->al_count; index++) {
1880 ae = ATTR_ENTRY(attr_buffer, index);
1881 ent_size = strlen(ae->a_name) + sizeof("user.");
1882 if (left >= ent_size) {
1883 strncpy(bp, "user.", sizeof("user."));
1884 strncat(bp, ae->a_name, ent_size - sizeof("user."));
1892 total_size += ent_size;
1894 if (al->al_more == 0) break;
1901 retval = attr_listf(filedes, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1903 retval = attr_list(path, attr_buffer, ATTR_MAX_VALUELEN, flags, cursor);
1905 for (index = 0; index < al->al_count; index++) {
1906 ae = ATTR_ENTRY(attr_buffer, index);
1907 ent_size = strlen(ae->a_name) + sizeof("system.");
1908 if (left >= ent_size) {
1909 strncpy(bp, "system.", sizeof("system."));
1910 strncat(bp, ae->a_name, ent_size - sizeof("system."));
1918 total_size += ent_size;
1920 if (al->al_more == 0) break;
1923 return (ssize_t)(retval ? retval : total_size);
1928 ssize_t sys_listxattr (const char *path, char *list, size_t size)
1930 #if defined(HAVE_LISTXATTR)
1931 #ifndef XATTR_ADD_OPT
1932 return listxattr(path, list, size);
1935 return listxattr(path, list, size, options);
1937 #elif defined(HAVE_LISTEA)
1938 return listea(path, list, size);
1939 #elif defined(HAVE_EXTATTR_LIST_FILE)
1942 return bsd_attr_list(0, arg, list, size);
1943 #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1944 return irix_attr_list(path, 0, list, size, 0);
1945 #elif defined(HAVE_ATTROPEN)
1947 int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
1948 if (attrdirfd >= 0) {
1949 ret = solaris_list_xattr(attrdirfd, list, size);
1959 ssize_t sys_llistxattr (const char *path, char *list, size_t size)
1961 #if defined(HAVE_LLISTXATTR)
1962 return llistxattr(path, list, size);
1963 #elif defined(HAVE_LISTXATTR) && defined(XATTR_ADD_OPT)
1964 int options = XATTR_NOFOLLOW;
1965 return listxattr(path, list, size, options);
1966 #elif defined(HAVE_LLISTEA)
1967 return llistea(path, list, size);
1968 #elif defined(HAVE_EXTATTR_LIST_LINK)
1971 return bsd_attr_list(1, arg, list, size);
1972 #elif defined(HAVE_ATTR_LIST) && defined(HAVE_SYS_ATTRIBUTES_H)
1973 return irix_attr_list(path, 0, list, size, ATTR_DONTFOLLOW);
1974 #elif defined(HAVE_ATTROPEN)
1976 int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
1977 if (attrdirfd >= 0) {
1978 ret = solaris_list_xattr(attrdirfd, list, size);
1988 ssize_t sys_flistxattr (int filedes, char *list, size_t size)
1990 #if defined(HAVE_FLISTXATTR)
1991 #ifndef XATTR_ADD_OPT
1992 return flistxattr(filedes, list, size);
1995 return flistxattr(filedes, list, size, options);
1997 #elif defined(HAVE_FLISTEA)
1998 return flistea(filedes, list, size);
1999 #elif defined(HAVE_EXTATTR_LIST_FD)
2001 arg.filedes = filedes;
2002 return bsd_attr_list(2, arg, list, size);
2003 #elif defined(HAVE_ATTR_LISTF)
2004 return irix_attr_list(NULL, filedes, list, size, 0);
2005 #elif defined(HAVE_ATTROPEN)
2007 int attrdirfd = solaris_openat(filedes, ".", O_RDONLY|O_XATTR, 0);
2008 if (attrdirfd >= 0) {
2009 ret = solaris_list_xattr(attrdirfd, list, size);
2019 int sys_removexattr (const char *path, const char *name)
2021 #if defined(HAVE_REMOVEXATTR)
2022 #ifndef XATTR_ADD_OPT
2023 return removexattr(path, name);
2026 return removexattr(path, name, options);
2028 #elif defined(HAVE_REMOVEEA)
2029 return removeea(path, name);
2030 #elif defined(HAVE_EXTATTR_DELETE_FILE)
2032 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2033 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2034 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2036 return extattr_delete_file(path, attrnamespace, attrname);
2037 #elif defined(HAVE_ATTR_REMOVE)
2039 char *attrname = strchr(name,'.') + 1;
2041 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2043 return attr_remove(path, attrname, flags);
2044 #elif defined(HAVE_ATTROPEN)
2046 int attrdirfd = solaris_attropen(path, ".", O_RDONLY, 0);
2047 if (attrdirfd >= 0) {
2048 ret = solaris_unlinkat(attrdirfd, name);
2058 int sys_lremovexattr (const char *path, const char *name)
2060 #if defined(HAVE_LREMOVEXATTR)
2061 return lremovexattr(path, name);
2062 #elif defined(HAVE_REMOVEXATTR) && defined(XATTR_ADD_OPT)
2063 int options = XATTR_NOFOLLOW;
2064 return removexattr(path, name, options);
2065 #elif defined(HAVE_LREMOVEEA)
2066 return lremoveea(path, name);
2067 #elif defined(HAVE_EXTATTR_DELETE_LINK)
2069 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2070 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2071 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2073 return extattr_delete_link(path, attrnamespace, attrname);
2074 #elif defined(HAVE_ATTR_REMOVE)
2075 int flags = ATTR_DONTFOLLOW;
2076 char *attrname = strchr(name,'.') + 1;
2078 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2080 return attr_remove(path, attrname, flags);
2081 #elif defined(HAVE_ATTROPEN)
2083 int attrdirfd = solaris_attropen(path, ".", O_RDONLY|AT_SYMLINK_NOFOLLOW, 0);
2084 if (attrdirfd >= 0) {
2085 ret = solaris_unlinkat(attrdirfd, name);
2095 int sys_fremovexattr (int filedes, const char *name)
2097 #if defined(HAVE_FREMOVEXATTR)
2098 #ifndef XATTR_ADD_OPT
2099 return fremovexattr(filedes, name);
2102 return fremovexattr(filedes, name, options);
2104 #elif defined(HAVE_FREMOVEEA)
2105 return fremoveea(filedes, name);
2106 #elif defined(HAVE_EXTATTR_DELETE_FD)
2108 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2109 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2110 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2112 return extattr_delete_fd(filedes, attrnamespace, attrname);
2113 #elif defined(HAVE_ATTR_REMOVEF)
2115 char *attrname = strchr(name,'.') + 1;
2117 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
2119 return attr_removef(filedes, attrname, flags);
2120 #elif defined(HAVE_ATTROPEN)
2122 int attrdirfd = solaris_openat(filedes, ".", O_RDONLY|O_XATTR, 0);
2123 if (attrdirfd >= 0) {
2124 ret = solaris_unlinkat(attrdirfd, name);
2134 int sys_setxattr (const char *path, const char *name, const void *value, size_t size, int flags)
2136 #if defined(HAVE_SETXATTR)
2137 #ifndef XATTR_ADD_OPT
2138 return setxattr(path, name, value, size, flags);
2141 return setxattr(path, name, value, size, 0, options);
2143 #elif defined(HAVE_SETEA)
2144 return setea(path, name, value, size, flags);
2145 #elif defined(HAVE_EXTATTR_SET_FILE)
2148 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2149 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2150 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2152 /* Check attribute existence */
2153 retval = extattr_get_file(path, attrnamespace, attrname, NULL, 0);
2155 /* REPLACE attribute, that doesn't exist */
2156 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2160 /* Ignore other errors */
2163 /* CREATE attribute, that already exists */
2164 if (flags & XATTR_CREATE) {
2170 retval = extattr_set_file(path, attrnamespace, attrname, value, size);
2171 return (retval < 0) ? -1 : 0;
2172 #elif defined(HAVE_ATTR_SET)
2174 char *attrname = strchr(name,'.') + 1;
2176 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2177 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2178 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2180 return attr_set(path, attrname, (const char *)value, size, myflags);
2181 #elif defined(HAVE_ATTROPEN)
2183 int myflags = O_RDWR;
2185 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2186 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2187 attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2189 ret = solaris_write_xattr(attrfd, value, size);
2199 int sys_lsetxattr (const char *path, const char *name, const void *value, size_t size, int flags)
2201 #if defined(HAVE_LSETXATTR)
2202 return lsetxattr(path, name, value, size, flags);
2203 #elif defined(HAVE_SETXATTR) && defined(XATTR_ADD_OPT)
2204 int options = XATTR_NOFOLLOW;
2205 return setxattr(path, name, value, size, 0, options);
2206 #elif defined(LSETEA)
2207 return lsetea(path, name, value, size, flags);
2208 #elif defined(HAVE_EXTATTR_SET_LINK)
2211 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2212 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2213 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2215 /* Check attribute existence */
2216 retval = extattr_get_link(path, attrnamespace, attrname, NULL, 0);
2218 /* REPLACE attribute, that doesn't exist */
2219 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2223 /* Ignore other errors */
2226 /* CREATE attribute, that already exists */
2227 if (flags & XATTR_CREATE) {
2234 retval = extattr_set_link(path, attrnamespace, attrname, value, size);
2235 return (retval < 0) ? -1 : 0;
2236 #elif defined(HAVE_ATTR_SET)
2237 int myflags = ATTR_DONTFOLLOW;
2238 char *attrname = strchr(name,'.') + 1;
2240 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2241 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2242 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2244 return attr_set(path, attrname, (const char *)value, size, myflags);
2245 #elif defined(HAVE_ATTROPEN)
2247 int myflags = O_RDWR | AT_SYMLINK_NOFOLLOW;
2249 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2250 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2251 attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2253 ret = solaris_write_xattr(attrfd, value, size);
2263 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags)
2265 #if defined(HAVE_FSETXATTR)
2266 #ifndef XATTR_ADD_OPT
2267 return fsetxattr(filedes, name, value, size, flags);
2270 return fsetxattr(filedes, name, value, size, 0, options);
2272 #elif defined(HAVE_FSETEA)
2273 return fsetea(filedes, name, value, size, flags);
2274 #elif defined(HAVE_EXTATTR_SET_FD)
2277 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
2278 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
2279 const char *attrname = ((s=strchr_m(name, '.')) == NULL) ? name : s + 1;
2281 /* Check attribute existence */
2282 retval = extattr_get_fd(filedes, attrnamespace, attrname, NULL, 0);
2284 /* REPLACE attribute, that doesn't exist */
2285 if (flags & XATTR_REPLACE && errno == ENOATTR) {
2289 /* Ignore other errors */
2292 /* CREATE attribute, that already exists */
2293 if (flags & XATTR_CREATE) {
2299 retval = extattr_set_fd(filedes, attrnamespace, attrname, value, size);
2300 return (retval < 0) ? -1 : 0;
2301 #elif defined(HAVE_ATTR_SETF)
2303 char *attrname = strchr(name,'.') + 1;
2305 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
2306 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
2307 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
2309 return attr_setf(filedes, attrname, (const char *)value, size, myflags);
2310 #elif defined(HAVE_ATTROPEN)
2312 int myflags = O_RDWR | O_XATTR;
2314 if (flags & XATTR_CREATE) myflags |= O_EXCL;
2315 if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT;
2316 attrfd = solaris_openat(filedes, name, myflags, (mode_t) SOLARIS_ATTRMODE);
2318 ret = solaris_write_xattr(attrfd, value, size);
2328 /**************************************************************************
2329 helper functions for Solaris' EA support
2330 ****************************************************************************/
2331 #ifdef HAVE_ATTROPEN
2332 static ssize_t solaris_read_xattr(int attrfd, void *value, size_t size)
2336 if (fstat(attrfd, &sbuf) == -1) {
2341 /* This is to return the current size of the named extended attribute */
2343 return sbuf.st_size;
2346 /* check size and read xattr */
2347 if (sbuf.st_size > size) {
2352 return read(attrfd, value, sbuf.st_size);
2355 static ssize_t solaris_list_xattr(int attrdirfd, char *list, size_t size)
2360 int newfd = dup(attrdirfd);
2361 /* CAUTION: The originating file descriptor should not be
2362 used again following the call to fdopendir().
2363 For that reason we dup() the file descriptor
2364 here to make things more clear. */
2365 dirp = fdopendir(newfd);
2367 while ((de = readdir(dirp))) {
2368 size_t listlen = strlen(de->d_name);
2369 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")) {
2370 /* we don't want "." and ".." here: */
2371 DEBUG(10,("skipped EA %s\n",de->d_name));
2376 /* return the current size of the list of extended attribute names*/
2379 /* check size and copy entrieѕ + nul into list. */
2380 if ((len + listlen + 1) > size) {
2385 safe_strcpy(list + len, de->d_name, listlen);
2393 if (closedir(dirp) == -1) {
2394 DEBUG(0,("closedir dirp failed: %s\n",strerror(errno)));
2400 static int solaris_unlinkat(int attrdirfd, const char *name)
2402 if (unlinkat(attrdirfd, name, 0) == -1) {
2403 if (errno == ENOENT) {
2411 static int solaris_attropen(const char *path, const char *attrpath, int oflag, mode_t mode)
2413 int filedes = attropen(path, attrpath, oflag, mode);
2414 if (filedes == -1) {
2415 DEBUG(10,("attropen FAILED: path: %s, name: %s, errno: %s\n",path,attrpath,strerror(errno)));
2416 if (errno == EINVAL) {
2425 static int solaris_openat(int fildes, const char *path, int oflag, mode_t mode)
2427 int filedes = openat(fildes, path, oflag, mode);
2428 if (filedes == -1) {
2429 DEBUG(10,("openat FAILED: fd: %d, path: %s, errno: %s\n",filedes,path,strerror(errno)));
2430 if (errno == EINVAL) {
2439 static int solaris_write_xattr(int attrfd, const char *value, size_t size)
2441 if ((ftruncate(attrfd, 0) == 0) && (write(attrfd, value, size) == size)) {
2444 DEBUG(10,("solaris_write_xattr FAILED!\n"));
2448 #endif /*HAVE_ATTROPEN*/
2451 /****************************************************************************
2452 Return the major devicenumber for UNIX extensions.
2453 ****************************************************************************/
2455 uint32 unix_dev_major(SMB_DEV_T dev)
2457 #if defined(HAVE_DEVICE_MAJOR_FN)
2458 return (uint32)major(dev);
2460 return (uint32)(dev >> 8);
2464 /****************************************************************************
2465 Return the minor devicenumber for UNIX extensions.
2466 ****************************************************************************/
2468 uint32 unix_dev_minor(SMB_DEV_T dev)
2470 #if defined(HAVE_DEVICE_MINOR_FN)
2471 return (uint32)minor(dev);
2473 return (uint32)(dev & 0xff);
2477 #if defined(WITH_AIO)
2479 /*******************************************************************
2480 An aio_read wrapper that will deal with 64-bit sizes.
2481 ********************************************************************/
2483 int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
2485 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_READ64)
2486 return aio_read64(aiocb);
2487 #elif defined(HAVE_AIO_READ)
2488 return aio_read(aiocb);
2495 /*******************************************************************
2496 An aio_write wrapper that will deal with 64-bit sizes.
2497 ********************************************************************/
2499 int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
2501 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_WRITE64)
2502 return aio_write64(aiocb);
2503 #elif defined(HAVE_AIO_WRITE)
2504 return aio_write(aiocb);
2511 /*******************************************************************
2512 An aio_return wrapper that will deal with 64-bit sizes.
2513 ********************************************************************/
2515 ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
2517 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_RETURN64)
2518 return aio_return64(aiocb);
2519 #elif defined(HAVE_AIO_RETURN)
2520 return aio_return(aiocb);
2527 /*******************************************************************
2528 An aio_cancel wrapper that will deal with 64-bit sizes.
2529 ********************************************************************/
2531 int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
2533 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_CANCEL64)
2534 return aio_cancel64(fd, aiocb);
2535 #elif defined(HAVE_AIO_CANCEL)
2536 return aio_cancel(fd, aiocb);
2543 /*******************************************************************
2544 An aio_error wrapper that will deal with 64-bit sizes.
2545 ********************************************************************/
2547 int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
2549 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_ERROR64)
2550 return aio_error64(aiocb);
2551 #elif defined(HAVE_AIO_ERROR)
2552 return aio_error(aiocb);
2559 /*******************************************************************
2560 An aio_fsync wrapper that will deal with 64-bit sizes.
2561 ********************************************************************/
2563 int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
2565 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_FSYNC64)
2566 return aio_fsync64(op, aiocb);
2567 #elif defined(HAVE_AIO_FSYNC)
2568 return aio_fsync(op, aiocb);
2575 /*******************************************************************
2576 An aio_fsync wrapper that will deal with 64-bit sizes.
2577 ********************************************************************/
2579 int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
2581 #if defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_AIOCB64) && defined(HAVE_AIO_SUSPEND64)
2582 return aio_suspend64(cblist, n, timeout);
2583 #elif defined(HAVE_AIO_FSYNC)
2584 return aio_suspend(cblist, n, timeout);
2590 #else /* !WITH_AIO */
2592 int sys_aio_read(SMB_STRUCT_AIOCB *aiocb)
2598 int sys_aio_write(SMB_STRUCT_AIOCB *aiocb)
2604 ssize_t sys_aio_return(SMB_STRUCT_AIOCB *aiocb)
2610 int sys_aio_cancel(int fd, SMB_STRUCT_AIOCB *aiocb)
2616 int sys_aio_error(const SMB_STRUCT_AIOCB *aiocb)
2622 int sys_aio_fsync(int op, SMB_STRUCT_AIOCB *aiocb)
2628 int sys_aio_suspend(const SMB_STRUCT_AIOCB * const cblist[], int n, const struct timespec *timeout)
2633 #endif /* WITH_AIO */
2635 int sys_getpeereid( int s, uid_t *uid)
2637 #if defined(HAVE_PEERCRED)
2639 socklen_t cred_len = sizeof(struct ucred);
2642 ret = getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void *)&cred, &cred_len);
2647 if (cred_len != sizeof(struct ucred)) {
2655 #if defined(HAVE_GETPEEREID)
2657 return getpeereid(s, uid, &gid);
2664 int sys_getnameinfo(const struct sockaddr *psa,
2673 * For Solaris we must make sure salen is the
2674 * correct length for the incoming sa_family.
2677 if (salen == sizeof(struct sockaddr_storage)) {
2678 salen = sizeof(struct sockaddr_in);
2679 #if defined(HAVE_IPV6)
2680 if (psa->sa_family == AF_INET6) {
2681 salen = sizeof(struct sockaddr_in6);
2685 return getnameinfo(psa, salen, host, hostlen, service, servlen, flags);
2688 int sys_connect(int fd, const struct sockaddr * addr)
2690 socklen_t salen = (socklen_t)-1;
2692 if (addr->sa_family == AF_INET) {
2693 salen = sizeof(struct sockaddr_in);
2694 } else if (addr->sa_family == AF_UNIX) {
2695 salen = sizeof(struct sockaddr_un);
2697 #if defined(HAVE_IPV6)
2698 else if (addr->sa_family == AF_INET6) {
2699 salen = sizeof(struct sockaddr_in6);
2703 return connect(fd, addr, salen);