diff options
author | sjg <sjg@FreeBSD.org> | 2013-04-12 20:48:55 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2013-04-12 20:48:55 +0000 |
commit | 97d8b9495668afa398ab17c8c5f7e223b5fd2e89 (patch) | |
tree | 54038c9ac32a45f8741dcc23fb9a8ffc0e15ff89 /lib | |
parent | 5ee3bfdb338e7c80af29a67f4425c4be24c7b866 (diff) | |
parent | 086d73aef6d0ab7d21daa2076fdc8d25961f9b05 (diff) | |
download | FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.zip FreeBSD-src-97d8b9495668afa398ab17c8c5f7e223b5fd2e89.tar.gz |
sync from head
Diffstat (limited to 'lib')
145 files changed, 5162 insertions, 5409 deletions
diff --git a/lib/Makefile b/lib/Makefile index 1447002..8846164 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -82,6 +82,7 @@ SUBDIR= ${SUBDIR_ORDERED} \ ${_libipx} \ libjail \ libkiconv \ + ${_libldns} \ liblzma \ libmagic \ libmandoc \ @@ -118,6 +119,7 @@ SUBDIR= ${SUBDIR_ORDERED} \ ${_libvmmapi} \ libwrap \ liby \ + libyaml \ libz \ ${_atf} \ ${_bind} \ @@ -177,6 +179,10 @@ _libiconv_modules= libiconv_modules _libipx= libipx .endif +.if ${MK_LDNS} != "no" +_libldns= libldns +.endif + .if ${MK_LIBCPLUSPLUS} != "no" _libcxxrt= libcxxrt _libcplusplus= libc++ diff --git a/lib/bind/config.h b/lib/bind/config.h index 5e9d74b..bf6f8ce 100644 --- a/lib/bind/config.h +++ b/lib/bind/config.h @@ -286,9 +286,6 @@ int sigwait(const unsigned int *set, int *sig); /* Define if your OpenSSL version supports GOST. */ /* #undef HAVE_OPENSSL_GOST */ -/* Define to 1 if you have the <regex.h> header file. */ -#define HAVE_REGEX_H 1 - /* Define to 1 if you have the `setegid' function. */ #define HAVE_SETEGID 1 diff --git a/lib/bind/dns/code.h b/lib/bind/dns/code.h index a451eeb..99944ad 100644 --- a/lib/bind/dns/code.h +++ b/lib/bind/dns/code.h @@ -1,7 +1,7 @@ /* $FreeBSD$ */ /* - * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2013 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2003 Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any diff --git a/lib/bind/dns/dns/enumclass.h b/lib/bind/dns/dns/enumclass.h index 7ee27fe..f9249ec 100644 --- a/lib/bind/dns/dns/enumclass.h +++ b/lib/bind/dns/dns/enumclass.h @@ -1,7 +1,7 @@ /* $FreeBSD$ */ /* - * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2013 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2003 Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any diff --git a/lib/bind/dns/dns/enumtype.h b/lib/bind/dns/dns/enumtype.h index 4c9a2f9..5ab36d1 100644 --- a/lib/bind/dns/dns/enumtype.h +++ b/lib/bind/dns/dns/enumtype.h @@ -1,7 +1,7 @@ /* $FreeBSD$ */ /* - * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2013 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2003 Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any diff --git a/lib/bind/dns/dns/rdatastruct.h b/lib/bind/dns/dns/rdatastruct.h index 9504fa8..10cba31 100644 --- a/lib/bind/dns/dns/rdatastruct.h +++ b/lib/bind/dns/dns/rdatastruct.h @@ -1,7 +1,7 @@ /* $FreeBSD$ */ /* - * Copyright (C) 2004-2012 Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2013 Internet Systems Consortium, Inc. ("ISC") * Copyright (C) 1998-2003 Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any diff --git a/lib/clang/clang.build.mk b/lib/clang/clang.build.mk index 0015e3d..6de044a 100644 --- a/lib/clang/clang.build.mk +++ b/lib/clang/clang.build.mk @@ -19,7 +19,15 @@ CFLAGS+= -fno-strict-aliasing TARGET_ARCH?= ${MACHINE_ARCH} BUILD_ARCH?= ${MACHINE_ARCH} -TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/}-unknown-freebsd10.0 + +.if (${TARGET_ARCH} == "arm" || ${TARGET_ARCH} == "armv6") && \ + ${MK_ARM_EABI} != "no" +TARGET_ABI= gnueabi +.else +TARGET_ABI= unknown +.endif + +TARGET_TRIPLE?= ${TARGET_ARCH:C/amd64/x86_64/}-${TARGET_ABI}-freebsd10.0 BUILD_TRIPLE?= ${BUILD_ARCH:C/amd64/x86_64/}-unknown-freebsd10.0 CFLAGS+= -DLLVM_DEFAULT_TARGET_TRIPLE=\"${TARGET_TRIPLE}\" \ -DLLVM_HOSTTRIPLE=\"${BUILD_TRIPLE}\" \ diff --git a/lib/libarchive/Makefile b/lib/libarchive/Makefile index 73b3c22..ac85bba 100644 --- a/lib/libarchive/Makefile +++ b/lib/libarchive/Makefile @@ -55,6 +55,7 @@ INCS= archive.h archive_entry.h # Sources to be compiled. SRCS= archive_acl.c \ archive_check_magic.c \ + archive_cmdline.c \ archive_crypto.c \ archive_entry.c \ archive_entry_copy_stat.c \ @@ -70,6 +71,7 @@ SRCS= archive_acl.c \ archive_ppmd7.c \ archive_rb.c \ archive_read.c \ + archive_read_append_filter.c \ archive_read_data_into_fd.c \ archive_read_disk_entry_from_file.c \ archive_read_disk_posix.c \ @@ -79,11 +81,15 @@ SRCS= archive_acl.c \ archive_read_open_file.c \ archive_read_open_filename.c \ archive_read_open_memory.c \ + archive_read_set_format.c \ archive_read_set_options.c \ archive_read_support_filter_all.c \ archive_read_support_filter_bzip2.c \ archive_read_support_filter_compress.c \ archive_read_support_filter_gzip.c \ + archive_read_support_filter_grzip.c \ + archive_read_support_filter_lrzip.c \ + archive_read_support_filter_lzop.c \ archive_read_support_filter_none.c \ archive_read_support_filter_program.c \ archive_read_support_filter_rpm.c \ @@ -117,11 +123,17 @@ SRCS= archive_acl.c \ archive_write_open_file.c \ archive_write_open_filename.c \ archive_write_open_memory.c \ + archive_write_add_filter_b64encode.c \ + archive_write_add_filter_by_name.c \ archive_write_add_filter_bzip2.c \ archive_write_add_filter_compress.c \ + archive_write_add_filter_grzip.c \ archive_write_add_filter_gzip.c \ + archive_write_add_filter_lrzip.c \ + archive_write_add_filter_lzop.c \ archive_write_add_filter_none.c \ archive_write_add_filter_program.c \ + archive_write_add_filter_uuencode.c \ archive_write_add_filter_xz.c \ archive_write_set_format.c \ archive_write_set_format_7zip.c \ @@ -135,10 +147,11 @@ SRCS= archive_acl.c \ archive_write_set_format_pax.c \ archive_write_set_format_shar.c \ archive_write_set_format_ustar.c \ + archive_write_set_format_v7tar.c \ archive_write_set_format_xar.c \ archive_write_set_format_zip.c \ archive_write_set_options.c \ - filter_fork.c + filter_fork_posix.c # Man pages to be installed. MAN= archive_entry.3 \ @@ -174,6 +187,7 @@ MAN= archive_entry.3 \ archive_write_set_options.3 \ cpio.5 \ libarchive.3 \ + libarchive_changes.3 \ libarchive_internals.3 \ libarchive-formats.5 \ tar.5 @@ -382,6 +396,7 @@ MLINKS+= archive_write_format.3 archive_write_set_format_shar.3 MLINKS+= archive_write_format.3 archive_write_set_format_shar_dump.3 MLINKS+= archive_write_format.3 archive_write_set_format_ustar.3 MLINKS+= archive_write_free.3 archive_write_close.3 +MLINKS+= archive_write_free.3 archive_write_fail.3 MLINKS+= archive_write_free.3 archive_write_finish.3 MLINKS+= archive_write_open.3 archive_write_open_FILE.3 MLINKS+= archive_write_open.3 archive_write_open_fd.3 diff --git a/lib/libarchive/config_freebsd.h b/lib/libarchive/config_freebsd.h index 214ffd1..bcbad16 100644 --- a/lib/libarchive/config_freebsd.h +++ b/lib/libarchive/config_freebsd.h @@ -47,6 +47,8 @@ #endif #ifdef WITH_OPENSSL +#define HAVE_LIBCRYPTO 1 +#define HAVE_OPENSSL_EVP_H 1 #define HAVE_OPENSSL_MD5_H 1 #define HAVE_OPENSSL_RIPEMD_H 1 #define HAVE_OPENSSL_SHA_H 1 @@ -57,8 +59,10 @@ #define HAVE_SHA384 1 #define HAVE_SHA512 1 #else +#define HAVE_LIBMD 1 #define HAVE_MD5_H 1 #define HAVE_MD5INIT 1 +#define HAVE_RIPEMD_H 1 #define HAVE_SHA_H 1 #define HAVE_SHA1 1 #define HAVE_SHA1_INIT 1 @@ -144,6 +148,7 @@ #define HAVE_PIPE 1 #define HAVE_POLL 1 #define HAVE_POLL_H 1 +#define HAVE_POSIX_SPAWNP 1 #define HAVE_PWD_H 1 #define HAVE_READDIR_R 1 #define HAVE_READLINK 1 @@ -154,6 +159,7 @@ #define HAVE_SETLOCALE 1 #define HAVE_SIGACTION 1 #define HAVE_SIGNAL_H 1 +#define HAVE_SPAWN_H 1 #define HAVE_STATFS 1 #define HAVE_STATVFS 1 #define HAVE_STDARG_H 1 diff --git a/lib/libarchive/test/Makefile b/lib/libarchive/test/Makefile index 5e7c7a4..4ec21f9 100644 --- a/lib/libarchive/test/Makefile +++ b/lib/libarchive/test/Makefile @@ -10,7 +10,8 @@ DPADD=${LIBBZ2} ${LIBZ} ${LIBMD} ${LIBCRYPTO} ${LIBBSDXML} LDADD= -L ${.OBJDIR}/.. -larchive LDADD+= -lz -lbz2 -llzma -lmd -lcrypto -lbsdxml CFLAGS+= -g -CFLAGS+= -I${.CURDIR}/.. -I${LIBARCHIVEDIR}/libarchive -I${.OBJDIR} +CFLAGS+= -I${.CURDIR}/.. -I${.OBJDIR} +CFLAGS+= -I${LIBARCHIVEDIR}/libarchive -I${LIBARCHIVEDIR}/test_utils CFLAGS+= -DHAVE_LIBLZMA=1 -DHAVE_LZMA_H=1 # Uncomment to link against dmalloc @@ -26,6 +27,7 @@ TESTS= \ test_acl_posix1e.c \ test_archive_api_feature.c \ test_archive_clear_error.c \ + test_archive_cmdline.c \ test_archive_crypto.c \ test_archive_getdate.c \ test_archive_match_time.c \ @@ -35,6 +37,7 @@ TESTS= \ test_archive_read_close_twice.c \ test_archive_read_close_twice_open_fd.c \ test_archive_read_close_twice_open_filename.c \ + test_archive_read_multiple_data_objects.c \ test_archive_read_next_header_empty.c \ test_archive_read_next_header_raw.c \ test_archive_read_open2.c \ @@ -46,7 +49,9 @@ TESTS= \ test_archive_set_error.c \ test_archive_string.c \ test_archive_string_conversion.c \ + test_archive_write_add_filter_by_name.c \ test_archive_write_set_filter_option.c \ + test_archive_write_set_format_by_name.c \ test_archive_write_set_format_option.c \ test_archive_write_set_option.c \ test_archive_write_set_options.c \ @@ -57,11 +62,13 @@ TESTS= \ test_compat_gzip.c \ test_compat_lzip.c \ test_compat_lzma.c \ + test_compat_lzop.c \ test_compat_mac.c \ test_compat_pax_libarchive_2x.c \ test_compat_solaris_tar_acl.c \ test_compat_solaris_pax_sparse.c \ test_compat_tar_hardlink.c \ + test_compat_uudecode.c \ test_compat_xz.c \ test_compat_zip.c \ test_empty_write.c \ @@ -77,13 +84,19 @@ TESTS= \ test_open_file.c \ test_open_filename.c \ test_pax_filename_encoding.c \ - test_read_compress_program.c \ test_read_data_large.c \ test_read_disk.c \ test_read_disk_directory_traversals.c \ test_read_disk_entry_from_file.c \ test_read_extract.c \ test_read_file_nonexistent.c \ + test_read_filter_grzip.c \ + test_read_filter_lrzip.c \ + test_read_filter_lzop.c \ + test_read_filter_lzop_multiple_parts.c \ + test_read_filter_program.c \ + test_read_filter_program_signature.c \ + test_read_filter_uudecode.c \ test_read_format_7zip.c \ test_read_format_ar.c \ test_read_format_cab.c \ @@ -137,35 +150,49 @@ TESTS= \ test_read_format_ustar_filename.c \ test_read_format_xar.c \ test_read_format_zip.c \ + test_read_format_zip_comment_stored.c \ test_read_format_zip_filename.c \ + test_read_format_zip_mac_metadata.c \ + test_read_format_zip_sfx.c \ test_read_large.c \ test_read_pax_truncated.c \ test_read_position.c \ + test_read_set_format.c \ test_read_truncated.c \ test_read_truncated_filter.c \ - test_read_uu.c \ test_sparse_basic.c \ test_tar_filenames.c \ test_tar_large.c \ test_ustar_filenames.c \ test_ustar_filename_encoding.c \ - test_write_compress.c \ - test_write_compress_bzip2.c \ - test_write_compress_gzip.c \ - test_write_compress_lzip.c \ - test_write_compress_lzma.c \ - test_write_compress_program.c \ - test_write_compress_xz.c \ test_write_disk.c \ + test_write_disk_appledouble.c \ test_write_disk_failures.c \ test_write_disk_hardlink.c \ + test_write_disk_hfs_compression.c \ test_write_disk_lookup.c \ + test_write_disk_mac_metadata.c \ + test_write_disk_no_hfs_compression.c \ test_write_disk_perms.c \ test_write_disk_secure.c \ test_write_disk_sparse.c \ test_write_disk_symlink.c \ test_write_disk_times.c \ + test_write_filter_b64encode.c \ + test_write_filter_bzip2.c \ + test_write_filter_compress.c \ + test_write_filter_gzip.c \ + test_write_filter_gzip_timestamp.c \ + test_write_filter_lrzip.c \ + test_write_filter_lzip.c \ + test_write_filter_lzma.c \ + test_write_filter_lzop.c \ + test_write_filter_program.c \ + test_write_filter_uuencode.c \ + test_write_filter_xz.c \ test_write_format_7zip.c \ + test_write_format_7zip_empty.c \ + test_write_format_7zip_large.c \ test_write_format_ar.c \ test_write_format_cpio.c \ test_write_format_cpio_empty.c \ @@ -178,18 +205,25 @@ TESTS= \ test_write_format_iso9660_filename.c \ test_write_format_iso9660_zisofs.c \ test_write_format_mtree.c \ + test_write_format_mtree_absolute_path.c \ + test_write_format_mtree_classic.c \ + test_write_format_mtree_classic_indent.c \ test_write_format_mtree_fflags.c \ + test_write_format_mtree_no_separator.c \ + test_write_format_mtree_quoted_filename.c \ test_write_format_pax.c \ test_write_format_shar_empty.c \ test_write_format_tar.c \ test_write_format_tar_empty.c \ test_write_format_tar_sparse.c \ test_write_format_tar_ustar.c \ + test_write_format_tar_v7tar.c \ test_write_format_xar.c \ test_write_format_xar_empty.c \ test_write_format_zip.c \ test_write_format_zip_empty.c \ test_write_format_zip_no_compression.c \ + test_write_zip_set_compression_store.c \ test_write_open_memory.c \ test_zip_filename_encoding.c @@ -200,6 +234,9 @@ SRCS= \ main.c \ read_open_memory.c +.PATH: ${LIBARCHIVEDIR}/test_utils +SRCS+= test_utils.c + # Build libarchive_test and run it. check test: libarchive_test ./libarchive_test -r ${LIBARCHIVEDIR}/libarchive/test diff --git a/lib/libc/arm/aeabi/Makefile.inc b/lib/libc/arm/aeabi/Makefile.inc index ac147c0..379eb23 100644 --- a/lib/libc/arm/aeabi/Makefile.inc +++ b/lib/libc/arm/aeabi/Makefile.inc @@ -7,5 +7,24 @@ SRCS+= aeabi_atexit.c \ aeabi_float.c \ aeabi_unwind_cpp.c +# Add the aeabi_mem* functions. While they live in compiler-rt they call into +# libc. This causes issues when other parts of libc call these functions. +# We work around this by including these functions in libc but mark them as +# hidden so users of libc will not pick up these versions. +.PATH: ${.CURDIR}/../../contrib/compiler-rt/lib/arm + +SRCS+= aeabi_memcmp.S \ + aeabi_memcpy.S \ + aeabi_memmove.S \ + aeabi_memset.S + +# Mark the functions as hidden so they are not available outside of libc. +CFLAGS.aeabi_memcmp.S= -DVISIBILITY_HIDDEN +CFLAGS.aeabi_memcpy.S= -DVISIBILITY_HIDDEN +CFLAGS.aeabi_memmove.S= -DVISIBILITY_HIDDEN +CFLAGS.aeabi_memset.S= -DVISIBILITY_HIDDEN +CFLAGS+= ${CFLAGS.${.IMPSRC:T}} + + SYM_MAPS+=${.CURDIR}/arm/aeabi/Symbol.map diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 0bbbb33..fac1e43 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -4,37 +4,145 @@ # machine-independent gen sources .PATH: ${.CURDIR}/${LIBC_ARCH}/gen ${.CURDIR}/gen -SRCS+= __getosreldate.c __xuname.c \ - _once_stub.c _pthread_stubs.c _rand48.c _spinlock_stub.c \ +SRCS+= __getosreldate.c \ + __xuname.c \ + _once_stub.c \ + _pthread_stubs.c \ + _rand48.c \ + _spinlock_stub.c \ _thread_init.c \ - alarm.c arc4random.c assert.c auxv.c basename.c check_utility_compat.c \ - clock.c clock_getcpuclockid.c closedir.c confstr.c \ - crypt.c ctermid.c daemon.c devname.c dirfd.c dirname.c disklabel.c \ - dlfcn.c drand48.c elf_utils.c erand48.c err.c errlst.c errno.c \ - exec.c fdevname.c feature_present.c fmtcheck.c fmtmsg.c fnmatch.c \ - fpclassify.c frexp.c fstab.c ftok.c fts.c fts-compat.c ftw.c \ - getbootfile.c getbsize.c \ - getcap.c getcwd.c getdomainname.c getgrent.c getgrouplist.c \ - gethostname.c getloadavg.c getlogin.c getmntinfo.c getnetgrent.c \ - getosreldate.c getpagesize.c getpagesizes.c \ - getpeereid.c getprogname.c getpwent.c getttyent.c \ - getusershell.c getutxent.c getvfsbyname.c glob.c \ - initgroups.c isatty.c isinf.c isnan.c jrand48.c lcong48.c \ + alarm.c \ + arc4random.c \ + assert.c \ + auxv.c \ + basename.c \ + cap_sandboxed.c \ + check_utility_compat.c \ + clock.c \ + clock_getcpuclockid.c \ + closedir.c \ + confstr.c \ + crypt.c \ + ctermid.c \ + daemon.c \ + devname.c \ + dirfd.c \ + dirname.c \ + disklabel.c \ + dlfcn.c \ + drand48.c \ + elf_utils.c \ + erand48.c \ + err.c \ + errlst.c \ + errno.c \ + exec.c \ + fdevname.c \ + feature_present.c \ + fmtcheck.c \ + fmtmsg.c \ + fnmatch.c \ + fpclassify.c \ + frexp.c \ + fstab.c \ + ftok.c \ + fts.c \ + fts-compat.c \ + ftw.c \ + getbootfile.c \ + getbsize.c \ + getcap.c \ + getcwd.c \ + getdomainname.c \ + getgrent.c \ + getgrouplist.c \ + gethostname.c \ + getloadavg.c \ + getlogin.c \ + getmntinfo.c \ + getnetgrent.c \ + getosreldate.c \ + getpagesize.c \ + getpagesizes.c \ + getpeereid.c \ + getprogname.c \ + getpwent.c \ + getttyent.c \ + getusershell.c \ + getutxent.c \ + getvfsbyname.c \ + glob.c \ + initgroups.c \ + isatty.c \ + isinf.c \ + isnan.c \ + jrand48.c \ + lcong48.c \ libc_dlopen.c \ - lockf.c lrand48.c mrand48.c nftw.c nice.c \ - nlist.c nrand48.c opendir.c \ - pause.c pmadvise.c popen.c posix_spawn.c \ - psignal.c pututxline.c pw_scan.c \ - raise.c readdir.c readpassphrase.c rewinddir.c \ - scandir.c seed48.c seekdir.c semctl.c \ - setdomainname.c sethostname.c setjmperr.c setmode.c \ - setproctitle.c setprogname.c siginterrupt.c siglist.c signal.c \ - sigsetops.c sleep.c srand48.c statvfs.c stringlist.c strtofflags.c \ - sysconf.c sysctl.c sysctlbyname.c sysctlnametomib.c \ - syslog.c telldir.c termios.c time.c times.c timezone.c tls.c \ - ttyname.c ttyslot.c ualarm.c ulimit.c uname.c unvis-compat.c \ - usleep.c utime.c utxdb.c valloc.c wait.c wait3.c waitpid.c \ - waitid.c wordexp.c + lockf.c \ + lrand48.c \ + mrand48.c \ + nftw.c \ + nice.c \ + nlist.c \ + nrand48.c \ + opendir.c \ + pause.c \ + pmadvise.c \ + popen.c \ + posix_spawn.c \ + psignal.c \ + pututxline.c \ + pw_scan.c \ + raise.c \ + readdir.c \ + readpassphrase.c \ + rewinddir.c \ + scandir.c \ + seed48.c \ + seekdir.c \ + semctl.c \ + setdomainname.c \ + sethostname.c \ + setjmperr.c \ + setmode.c \ + setproctitle.c \ + setprogname.c \ + siginterrupt.c \ + siglist.c \ + signal.c \ + sigsetops.c \ + sleep.c \ + srand48.c \ + statvfs.c \ + stringlist.c \ + strtofflags.c \ + sysconf.c \ + sysctl.c \ + sysctlbyname.c \ + sysctlnametomib.c \ + syslog.c \ + telldir.c \ + termios.c \ + time.c \ + times.c \ + timezone.c \ + tls.c \ + ttyname.c \ + ttyslot.c \ + ualarm.c \ + ulimit.c \ + uname.c \ + unvis-compat.c \ + usleep.c \ + utime.c \ + utxdb.c \ + valloc.c \ + wait.c \ + wait3.c \ + waitpid.c \ + waitid.c \ + wordexp.c .PATH: ${.CURDIR}/../../contrib/libc-pwcache SRCS+= pwcache.c pwcache.h @@ -58,101 +166,259 @@ SYM_MAPS+=${.CURDIR}/gen/Symbol.map # machine-dependent gen sources .sinclude "${.CURDIR}/${LIBC_ARCH}/gen/Makefile.inc" -MAN+= alarm.3 arc4random.3 \ - basename.3 check_utility_compat.3 clock.3 clock_getcpuclockid.3 \ - confstr.3 ctermid.3 daemon.3 devname.3 directory.3 dirname.3 \ - dl_iterate_phdr.3 dladdr.3 dlinfo.3 dllockinit.3 dlopen.3 \ - err.3 exec.3 \ - feature_present.3 fmtcheck.3 fmtmsg.3 fnmatch.3 fpclassify.3 frexp.3 \ - ftok.3 fts.3 ftw.3 \ - getbootfile.3 getbsize.3 getcap.3 getcontext.3 getcwd.3 \ - getdiskbyname.3 getdomainname.3 getfsent.3 \ - getgrent.3 getgrouplist.3 gethostname.3 getloadavg.3 \ - getmntinfo.3 getnetgrent.3 getosreldate.3 getpagesize.3 \ - getpagesizes.3 getpass.3 getpeereid.3 getprogname.3 getpwent.3 \ - getttyent.3 getusershell.3 getutxent.3 getvfsbyname.3 \ - glob.3 initgroups.3 isgreater.3 ldexp.3 lockf.3 makecontext.3 \ +MAN+= alarm.3 \ + arc4random.3 \ + basename.3 \ + cap_sandboxed.3 \ + check_utility_compat.3 \ + clock.3 \ + clock_getcpuclockid.3 \ + confstr.3 \ + ctermid.3 \ + daemon.3 \ + devname.3 \ + directory.3 \ + dirname.3 \ + dl_iterate_phdr.3 \ + dladdr.3 \ + dlinfo.3 \ + dllockinit.3 \ + dlopen.3 \ + err.3 \ + exec.3 \ + feature_present.3 \ + fmtcheck.3 \ + fmtmsg.3 \ + fnmatch.3 \ + fpclassify.3 \ + frexp.3 \ + ftok.3 \ + fts.3 \ + ftw.3 \ + getbootfile.3 \ + getbsize.3 \ + getcap.3 \ + getcontext.3 \ + getcwd.3 \ + getdiskbyname.3 \ + getdomainname.3 \ + getfsent.3 \ + getgrent.3 \ + getgrouplist.3 \ + gethostname.3 \ + getloadavg.3 \ + getmntinfo.3 \ + getnetgrent.3 \ + getosreldate.3 \ + getpagesize.3 \ + getpagesizes.3 \ + getpass.3 \ + getpeereid.3 \ + getprogname.3 \ + getpwent.3 \ + getttyent.3 \ + getusershell.3 \ + getutxent.3 \ + getvfsbyname.3 \ + glob.3 \ + initgroups.3 \ + isgreater.3 \ + ldexp.3 \ + lockf.3 \ + makecontext.3 \ modf.3 \ - nice.3 nlist.3 pause.3 popen.3 \ - posix_spawn.3 posix_spawn_file_actions_addopen.3 \ - posix_spawn_file_actions_init.3 posix_spawnattr_getflags.3 \ - posix_spawnattr_getpgroup.3 posix_spawnattr_getschedparam.3 \ - posix_spawnattr_getschedpolicy.3 posix_spawnattr_init.3 \ - posix_spawnattr_getsigdefault.3 posix_spawnattr_getsigmask.3 \ - psignal.3 pwcache.3 \ - raise.3 rand48.3 readpassphrase.3 rfork_thread.3 \ - scandir.3 sem_destroy.3 sem_getvalue.3 sem_init.3 \ - sem_open.3 sem_post.3 sem_timedwait.3 sem_wait.3 \ - setjmp.3 setmode.3 setproctitle.3 \ - siginterrupt.3 signal.3 sigsetops.3 sleep.3 \ - statvfs.3 stringlist.3 \ - strtofflags.3 sysconf.3 sysctl.3 syslog.3 tcgetpgrp.3 tcgetsid.3 \ - tcsendbreak.3 tcsetattr.3 tcsetpgrp.3 tcsetsid.3 time.3 times.3 \ - timezone.3 ttyname.3 tzset.3 ualarm.3 ucontext.3 ulimit.3 uname.3 \ - unvis.3 usleep.3 utime.3 valloc.3 vis.3 wordexp.3 + nice.3 \ + nlist.3 \ + pause.3 \ + popen.3 \ + posix_spawn.3 \ + posix_spawn_file_actions_addopen.3 \ + posix_spawn_file_actions_init.3 \ + posix_spawnattr_getflags.3 \ + posix_spawnattr_getpgroup.3 \ + posix_spawnattr_getschedparam.3 \ + posix_spawnattr_getschedpolicy.3 \ + posix_spawnattr_init.3 \ + posix_spawnattr_getsigdefault.3 \ + posix_spawnattr_getsigmask.3 \ + psignal.3 \ + pwcache.3 \ + raise.3 \ + rand48.3 \ + readpassphrase.3 \ + rfork_thread.3 \ + scandir.3 \ + sem_destroy.3 \ + sem_getvalue.3 \ + sem_init.3 \ + sem_open.3 \ + sem_post.3 \ + sem_timedwait.3 \ + sem_wait.3 \ + setjmp.3 \ + setmode.3 \ + setproctitle.3 \ + siginterrupt.3 \ + signal.3 \ + sigsetops.3 \ + sleep.3 \ + statvfs.3 \ + stringlist.3 \ + strtofflags.3 \ + sysconf.3 \ + sysctl.3 \ + syslog.3 \ + tcgetpgrp.3 \ + tcgetsid.3 \ + tcsendbreak.3 \ + tcsetattr.3 \ + tcsetpgrp.3 \ + tcsetsid.3 \ + time.3 \ + times.3 \ + timezone.3 \ + ttyname.3 \ + tzset.3 \ + ualarm.3 \ + ucontext.3 \ + ulimit.3 \ + uname.3 \ + unvis.3 \ + usleep.3 \ + utime.3 \ + valloc.3 \ + vis.3 \ + wordexp.3 -MLINKS+=arc4random.3 arc4random_addrandom.3 arc4random.3 arc4random_stir.3 \ - arc4random.3 arc4random_buf.3 arc4random.3 arc4random_uniform.3 +MLINKS+=arc4random.3 arc4random_addrandom.3 \ + arc4random.3 arc4random_stir.3 \ + arc4random.3 arc4random_buf.3 \ + arc4random.3 arc4random_uniform.3 MLINKS+=basename.3 basename_r.3 MLINKS+=ctermid.3 ctermid_r.3 MLINKS+=devname.3 devname_r.3 MLINKS+=devname.3 fdevname.3 MLINKS+=devname.3 fdevname_r.3 -MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \ +MLINKS+=directory.3 closedir.3 \ + directory.3 dirfd.3 \ + directory.3 opendir.3 \ directory.3 fdopendir.3 \ - directory.3 readdir.3 directory.3 readdir_r.3 directory.3 rewinddir.3 \ - directory.3 seekdir.3 directory.3 telldir.3 -MLINKS+=dlopen.3 fdlopen.3 dlopen.3 dlclose.3 dlopen.3 dlerror.3 \ - dlopen.3 dlfunc.3 dlopen.3 dlsym.3 -MLINKS+=err.3 err_set_exit.3 err.3 err_set_file.3 err.3 errc.3 err.3 errx.3 \ - err.3 verr.3 err.3 verrc.3 err.3 verrx.3 err.3 vwarn.3 err.3 vwarnc.3 \ - err.3 vwarnx.3 err.3 warnc.3 err.3 warn.3 err.3 warnx.3 -MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 exect.3 \ - exec.3 execv.3 exec.3 execvP.3 exec.3 execvp.3 -MLINKS+=fpclassify.3 finite.3 fpclassify.3 finitef.3 \ - fpclassify.3 isfinite.3 fpclassify.3 isinf.3 fpclassify.3 isnan.3 \ + directory.3 readdir.3 \ + directory.3 readdir_r.3 \ + directory.3 rewinddir.3 \ + directory.3 seekdir.3 \ + directory.3 telldir.3 +MLINKS+=dlopen.3 fdlopen.3 \ + dlopen.3 dlclose.3 \ + dlopen.3 dlerror.3 \ + dlopen.3 dlfunc.3 \ + dlopen.3 dlsym.3 +MLINKS+=err.3 err_set_exit.3 \ + err.3 err_set_file.3 \ + err.3 errc.3 \ + err.3 errx.3 \ + err.3 verr.3 \ + err.3 verrc.3 \ + err.3 verrx.3 \ + err.3 vwarn.3 \ + err.3 vwarnc.3 \ + err.3 vwarnx.3 \ + err.3 warnc.3 \ + err.3 warn.3 \ + err.3 warnx.3 +MLINKS+=exec.3 execl.3 \ + exec.3 execle.3 \ + exec.3 execlp.3 \ + exec.3 exect.3 \ + exec.3 execv.3 \ + exec.3 execvP.3 \ + exec.3 execvp.3 +MLINKS+=fpclassify.3 finite.3 \ + fpclassify.3 finitef.3 \ + fpclassify.3 isfinite.3 \ + fpclassify.3 isinf.3 \ + fpclassify.3 isnan.3 \ fpclassify.3 isnormal.3 -MLINKS+=frexp.3 frexpf.3 frexp.3 frexpl.3 -MLINKS+=fts.3 fts_children.3 fts.3 fts_close.3 fts.3 fts_open.3 \ - fts.3 fts_read.3 fts.3 fts_set.3 fts.3 fts_set_clientptr.3 \ - fts.3 fts_get_clientptr.3 fts.3 fts_get_stream.3 +MLINKS+=frexp.3 frexpf.3 \ + frexp.3 frexpl.3 +MLINKS+=fts.3 fts_children.3 \ + fts.3 fts_close.3 \ + fts.3 fts_open.3 \ + fts.3 fts_read.3 \ + fts.3 fts_set.3 \ + fts.3 fts_set_clientptr.3 \ + fts.3 fts_get_clientptr.3 \ + fts.3 fts_get_stream.3 MLINKS+=ftw.3 nftw.3 -MLINKS+=getcap.3 cgetcap.3 getcap.3 cgetclose.3 getcap.3 cgetent.3 \ - getcap.3 cgetfirst.3 getcap.3 cgetmatch.3 getcap.3 cgetnext.3 \ - getcap.3 cgetnum.3 getcap.3 cgetset.3 getcap.3 cgetstr.3 \ +MLINKS+=getcap.3 cgetcap.3 \ + getcap.3 cgetclose.3 \ + getcap.3 cgetent.3 \ + getcap.3 cgetfirst.3 \ + getcap.3 cgetmatch.3 \ + getcap.3 cgetnext.3 \ + getcap.3 cgetnum.3 \ + getcap.3 cgetset.3 \ + getcap.3 cgetstr.3 \ getcap.3 cgetustr.3 MLINKS+=getcwd.3 getwd.3 +MLINKS+=getcontext.3 getcontextx.3 MLINKS+=getcontext.3 setcontext.3 MLINKS+=getdomainname.3 setdomainname.3 -MLINKS+=getfsent.3 endfsent.3 getfsent.3 getfsfile.3 getfsent.3 getfsspec.3 \ - getfsent.3 getfstype.3 getfsent.3 setfsent.3 \ - getfsent.3 setfstab.3 getfsent.3 getfstab.3 -MLINKS+=getgrent.3 endgrent.3 getgrent.3 getgrgid.3 getgrent.3 getgrnam.3 \ - getgrent.3 setgrent.3 getgrent.3 setgroupent.3 \ - getgrent.3 getgrent_r.3 getgrent.3 getgrnam_r.3 getgrent.3 getgrgid_r.3 +MLINKS+=getfsent.3 endfsent.3 \ + getfsent.3 getfsfile.3 \ + getfsent.3 getfsspec.3 \ + getfsent.3 getfstype.3 \ + getfsent.3 setfsent.3 \ + getfsent.3 setfstab.3 \ + getfsent.3 getfstab.3 +MLINKS+=getgrent.3 endgrent.3 \ + getgrent.3 getgrgid.3 \ + getgrent.3 getgrnam.3 \ + getgrent.3 setgrent.3 \ + getgrent.3 setgroupent.3 \ + getgrent.3 getgrent_r.3 \ + getgrent.3 getgrnam_r.3 \ + getgrent.3 getgrgid_r.3 MLINKS+=gethostname.3 sethostname.3 -MLINKS+=getnetgrent.3 endnetgrent.3 getnetgrent.3 innetgr.3 \ +MLINKS+=getnetgrent.3 endnetgrent.3 \ + getnetgrent.3 innetgr.3 \ getnetgrent.3 setnetgrent.3 MLINKS+=getprogname.3 setprogname.3 -MLINKS+=getpwent.3 endpwent.3 getpwent.3 getpwnam.3 getpwent.3 getpwuid.3 \ - getpwent.3 setpassent.3 getpwent.3 setpwent.3 getpwent.3 setpwfile.3 \ - getpwent.3 getpwent_r.3 getpwent.3 getpwnam_r.3 \ +MLINKS+=getpwent.3 endpwent.3 \ + getpwent.3 getpwnam.3 \ + getpwent.3 getpwuid.3 \ + getpwent.3 setpassent.3 \ + getpwent.3 setpwent.3 \ + getpwent.3 setpwfile.3 \ + getpwent.3 getpwent_r.3 \ + getpwent.3 getpwnam_r.3 \ getpwent.3 getpwuid_r.3 -MLINKS+=getttyent.3 endttyent.3 getttyent.3 getttynam.3 \ - getttyent.3 isdialuptty.3 getttyent.3 isnettty.3 \ +MLINKS+=getttyent.3 endttyent.3 \ + getttyent.3 getttynam.3 \ + getttyent.3 isdialuptty.3 \ + getttyent.3 isnettty.3 \ getttyent.3 setttyent.3 -MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3 -MLINKS+=getutxent.3 endutxent.3 getutxent.3 getutxid.3 \ - getutxent.3 getutxline.3 getutxent.3 getutxuser.3 \ - getutxent.3 pututxline.3 getutxent.3 setutxdb.3 \ - getutxent.3 setutxent.3 getutxent.3 utmpx.3 +MLINKS+=getusershell.3 endusershell.3 \ + getusershell.3 setusershell.3 +MLINKS+=getutxent.3 endutxent.3 \ + getutxent.3 getutxid.3 \ + getutxent.3 getutxline.3 \ + getutxent.3 getutxuser.3 \ + getutxent.3 pututxline.3 \ + getutxent.3 setutxdb.3 \ + getutxent.3 setutxent.3 \ + getutxent.3 utmpx.3 MLINKS+=glob.3 globfree.3 -MLINKS+=isgreater.3 isgreaterequal.3 isgreater.3 isless.3 \ - isgreater.3 islessequal.3 isgreater.3 islessgreater.3 \ +MLINKS+=isgreater.3 isgreaterequal.3 \ + isgreater.3 isless.3 \ + isgreater.3 islessequal.3 \ + isgreater.3 islessgreater.3 \ isgreater.3 isunordered.3 -MLINKS+=ldexp.3 ldexpf.3 ldexp.3 ldexpl.3 +MLINKS+=ldexp.3 ldexpf.3 \ + ldexp.3 ldexpl.3 MLINKS+=makecontext.3 swapcontext.3 -MLINKS+=modf.3 modff.3 modf.3 modfl.3 +MLINKS+=modf.3 modff.3 \ + modf.3 modfl.3 MLINKS+=popen.3 pclose.3 MLINKS+=posix_spawn.3 posix_spawnp.3 \ posix_spawn_file_actions_addopen.3 posix_spawn_file_actions_addclose.3 \ @@ -165,36 +431,80 @@ MLINKS+=posix_spawn.3 posix_spawnp.3 \ posix_spawnattr_getsigdefault.3 posix_spawnattr_setsigdefault.3 \ posix_spawnattr_getsigmask.3 posix_spawnattr_setsigmask.3 \ posix_spawnattr_init.3 posix_spawnattr_destroy.3 -MLINKS+=psignal.3 strsignal.3 psignal.3 sys_siglist.3 psignal.3 sys_signame.3 -MLINKS+=pwcache.3 group_from_gid.3 pwcache.3 user_from_uid.3 -MLINKS+=rand48.3 _rand48.3 rand48.3 drand48.3 rand48.3 erand48.3 \ - rand48.3 jrand48.3 rand48.3 lcong48.3 rand48.3 lrand48.3 \ - rand48.3 mrand48.3 rand48.3 nrand48.3 rand48.3 seed48.3 \ +MLINKS+=psignal.3 strsignal.3 \ + psignal.3 sys_siglist.3 \ + psignal.3 sys_signame.3 +MLINKS+=pwcache.3 group_from_gid.3 \ + pwcache.3 user_from_uid.3 +MLINKS+=rand48.3 _rand48.3 \ + rand48.3 drand48.3 \ + rand48.3 erand48.3 \ + rand48.3 jrand48.3 \ + rand48.3 lcong48.3 \ + rand48.3 lrand48.3 \ + rand48.3 mrand48.3 \ + rand48.3 nrand48.3 \ + rand48.3 seed48.3 \ rand48.3 srand48.3 MLINKS+=scandir.3 alphasort.3 -MLINKS+=sem_open.3 sem_close.3 sem_open.3 sem_unlink.3 +MLINKS+=sem_open.3 sem_close.3 \ + sem_open.3 sem_unlink.3 MLINKS+=sem_wait.3 sem_trywait.3 -MLINKS+=setjmp.3 _longjmp.3 setjmp.3 _setjmp.3 setjmp.3 longjmp.3 \ - setjmp.3 longjmperr.3 setjmp.3 longjmperror.3 \ - setjmp.3 siglongjmp.3 setjmp.3 sigsetjmp.3 +MLINKS+=setjmp.3 _longjmp.3 \ + setjmp.3 _setjmp.3 \ + setjmp.3 longjmp.3 \ + setjmp.3 longjmperr.3 \ + setjmp.3 longjmperror.3 \ + setjmp.3 siglongjmp.3 \ + setjmp.3 sigsetjmp.3 MLINKS+=setmode.3 getmode.3 -MLINKS+=sigsetops.3 sigaddset.3 sigsetops.3 sigdelset.3 \ - sigsetops.3 sigemptyset.3 sigsetops.3 sigfillset.3 \ +MLINKS+=sigsetops.3 sigaddset.3 \ + sigsetops.3 sigdelset.3 \ + sigsetops.3 sigemptyset.3 \ + sigsetops.3 sigfillset.3 \ sigsetops.3 sigismember.3 MLINKS+=statvfs.3 fstatvfs.3 -MLINKS+=stringlist.3 sl_add.3 stringlist.3 sl_find.3 \ - stringlist.3 sl_free.3 stringlist.3 sl_init.3 +MLINKS+=stringlist.3 sl_add.3 \ + stringlist.3 sl_find.3 \ + stringlist.3 sl_free.3 \ + stringlist.3 sl_init.3 MLINKS+=strtofflags.3 fflagstostr.3 -MLINKS+=sysctl.3 sysctlbyname.3 sysctl.3 sysctlnametomib.3 -MLINKS+=syslog.3 closelog.3 syslog.3 openlog.3 syslog.3 setlogmask.3 \ +MLINKS+=sysctl.3 sysctlbyname.3 \ + sysctl.3 sysctlnametomib.3 +MLINKS+=syslog.3 closelog.3 \ + syslog.3 openlog.3 \ + syslog.3 setlogmask.3 \ syslog.3 vsyslog.3 -MLINKS+=tcsendbreak.3 tcdrain.3 tcsendbreak.3 tcflow.3 tcsendbreak.3 tcflush.3 -MLINKS+=tcsetattr.3 cfgetispeed.3 tcsetattr.3 cfgetospeed.3 \ - tcsetattr.3 cfmakeraw.3 tcsetattr.3 cfmakesane.3 \ - tcsetattr.3 cfsetispeed.3 tcsetattr.3 cfsetospeed.3 \ - tcsetattr.3 cfsetspeed.3 tcsetattr.3 tcgetattr.3 -MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyname_r.3 +MLINKS+=tcsendbreak.3 tcdrain.3 \ + tcsendbreak.3 tcflow.3 \ + tcsendbreak.3 tcflush.3 +MLINKS+=tcsetattr.3 cfgetispeed.3 \ + tcsetattr.3 cfgetospeed.3 \ + tcsetattr.3 cfmakeraw.3 \ + tcsetattr.3 cfmakesane.3 \ + tcsetattr.3 cfsetispeed.3 \ + tcsetattr.3 cfsetospeed.3 \ + tcsetattr.3 cfsetspeed.3 \ + tcsetattr.3 tcgetattr.3 +MLINKS+=ttyname.3 isatty.3 \ + ttyname.3 ttyname_r.3 MLINKS+=tzset.3 tzsetwall.3 -MLINKS+=unvis.3 strunvis.3 unvis.3 strunvisx.3 -MLINKS+=vis.3 strvis.3 vis.3 strvisx.3 +MLINKS+=unvis.3 strunvis.3 \ + unvis.3 strunvisx.3 +MLINKS+=vis.3 nvis.3 \ + vis.3 snvis.3 \ + vis.3 strenvisx.3 \ + vis.3 strnunvis.3 \ + vis.3 strnunvisx.3 \ + vis.3 strnvis.3 \ + vis.3 strnvisx.3 \ + vis.3 strsenvisx.3 \ + vis.3 strsnvis.3 \ + vis.3 strsnvisx.3 \ + vis.3 strsvis.3 \ + vis.3 strsvisx.3 \ + vis.3 strvis.3 \ + vis.3 strvisx.3 \ + vis.3 svis.3 + MLINKS+=wordexp.3 wordfree.3 diff --git a/lib/libc/gen/Symbol.map b/lib/libc/gen/Symbol.map index 4cbf07c..2438951 100644 --- a/lib/libc/gen/Symbol.map +++ b/lib/libc/gen/Symbol.map @@ -391,10 +391,12 @@ FBSD_1.3 { pwcache_userdb; pwcache_groupdb; snvis; + strenvisx; strnunvis; strnunvisx; strnvis; strnvisx; + strsenvisx; strsnvis; strsnvisx; strsvis; diff --git a/lib/libc/gen/cap_sandboxed.3 b/lib/libc/gen/cap_sandboxed.3 new file mode 100644 index 0000000..067d6d2 --- /dev/null +++ b/lib/libc/gen/cap_sandboxed.3 @@ -0,0 +1,70 @@ +.\" Copyright (c) 2012 The FreeBSD Foundation +.\" All rights reserved. +.\" +.\" This documentation was written by Pawel Jakub Dawidek under sponsorship +.\" from the FreeBSD Foundation. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 18, 2012 +.Dt CAP_SANDBOXED 3 +.Os +.Sh NAME +.Nm cap_sandboxed +.Nd Check if in a capability mode sandbox +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/capability.h +.In stdbool.h +.Ft bool +.Fn cap_sandboxed "void" +.Sh DESCRIPTION +.Fn cap_sandboxed +returns +.Va true +if the process is in a capability mode sandbox or +.Va false +if it is not. +This function is a more handy alternative to the +.Xr cap_getmode 2 +system call as it always succeeds, so there is no need for error checking. +If the support for capability mode is not compiled into the kernel, +.Fn cap_sandboxed +will always return +.Va false . +.Sh RETURN VALUES +Function +.Fn cap_sandboxed +is always successful and will return either +.Va true +or +.Va false . +.Sh SEE ALSO +.Xr cap_enter 2 , +.Xr capsicum 4 +.Sh AUTHORS +This function was implemented and manual page was written by +.An Pawel Jakub Dawidek Aq pawel@dawidek.net +under sponsorship of the FreeBSD Foundation. diff --git a/lib/libc/gen/cap_sandboxed.c b/lib/libc/gen/cap_sandboxed.c new file mode 100644 index 0000000..baa9b3f --- /dev/null +++ b/lib/libc/gen/cap_sandboxed.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2012 The FreeBSD Foundation + * All rights reserved. + * + * This software was developed by Pawel Jakub Dawidek under sponsorship from + * the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <sys/capability.h> + +#include <assert.h> +#include <errno.h> +#include <stdbool.h> + +bool +cap_sandboxed(void) +{ + u_int mode; + + if (cap_getmode(&mode) != 0) { + assert(errno == ENOSYS); + return (false); + } + assert(mode == 0 || mode == 1); + return (mode == 1); +} diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 243320c..d15be06 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -1119,7 +1119,8 @@ fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path) newfd = fd; if (ISSET(FTS_NOCHDIR)) return (0); - if (fd < 0 && (newfd = _open(path, O_RDONLY | O_CLOEXEC, 0)) < 0) + if (fd < 0 && (newfd = _open(path, O_RDONLY | O_DIRECTORY | + O_CLOEXEC, 0)) < 0) return (-1); if (_fstat(newfd, &sb)) { ret = -1; diff --git a/lib/libc/gen/getcontext.3 b/lib/libc/gen/getcontext.3 index 5b801fd..9e3e4fc 100644 --- a/lib/libc/gen/getcontext.3 +++ b/lib/libc/gen/getcontext.3 @@ -35,7 +35,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 26, 2011 +.Dd March 13, 2013 .Dt GETCONTEXT 3 .Os .Sh NAME @@ -47,6 +47,8 @@ .In ucontext.h .Ft int .Fn getcontext "ucontext_t *ucp" +.Ft ucontext_t * +.Fn getcontextx "void" .Ft int .Fn setcontext "const ucontext_t *ucp" .Sh DESCRIPTION diff --git a/lib/libc/gen/glob.c b/lib/libc/gen/glob.c index 832dc8d..95a3a06 100644 --- a/lib/libc/gen/glob.c +++ b/lib/libc/gen/glob.c @@ -738,7 +738,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last, /* - * Extend the gl_pathv member of a glob_t structure to accomodate a new item, + * Extend the gl_pathv member of a glob_t structure to accommodate a new item, * add the new item, and update gl_pathc. * * This assumes the BSD realloc, which only copies the block when its size diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 2d505fc..a9eb0af 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -49,7 +49,7 @@ __FBSDID("$FreeBSD$"); #include "gen-private.h" #include "telldir.h" -static DIR * __opendir_common(int, const char *, int); +static DIR * __opendir_common(int, int); /* * Open a directory. @@ -78,7 +78,7 @@ fdopendir(int fd) } if (_fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) return (NULL); - return (__opendir_common(fd, NULL, DTF_HIDEW|DTF_NODUP)); + return (__opendir_common(fd, DTF_HIDEW|DTF_NODUP)); } DIR * @@ -92,7 +92,7 @@ __opendir2(const char *name, int flags) O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC)) == -1) return (NULL); - dir = __opendir_common(fd, name, flags); + dir = __opendir_common(fd, flags); if (dir == NULL) { saved_errno = errno; _close(fd); @@ -113,7 +113,7 @@ opendir_compar(const void *p1, const void *p2) * Common routine for opendir(3), __opendir2(3) and fdopendir(3). */ static DIR * -__opendir_common(int fd, const char *name, int flags) +__opendir_common(int fd, int flags) { DIR *dirp; int incr; @@ -121,6 +121,8 @@ __opendir_common(int fd, const char *name, int flags) int unionstack; int fd2; + fd2 = -1; + if ((dirp = malloc(sizeof(DIR) + sizeof(struct _telldir))) == NULL) return (NULL); @@ -165,7 +167,22 @@ __opendir_common(int fd, const char *name, int flags) * entries into a buffer, sort the buffer, and * remove duplicate entries by setting the inode * number to zero. + * + * We reopen the directory because _getdirentries() + * on a MNT_UNION mount modifies the open directory, + * making it refer to the lower directory after the + * upper directory's entries are exhausted. + * This would otherwise break software that uses + * the directory descriptor for fchdir or *at + * functions, such as fts.c. */ + if ((fd2 = _openat(fd, ".", O_RDONLY | O_CLOEXEC)) == -1) { + saved_errno = errno; + free(buf); + free(dirp); + errno = saved_errno; + return (NULL); + } do { /* @@ -181,7 +198,7 @@ __opendir_common(int fd, const char *name, int flags) ddptr = buf + (len - space); } - n = _getdirentries(fd, ddptr, space, &dirp->dd_seek); + n = _getdirentries(fd2, ddptr, space, &dirp->dd_seek); if (n > 0) { ddptr += n; space -= n; @@ -191,25 +208,8 @@ __opendir_common(int fd, const char *name, int flags) ddeptr = ddptr; flags |= __DTF_READALL; - /* - * Re-open the directory. - * This has the effect of rewinding back to the - * top of the union stack and is needed by - * programs which plan to fchdir to a descriptor - * which has also been read -- see fts.c. - */ - if (flags & DTF_REWIND) { - if ((fd2 = _open(name, O_RDONLY | O_DIRECTORY | - O_CLOEXEC)) == -1) { - saved_errno = errno; - free(buf); - free(dirp); - errno = saved_errno; - return (NULL); - } - (void)_dup2(fd2, fd); - _close(fd2); - } + _close(fd2); + fd2 = -1; /* * There is now a buffer full of (possibly) duplicate @@ -293,7 +293,6 @@ __opendir_common(int fd, const char *name, int flags) if (dirp->dd_buf == NULL) goto fail; dirp->dd_seek = 0; - flags &= ~DTF_REWIND; } dirp->dd_loc = 0; @@ -310,6 +309,8 @@ __opendir_common(int fd, const char *name, int flags) fail: saved_errno = errno; + if (fd2 != -1) + _close(fd2); free(dirp); errno = saved_errno; return (NULL); diff --git a/lib/libc/gen/sem_new.c b/lib/libc/gen/sem_new.c index b11d547..1bf84ea 100644 --- a/lib/libc/gen/sem_new.c +++ b/lib/libc/gen/sem_new.c @@ -198,15 +198,11 @@ _sem_open(const char *name, int flags, ...) goto error; } - fd = _open(path, flags|O_RDWR|O_CLOEXEC, mode); + fd = _open(path, flags|O_RDWR|O_CLOEXEC|O_EXLOCK, mode); if (fd == -1) goto error; - if (flock(fd, LOCK_EX) == -1) + if (_fstat(fd, &sb)) goto error; - if (_fstat(fd, &sb)) { - flock(fd, LOCK_UN); - goto error; - } if (sb.st_size < sizeof(sem_t)) { sem_t tmp; @@ -214,10 +210,8 @@ _sem_open(const char *name, int flags, ...) tmp._kern._has_waiters = 0; tmp._kern._count = value; tmp._kern._flags = USYNC_PROCESS_SHARED | SEM_NAMED; - if (_write(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) { - flock(fd, LOCK_UN); + if (_write(fd, &tmp, sizeof(tmp)) != sizeof(tmp)) goto error; - } } flock(fd, LOCK_UN); sem = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ|PROT_WRITE, @@ -235,18 +229,18 @@ _sem_open(const char *name, int flags, ...) ni->open_count = 1; ni->sem = sem; LIST_INSERT_HEAD(&sem_list, ni, next); - _pthread_mutex_unlock(&sem_llock); _close(fd); + _pthread_mutex_unlock(&sem_llock); return (sem); error: errsave = errno; - _pthread_mutex_unlock(&sem_llock); if (fd != -1) _close(fd); if (sem != NULL) munmap(sem, sizeof(sem_t)); free(ni); + _pthread_mutex_unlock(&sem_llock); errno = errsave; return (SEM_FAILED); } diff --git a/lib/libc/gen/wordexp.c b/lib/libc/gen/wordexp.c index bcab1f5..b518b57 100644 --- a/lib/libc/gen/wordexp.c +++ b/lib/libc/gen/wordexp.c @@ -114,15 +114,12 @@ we_askshell(const char *words, wordexp_t *we, int flags) int status; /* Child exit status */ int error; /* Our return value */ int serrno; /* errno to return */ - char *ifs; /* IFS env. var. */ char *np, *p; /* Handy pointers */ char *nstrings; /* Temporary for realloc() */ char **nwv; /* Temporary for realloc() */ sigset_t newsigblock, oldsigblock; serrno = errno; - if ((ifs = getenv("IFS")) == NULL) - ifs = " \t\n"; if (pipe(pdes) < 0) return (WRDE_NOSPACE); /* XXX */ @@ -150,7 +147,7 @@ we_askshell(const char *words, wordexp_t *we, int flags) if (_dup2(pdes[1], STDOUT_FILENO) < 0) _exit(1); _close(pdes[1]); - if (asprintf(&cmd, "wordexp%c%s\n", *ifs, words) < 0) + if (asprintf(&cmd, "wordexp %s\n", words) < 0) _exit(1); if ((flags & WRDE_SHOWERR) == 0) { if ((devnull = _open(_PATH_DEVNULL, O_RDWR, 0666)) < 0) diff --git a/lib/libc/include/compat.h b/lib/libc/include/compat.h index 7694540..3739fe1 100644 --- a/lib/libc/include/compat.h +++ b/lib/libc/include/compat.h @@ -42,6 +42,8 @@ __sym_compat(__semctl, freebsd7___semctl, FBSD_1.0); __sym_compat(msgctl, freebsd7_msgctl, FBSD_1.0); __sym_compat(shmctl, freebsd7_shmctl, FBSD_1.0); +__sym_compat(cap_getrights, cap_rights_get, FBSD_1.2); + #undef __sym_compat #endif /* __LIBC_COMPAT_H__ */ diff --git a/lib/libc/locale/btowc.3 b/lib/libc/locale/btowc.3 index d9c3e9c..2d8cb49 100644 --- a/lib/libc/locale/btowc.3 +++ b/lib/libc/locale/btowc.3 @@ -42,9 +42,9 @@ .In wchar.h .In xlocale.h .Ft wint_t -.Fn btowc "int c" +.Fn btowc_l "int c" "locale_t loc" .Ft int -.Fn wctob "wint_t c" +.Fn wctob_l "wint_t c" "locale_t loc" .Sh DESCRIPTION The .Fn btowc diff --git a/lib/libc/locale/isblank.3 b/lib/libc/locale/isblank.3 index 5542280..731a88b 100644 --- a/lib/libc/locale/isblank.3 +++ b/lib/libc/locale/isblank.3 @@ -41,7 +41,7 @@ .Ft int .Fn isblank "int c" .Ft int -.Fn isblank "int c" "locale_t loc" +.Fn isblank_l "int c" "locale_t loc" .Sh DESCRIPTION The .Fn isblank diff --git a/lib/libc/net/getaddrinfo.3 b/lib/libc/net/getaddrinfo.3 index b09c068..3419809 100644 --- a/lib/libc/net/getaddrinfo.3 +++ b/lib/libc/net/getaddrinfo.3 @@ -18,7 +18,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 6, 2009 +.Dd February 14, 2013 .Dt GETADDRINFO 3 .Os .Sh NAME @@ -339,7 +339,7 @@ hints.ai_socktype = SOCK_STREAM; error = getaddrinfo("www.kame.net", "http", &hints, &res0); if (error) { errx(1, "%s", gai_strerror(error)); - /*NOTREACHED*/ + /* NOTREACHED */ } s = -1; for (res = res0; res; res = res->ai_next) { @@ -361,7 +361,7 @@ for (res = res0; res; res = res->ai_next) { } if (s < 0) { err(1, "%s", cause); - /*NOTREACHED*/ + /* NOTREACHED */ } freeaddrinfo(res0); .Ed @@ -383,7 +383,7 @@ hints.ai_flags = AI_PASSIVE; error = getaddrinfo(NULL, "http", &hints, &res0); if (error) { errx(1, "%s", gai_strerror(error)); - /*NOTREACHED*/ + /* NOTREACHED */ } nsock = 0; for (res = res0; res && nsock < MAXSOCK; res = res->ai_next) { @@ -405,7 +405,7 @@ for (res = res0; res && nsock < MAXSOCK; res = res->ai_next) { } if (nsock == 0) { err(1, "%s", cause); - /*NOTREACHED*/ + /* NOTREACHED */ } freeaddrinfo(res0); .Ed diff --git a/lib/libc/net/getnameinfo.3 b/lib/libc/net/getnameinfo.3 index 327c135..e508e5d 100644 --- a/lib/libc/net/getnameinfo.3 +++ b/lib/libc/net/getnameinfo.3 @@ -18,7 +18,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 28, 2007 +.Dd February 14, 2013 .Dt GETNAMEINFO 3 .Os .Sh NAME @@ -157,7 +157,7 @@ char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) { errx(1, "could not get numeric hostname"); - /*NOTREACHED*/ + /* NOTREACHED */ } printf("host=%s, serv=%s\en", hbuf, sbuf); .Ed @@ -170,7 +170,7 @@ char hbuf[NI_MAXHOST]; if (getnameinfo(sa, sa->sa_len, hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD)) { errx(1, "could not resolve hostname"); - /*NOTREACHED*/ + /* NOTREACHED */ } printf("host=%s\en", hbuf); .Ed diff --git a/lib/libc/net/nscachedcli.c b/lib/libc/net/nscachedcli.c index 1323805..b4de0c1 100644 --- a/lib/libc/net/nscachedcli.c +++ b/lib/libc/net/nscachedcli.c @@ -75,9 +75,10 @@ safe_write(struct cached_connection_ *connection, const void *data, nevents = _kevent(connection->write_queue, NULL, 0, &eventlist, 1, &timeout); if ((nevents == 1) && (eventlist.filter == EVFILT_WRITE)) { - s_result = _write(connection->sockfd, data + result, + s_result = _sendto(connection->sockfd, data + result, eventlist.data < data_size - result ? - eventlist.data : data_size - result); + eventlist.data : data_size - result, MSG_NOSIGNAL, + NULL, 0); if (s_result == -1) return (-1); else @@ -175,8 +176,8 @@ send_credentials(struct cached_connection_ *connection, int type) nevents = _kevent(connection->write_queue, NULL, 0, &eventlist, 1, NULL); if (nevents == 1 && eventlist.filter == EVFILT_WRITE) { - result = (_sendmsg(connection->sockfd, &cred_hdr, 0) == -1) ? - -1 : 0; + result = (_sendmsg(connection->sockfd, &cred_hdr, + MSG_NOSIGNAL) == -1) ? -1 : 0; EV_SET(&eventlist, connection->sockfd, EVFILT_WRITE, EV_ADD, 0, 0, NULL); _kevent(connection->write_queue, &eventlist, 1, NULL, 0, NULL); diff --git a/lib/libc/net/sctp_sys_calls.c b/lib/libc/net/sctp_sys_calls.c index beedf94..6b938a4 100644 --- a/lib/libc/net/sctp_sys_calls.c +++ b/lib/libc/net/sctp_sys_calls.c @@ -48,8 +48,6 @@ __FBSDID("$FreeBSD$"); #include <netinet/sctp_uio.h> #include <netinet/sctp.h> -#include <net/if_dl.h> - #ifndef IN6_IS_ADDR_V4MAPPED #define IN6_IS_ADDR_V4MAPPED(a) \ ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ @@ -57,77 +55,8 @@ __FBSDID("$FreeBSD$"); (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff))) #endif - -#define SCTP_CONTROL_VEC_SIZE_SND 8192 #define SCTP_CONTROL_VEC_SIZE_RCV 16384 -#define SCTP_STACK_BUF_SIZE 2048 - -#ifdef SCTP_DEBUG_PRINT_ADDRESS -#define SCTP_STRING_BUF_SZ 256 - -static void -SCTPPrintAnAddress(struct sockaddr *a) -{ - char stringToPrint[SCTP_STRING_BUF_SZ]; - u_short prt; - char *srcaddr, *txt; - - if (a == NULL) { - printf("NULL\n"); - return; - } - if (a->sa_family == AF_INET) { - srcaddr = (char *)&((struct sockaddr_in *)a)->sin_addr; - txt = "IPv4 Address: "; - prt = ntohs(((struct sockaddr_in *)a)->sin_port); - } else if (a->sa_family == AF_INET6) { - srcaddr = (char *)&((struct sockaddr_in6 *)a)->sin6_addr; - prt = ntohs(((struct sockaddr_in6 *)a)->sin6_port); - txt = "IPv6 Address: "; - } else if (a->sa_family == AF_LINK) { - int i; - char tbuf[SCTP_STRING_BUF_SZ]; - u_char adbuf[SCTP_STRING_BUF_SZ]; - struct sockaddr_dl *dl; - - dl = (struct sockaddr_dl *)a; - strncpy(tbuf, dl->sdl_data, dl->sdl_nlen); - tbuf[dl->sdl_nlen] = 0; - printf("Intf:%s (len:%d)Interface index:%d type:%x(%d) ll-len:%d ", - tbuf, - dl->sdl_nlen, - dl->sdl_index, - dl->sdl_type, - dl->sdl_type, - dl->sdl_alen - ); - memcpy(adbuf, LLADDR(dl), dl->sdl_alen); - for (i = 0; i < dl->sdl_alen; i++) { - printf("%2.2x", adbuf[i]); - if (i < (dl->sdl_alen - 1)) - printf(":"); - } - printf("\n"); - return; - } else { - return; - } - if (inet_ntop(a->sa_family, srcaddr, stringToPrint, sizeof(stringToPrint))) { - if (a->sa_family == AF_INET6) { - printf("%s%s:%d scope:%d\n", - txt, stringToPrint, prt, - ((struct sockaddr_in6 *)a)->sin6_scope_id); - } else { - printf("%s%s:%d\n", txt, stringToPrint, prt); - } - - } else { - printf("%s unprintable?\n", txt); - } -} - -#endif /* SCTP_DEBUG_PRINT_ADDRESS */ static void in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6) @@ -171,11 +100,10 @@ int sctp_connectx(int sd, const struct sockaddr *addrs, int addrcnt, sctp_assoc_t * id) { - char buf[SCTP_STACK_BUF_SIZE]; + char *buf; int i, ret, cnt, *aa; char *cpto; const struct sockaddr *at; - sctp_assoc_t *p_id; size_t len = sizeof(int); /* validate the address count and list */ @@ -183,24 +111,29 @@ sctp_connectx(int sd, const struct sockaddr *addrs, int addrcnt, errno = EINVAL; return (-1); } + if ((buf = malloc(sizeof(int) + (size_t)addrcnt * sizeof(struct sockaddr_in6))) == NULL) { + errno = E2BIG; + return (-1); + } at = addrs; cnt = 0; - cpto = ((caddr_t)buf + sizeof(int)); + cpto = buf + sizeof(int); /* validate all the addresses and get the size */ for (i = 0; i < addrcnt; i++) { switch (at->sa_family) { case AF_INET: if (at->sa_len != sizeof(struct sockaddr_in)) { + free(buf); errno = EINVAL; return (-1); } memcpy(cpto, at, sizeof(struct sockaddr_in)); cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in)); len += sizeof(struct sockaddr_in); - at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in)); break; case AF_INET6: if (at->sa_len != sizeof(struct sockaddr_in6)) { + free(buf); errno = EINVAL; return (-1); } @@ -213,31 +146,20 @@ sctp_connectx(int sd, const struct sockaddr *addrs, int addrcnt, cpto = ((caddr_t)cpto + sizeof(struct sockaddr_in6)); len += sizeof(struct sockaddr_in6); } - at = (struct sockaddr *)((caddr_t)at + sizeof(struct sockaddr_in6)); break; default: + free(buf); errno = EINVAL; return (-1); } - if (len > (sizeof(buf) - sizeof(int))) { - /* Never enough memory */ - errno = E2BIG; - return (-1); - } - cnt++; - } - /* do we have any? */ - if (cnt == 0) { - errno = EINVAL; - return (-1); + at = (struct sockaddr *)((caddr_t)at + at->sa_len); } aa = (int *)buf; - *aa = cnt; + *aa = addrcnt; ret = setsockopt(sd, IPPROTO_SCTP, SCTP_CONNECT_X, (void *)buf, (socklen_t) len); - if ((ret == 0) && id) { - p_id = (sctp_assoc_t *) buf; - *id = *p_id; + if ((ret == 0) && (id != NULL)) { + *id = *(sctp_assoc_t *) buf; } return (ret); } @@ -345,7 +267,6 @@ sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags) return (0); } - int sctp_opt_info(int sd, sctp_assoc_t id, int opt, void *arg, socklen_t * size) { @@ -471,9 +392,9 @@ sctp_getpaddrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs) void sctp_freepaddrs(struct sockaddr *addrs) { - /* Take away the hidden association id */ void *fr_addr; + /* Take away the hidden association id */ fr_addr = (void *)((caddr_t)addrs - sizeof(sctp_assoc_t)); /* Now free it */ free(fr_addr); @@ -534,15 +455,14 @@ sctp_getladdrs(int sd, sctp_assoc_t id, struct sockaddr **raddrs) void sctp_freeladdrs(struct sockaddr *addrs) { - /* Take away the hidden association id */ void *fr_addr; + /* Take away the hidden association id */ fr_addr = (void *)((caddr_t)addrs - sizeof(sctp_assoc_t)); /* Now free it */ free(fr_addr); } - ssize_t sctp_sendmsg(int s, const void *data, @@ -568,11 +488,10 @@ sctp_sendmsg(int s, return (syscall(SYS_sctp_generic_sendmsg, s, data, len, to, tolen, &sinfo, 0)); #else - ssize_t sz; struct msghdr msg; - struct sctp_sndrcvinfo *s_info; + struct sctp_sndrcvinfo *sinfo; struct iovec iov; - char controlVector[SCTP_CONTROL_VEC_SIZE_RCV]; + char cmsgbuf[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; struct cmsghdr *cmsg; struct sockaddr *who = NULL; union { @@ -583,36 +502,39 @@ sctp_sendmsg(int s, if ((tolen > 0) && ((to == NULL) || (tolen < sizeof(struct sockaddr)))) { errno = EINVAL; - return -1; + return (-1); } - if (to && (tolen > 0)) { - if (to->sa_family == AF_INET) { + if ((to != NULL) && (tolen > 0)) { + switch (to->sa_family) { + case AF_INET: if (tolen != sizeof(struct sockaddr_in)) { errno = EINVAL; - return -1; + return (-1); } if ((to->sa_len > 0) && (to->sa_len != sizeof(struct sockaddr_in))) { errno = EINVAL; - return -1; + return (-1); } memcpy(&addr, to, sizeof(struct sockaddr_in)); addr.in.sin_len = sizeof(struct sockaddr_in); - } else if (to->sa_family == AF_INET6) { + break; + case AF_INET6: if (tolen != sizeof(struct sockaddr_in6)) { errno = EINVAL; - return -1; + return (-1); } if ((to->sa_len > 0) && (to->sa_len != sizeof(struct sockaddr_in6))) { errno = EINVAL; - return -1; + return (-1); } memcpy(&addr, to, sizeof(struct sockaddr_in6)); addr.in6.sin6_len = sizeof(struct sockaddr_in6); - } else { + break; + default: errno = EAFNOSUPPORT; - return -1; + return (-1); } who = (struct sockaddr *)&addr; } @@ -628,26 +550,21 @@ sctp_sendmsg(int s, } msg.msg_iov = &iov; msg.msg_iovlen = 1; - msg.msg_control = (caddr_t)controlVector; - - cmsg = (struct cmsghdr *)controlVector; - + msg.msg_control = cmsgbuf; + msg.msg_controllen = CMSG_SPACE(sizeof(struct sctp_sndrcvinfo)); + cmsg = (struct cmsghdr *)cmsgbuf; cmsg->cmsg_level = IPPROTO_SCTP; cmsg->cmsg_type = SCTP_SNDRCV; cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); - s_info = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); - - s_info->sinfo_stream = stream_no; - s_info->sinfo_ssn = 0; - s_info->sinfo_flags = flags; - s_info->sinfo_ppid = ppid; - s_info->sinfo_context = context; - s_info->sinfo_assoc_id = 0; - s_info->sinfo_timetolive = timetolive; - errno = 0; - msg.msg_controllen = cmsg->cmsg_len; - sz = sendmsg(s, &msg, 0); - return (sz); + sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); + sinfo->sinfo_stream = stream_no; + sinfo->sinfo_ssn = 0; + sinfo->sinfo_flags = flags; + sinfo->sinfo_ppid = ppid; + sinfo->sinfo_context = context; + sinfo->sinfo_assoc_id = 0; + sinfo->sinfo_timetolive = timetolive; + return (sendmsg(s, &msg, 0)); #endif } @@ -662,12 +579,11 @@ sctp_getassocid(int sd, struct sockaddr *sa) siz = sizeof(sp); memset(&sp, 0, sizeof(sp)); memcpy((caddr_t)&sp.spinfo_address, sa, sa->sa_len); - errno = 0; if (getsockopt(sd, IPPROTO_SCTP, SCTP_GET_PEER_ADDR_INFO, &sp, &siz) != 0) { + /* We depend on the fact that 0 can never be returned */ return ((sctp_assoc_t) 0); } - /* We depend on the fact that 0 can never be returned */ return (sp.spinfo_assoc_id); } @@ -683,11 +599,9 @@ sctp_send(int sd, const void *data, size_t len, return (syscall(SYS_sctp_generic_sendmsg, sd, data, len, to, 0, sinfo, flags)); #else - ssize_t sz; struct msghdr msg; struct iovec iov; - struct sctp_sndrcvinfo *s_info; - char controlVector[SCTP_CONTROL_VEC_SIZE_SND]; + char cmsgbuf[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; struct cmsghdr *cmsg; if (sinfo == NULL) { @@ -697,24 +611,18 @@ sctp_send(int sd, const void *data, size_t len, iov.iov_base = (char *)data; iov.iov_len = len; - msg.msg_name = 0; + msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = &iov; msg.msg_iovlen = 1; - msg.msg_control = (caddr_t)controlVector; - - cmsg = (struct cmsghdr *)controlVector; - + msg.msg_control = cmsgbuf; + msg.msg_controllen = CMSG_SPACE(sizeof(struct sctp_sndrcvinfo)); + cmsg = (struct cmsghdr *)cmsgbuf; cmsg->cmsg_level = IPPROTO_SCTP; cmsg->cmsg_type = SCTP_SNDRCV; cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); - s_info = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); - /* copy in the data */ - *s_info = *sinfo; - errno = 0; - msg.msg_controllen = cmsg->cmsg_len; - sz = sendmsg(sd, &msg, flags); - return (sz); + memcpy(CMSG_DATA(cmsg), sinfo, sizeof(struct sctp_sndrcvinfo)); + return (sendmsg(sd, &msg, flags)); #endif } @@ -836,7 +744,7 @@ sctp_sendmsgx(int sd, sinfo.sinfo_ssn = stream_no; sinfo.sinfo_timetolive = timetolive; sinfo.sinfo_context = context; - return sctp_sendx(sd, msg, len, addrs, addrcnt, &sinfo, 0); + return (sctp_sendx(sd, msg, len, addrs, addrcnt, &sinfo, 0)); } ssize_t @@ -856,11 +764,10 @@ sctp_recvmsg(int s, return (syscall(SYS_sctp_generic_recvmsg, s, &iov, 1, from, fromlen, sinfo, msg_flags)); #else - struct sctp_sndrcvinfo *s_info; ssize_t sz; struct msghdr msg; struct iovec iov; - char controlVector[SCTP_CONTROL_VEC_SIZE_RCV]; + char cmsgbuf[SCTP_CONTROL_VEC_SIZE_RCV]; struct cmsghdr *cmsg; if (msg_flags == NULL) { @@ -877,52 +784,38 @@ sctp_recvmsg(int s, msg.msg_namelen = *fromlen; msg.msg_iov = &iov; msg.msg_iovlen = 1; - msg.msg_control = (caddr_t)controlVector; - msg.msg_controllen = sizeof(controlVector); - errno = 0; + msg.msg_control = cmsgbuf; + msg.msg_controllen = sizeof(cmsgbuf); sz = recvmsg(s, &msg, *msg_flags); *msg_flags = msg.msg_flags; if (sz <= 0) { return (sz); } - s_info = NULL; if (sinfo) { sinfo->sinfo_assoc_id = 0; } - if ((msg.msg_controllen) && sinfo) { + if ((msg.msg_controllen > 0) && (sinfo != NULL)) { /* * parse through and see if we find the sctp_sndrcvinfo (if * the user wants it). */ - cmsg = (struct cmsghdr *)controlVector; - while (cmsg) { - if ((cmsg->cmsg_len == 0) || (cmsg->cmsg_len > msg.msg_controllen)) { + for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) { + if (cmsg->cmsg_level != IPPROTO_SCTP) { + continue; + } + if (cmsg->cmsg_type == SCTP_SNDRCV) { + memcpy(sinfo, CMSG_DATA(cmsg), sizeof(struct sctp_sndrcvinfo)); break; } - if (cmsg->cmsg_level == IPPROTO_SCTP) { - if (cmsg->cmsg_type == SCTP_SNDRCV) { - /* Got it */ - s_info = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); - /* Copy it to the user */ - if (sinfo) - *sinfo = *s_info; - break; - } else if (cmsg->cmsg_type == SCTP_EXTRCV) { - /* - * Got it, presumably the user has - * asked for this extra info, so the - * structure holds more room :-D - */ - s_info = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); - /* Copy it to the user */ - if (sinfo) { - memcpy(sinfo, s_info, sizeof(struct sctp_extrcvinfo)); - } - break; - - } + if (cmsg->cmsg_type == SCTP_EXTRCV) { + /* + * Let's hope that the user provided enough + * enough memory. At least he asked for more + * information. + */ + memcpy(sinfo, CMSG_DATA(cmsg), sizeof(struct sctp_extrcvinfo)); + break; } - cmsg = CMSG_NXTHDR(&msg, cmsg); } } return (sz); @@ -940,10 +833,10 @@ sctp_recvv(int sd, unsigned int *infotype, int *flags) { - char ctlbuf[SCTP_CONTROL_VEC_SIZE_RCV]; + char cmsgbuf[SCTP_CONTROL_VEC_SIZE_RCV]; struct msghdr msg; struct cmsghdr *cmsg; - ssize_t n; + ssize_t ret; struct sctp_rcvinfo *rcvinfo; struct sctp_nxtinfo *nxtinfo; @@ -964,12 +857,11 @@ sctp_recvv(int sd, } msg.msg_iov = (struct iovec *)iov; msg.msg_iovlen = iovlen; - msg.msg_control = ctlbuf; - msg.msg_controllen = sizeof(ctlbuf); - errno = 0; - n = recvmsg(sd, &msg, *flags); + msg.msg_control = cmsgbuf; + msg.msg_controllen = sizeof(cmsgbuf); + ret = recvmsg(sd, &msg, *flags); *flags = msg.msg_flags; - if ((n > 0) && + if ((ret > 0) && (msg.msg_controllen > 0) && (infotype != NULL) && (infolen != NULL) && @@ -982,41 +874,44 @@ sctp_recvv(int sd, } if (cmsg->cmsg_type == SCTP_RCVINFO) { rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg); + if (nxtinfo != NULL) { + break; + } else { + continue; + } } if (cmsg->cmsg_type == SCTP_NXTINFO) { nxtinfo = (struct sctp_nxtinfo *)CMSG_DATA(cmsg); - } - if (rcvinfo && nxtinfo) { - break; + if (rcvinfo != NULL) { + break; + } else { + continue; + } } } - if (rcvinfo) { - if (nxtinfo) { - if (*infolen >= sizeof(struct sctp_recvv_rn)) { - struct sctp_recvv_rn *rn_info; - - rn_info = (struct sctp_recvv_rn *)info; - rn_info->recvv_rcvinfo = *rcvinfo; - rn_info->recvv_nxtinfo = *nxtinfo; - *infolen = (socklen_t) sizeof(struct sctp_recvv_rn); - *infotype = SCTP_RECVV_RN; - } - } else { - if (*infolen >= sizeof(struct sctp_rcvinfo)) { - memcpy(info, rcvinfo, sizeof(struct sctp_rcvinfo)); - *infolen = (socklen_t) sizeof(struct sctp_rcvinfo); - *infotype = SCTP_RECVV_RCVINFO; - } + if (rcvinfo != NULL) { + if ((nxtinfo != NULL) && (*infolen >= sizeof(struct sctp_recvv_rn))) { + struct sctp_recvv_rn *rn_info; + + rn_info = (struct sctp_recvv_rn *)info; + rn_info->recvv_rcvinfo = *rcvinfo; + rn_info->recvv_nxtinfo = *nxtinfo; + *infolen = (socklen_t) sizeof(struct sctp_recvv_rn); + *infotype = SCTP_RECVV_RN; + } else if (*infolen >= sizeof(struct sctp_rcvinfo)) { + memcpy(info, rcvinfo, sizeof(struct sctp_rcvinfo)); + *infolen = (socklen_t) sizeof(struct sctp_rcvinfo); + *infotype = SCTP_RECVV_RCVINFO; } - } else if (nxtinfo) { - if (*infolen >= sizeof(struct sctp_rcvinfo)) { + } else if (nxtinfo != NULL) { + if (*infolen >= sizeof(struct sctp_nxtinfo)) { memcpy(info, nxtinfo, sizeof(struct sctp_nxtinfo)); *infolen = (socklen_t) sizeof(struct sctp_nxtinfo); *infotype = SCTP_RECVV_NXTINFO; } } } - return (n); + return (ret); } ssize_t @@ -1241,7 +1136,4 @@ sctp_peeloff(int sd, sctp_assoc_t assoc_id) #endif - -#undef SCTP_CONTROL_VEC_SIZE_SND #undef SCTP_CONTROL_VEC_SIZE_RCV -#undef SCTP_STACK_BUF_SIZE diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index 68ffa66..f3a41e9 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -1212,7 +1212,7 @@ CHaddrange(struct parse *p, cset *cs, wint_t min, wint_t max) } cs->ranges = newranges; cs->ranges[cs->nranges].min = min; - cs->ranges[cs->nranges].min = max; + cs->ranges[cs->nranges].max = max; cs->nranges++; } diff --git a/lib/libc/rpc/clnt_vc.c b/lib/libc/rpc/clnt_vc.c index 881f84d..53e393e 100644 --- a/lib/libc/rpc/clnt_vc.c +++ b/lib/libc/rpc/clnt_vc.c @@ -260,7 +260,7 @@ clnt_vc_create(fd, raddr, prog, vers, sendsz, recvsz) if (ct->ct_addr.buf == NULL) goto err; memcpy(ct->ct_addr.buf, raddr->buf, raddr->len); - ct->ct_addr.len = raddr->maxlen; + ct->ct_addr.len = raddr->len; ct->ct_addr.maxlen = raddr->maxlen; /* diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc index bc3b9e5..0062d3d 100644 --- a/lib/libc/stdio/Makefile.inc +++ b/lib/libc/stdio/Makefile.inc @@ -14,6 +14,7 @@ SRCS+= _flock_stub.c asprintf.c clrerr.c dprintf.c \ ftell.c funopen.c fvwrite.c fwalk.c fwide.c fwprintf.c fwscanf.c \ fwrite.c getc.c getchar.c getdelim.c getline.c \ gets.c getw.c getwc.c getwchar.c makebuf.c mktemp.c \ + open_memstream.c open_wmemstream.c \ perror.c printf.c printf-pos.c putc.c putchar.c \ puts.c putw.c putwc.c putwchar.c \ refill.c remove.c rewind.c rget.c scanf.c setbuf.c setbuffer.c \ @@ -36,7 +37,7 @@ MAN+= fclose.3 ferror.3 fflush.3 fgetln.3 fgets.3 fgetwln.3 fgetws.3 \ flockfile.3 \ fopen.3 fputs.3 \ fputws.3 fread.3 fseek.3 funopen.3 fwide.3 getc.3 \ - getline.3 getwc.3 mktemp.3 \ + getline.3 getwc.3 mktemp.3 open_memstream.3 \ printf.3 printf_l.3 putc.3 putwc.3 remove.3 scanf.3 scanf_l.3 setbuf.3 \ stdio.3 tmpnam.3 \ ungetc.3 ungetwc.3 wprintf.3 wscanf.3 @@ -60,6 +61,7 @@ MLINKS+=getc.3 fgetc.3 getc.3 getc_unlocked.3 getc.3 getchar.3 \ MLINKS+=getline.3 getdelim.3 MLINKS+=getwc.3 fgetwc.3 getwc.3 getwchar.3 MLINKS+=mktemp.3 mkdtemp.3 mktemp.3 mkstemp.3 mktemp.3 mkstemps.3 +MLINKS+=open_memstream.3 open_wmemstream.3 MLINKS+=printf.3 asprintf.3 printf.3 dprintf.3 printf.3 fprintf.3 \ printf.3 snprintf.3 printf.3 sprintf.3 \ printf.3 vasprintf.3 printf.3 vdprintf.3 \ diff --git a/lib/libc/stdio/Symbol.map b/lib/libc/stdio/Symbol.map index b78de5a..538b29a 100644 --- a/lib/libc/stdio/Symbol.map +++ b/lib/libc/stdio/Symbol.map @@ -156,6 +156,8 @@ FBSD_1.3 { putwc_l; putwchar_l; fmemopen; + open_memstream; + open_wmemstream; }; FBSDprivate_1.0 { diff --git a/lib/libc/stdio/fgetln.c b/lib/libc/stdio/fgetln.c index 7cb2854..0cd04b8 100644 --- a/lib/libc/stdio/fgetln.c +++ b/lib/libc/stdio/fgetln.c @@ -115,7 +115,7 @@ fgetln(FILE *fp, size_t *lenp) * As a bonus, though, we can leave off the __SMOD. * * OPTIMISTIC is length that we (optimistically) expect will - * accomodate the `rest' of the string, on each trip through the + * accommodate the `rest' of the string, on each trip through the * loop below. */ #define OPTIMISTIC 80 diff --git a/lib/libc/stdio/fopen.3 b/lib/libc/stdio/fopen.3 index a07be38..f11f4e0 100644 --- a/lib/libc/stdio/fopen.3 +++ b/lib/libc/stdio/fopen.3 @@ -332,7 +332,7 @@ but is also supported by glibc. The .Fn fmemopen function -conforms to +conforms to .St -p1003.1-2008 . The ``b'' mode does not conform to any standard but is also supported by glibc. diff --git a/lib/libc/stdio/fwalk.c b/lib/libc/stdio/fwalk.c index e5ce49f..cb20071 100644 --- a/lib/libc/stdio/fwalk.c +++ b/lib/libc/stdio/fwalk.c @@ -37,7 +37,6 @@ static char sccsid[] = "@(#)fwalk.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include <sys/types.h> -#include <machine/atomic.h> #include <stdio.h> #include "local.h" #include "glue.h" diff --git a/lib/libc/stdio/open_memstream.3 b/lib/libc/stdio/open_memstream.3 new file mode 100644 index 0000000..9396830 --- /dev/null +++ b/lib/libc/stdio/open_memstream.3 @@ -0,0 +1,155 @@ +.\" Copyright (c) 2013 Advanced Computing Technologies LLC +.\" Written by: John H. Baldwin <jhb@FreeBSD.org> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd February 27, 2013 +.Dt OPEN_MEMSTREAM 3 +.Os +.Sh NAME +.Nm open_memstream , +.Nm open_wmemstream +.Nd dynamic memory buffer stream open functions +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdio.h +.Ft FILE * +.Fn open_memstream "char **bufp" "size_t **sizep" +.In wchar.h +.Ft FILE * +.Fn open_wmemstream "wchar_t **bufp" "size_t **sizep" +.Sh DESCRIPTION +The +.Fn open_memstream +and +.Fn open_wmemstream +functions create a write-only, seekable stream backed by a dynamically +allocated memory buffer. +The +.Fn open_memstream +function creates a byte-oriented stream, +while the +.Fn open_wmemstream +function creates a wide-oriented stream. +.Pp +Each stream maintains a current position and size. +Initially, +the position and size are set to zero. +Each write begins at the current position and advances it the number of +successfully written bytes for +.Fn open_memstream +or wide characters for +.Fn open_wmemstream . +If a write moves the current position beyond the length of the buffer, +the length of the buffer is extended and a null character is appended to the +buffer. +.Pp +A stream's buffer always contains a null character at the end of the buffer +that is not included in the current length. +.Pp +If a stream's current position is moved beyond the current length via a +seek operation and a write is performed, +the characters between the current length and the current position are filled +with null characters before the write is performed. +.Pp +After a successful call to +.Xr fclose 3 +or +.Xr fflush 3 , +the pointer referenced by +.Fa bufp +will contain the start of the memory buffer and the variable referenced by +.Fa sizep +will contain the smaller of the current position and the current buffer length. +.Pp +After a successful call to +.Xr fflush 3, +the pointer referenced by +.Fa bufp +and the variable referenced by +.Fa sizep +are only valid until the next write operation or a call to +.Xr fclose 3. +.Pp +Once a stream is closed, +the allocated buffer referenced by +.Fa bufp +should be released via a call to +.Xr free 3 +when it is no longer needed. +.Sh IMPLEMENTATION NOTES +Internally all I/O streams are effectively byte-oriented, +so using wide-oriented operations to write to a stream opened via +.Fn open_wmemstream +results in wide characters being expanded to a stream of multibyte characters +in stdio's internal buffers. +These multibyte characters are then converted back to wide characters when +written into the stream. +As a result, +the wide-oriented streams maintain an internal multibyte character conversion +state that is cleared on any seek opertion that changes the current position. +This should have no effect as long as wide-oriented output operations are used +on a wide-oriented stream. +.Sh RETURN VALUES +Upon successful completion, +.Fn open_memstream +and +.Fn open_wmemstream +return a +.Tn FILE +pointer. +Otherwise, +.Dv NULL +is returned and the global variable +.Va errno +is set to indicate the error. +.Sh ERRORS +.Bl -tag -width Er +.It Bq Er EINVAL +The +.Fa bufp +or +.Fa sizep +argument was +.Dv NULL . +.It Bq Er ENOMEM +Memory for the stream or buffer could not be allocated. +.El +.Sh SEE ALSO +.Xr fclose 3 , +.Xr fflush 3 , +.Xr fopen 3 , +.Xr free 3 , +.Xr fseek 3 , +.Xr sbuf 3 , +.Xr stdio 3 +.Sh STANDARDS +The +.Fn open_memstream +and +.Fn open_wmemstream +functions conform to +.St -p1003.1-2008 . diff --git a/lib/libc/stdio/open_memstream.c b/lib/libc/stdio/open_memstream.c new file mode 100644 index 0000000..aa50822 --- /dev/null +++ b/lib/libc/stdio/open_memstream.c @@ -0,0 +1,209 @@ +/*- + * Copyright (c) 2013 Advanced Computing Technologies LLC + * Written by: John H. Baldwin <jhb@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "namespace.h" +#include <assert.h> +#include <errno.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> +#include "un-namespace.h" + +/* XXX: There is no FPOS_MAX. This assumes fpos_t is an off_t. */ +#define FPOS_MAX OFF_MAX + +struct memstream { + char **bufp; + size_t *sizep; + ssize_t len; + fpos_t offset; +}; + +static int +memstream_grow(struct memstream *ms, fpos_t newoff) +{ + char *buf; + ssize_t newsize; + + if (newoff < 0 || newoff >= SSIZE_MAX) + newsize = SSIZE_MAX - 1; + else + newsize = newoff; + if (newsize > ms->len) { + buf = realloc(*ms->bufp, newsize + 1); + if (buf != NULL) { +#ifdef DEBUG + fprintf(stderr, "MS: %p growing from %zd to %zd\n", + ms, ms->len, newsize); +#endif + memset(buf + ms->len + 1, 0, newsize - ms->len); + *ms->bufp = buf; + ms->len = newsize; + return (1); + } + return (0); + } + return (1); +} + +static void +memstream_update(struct memstream *ms) +{ + + assert(ms->len >= 0 && ms->offset >= 0); + *ms->sizep = ms->len < ms->offset ? ms->len : ms->offset; +} + +static int +memstream_write(void *cookie, const char *buf, int len) +{ + struct memstream *ms; + ssize_t tocopy; + + ms = cookie; + if (!memstream_grow(ms, ms->offset + len)) + return (-1); + tocopy = ms->len - ms->offset; + if (len < tocopy) + tocopy = len; + memcpy(*ms->bufp + ms->offset, buf, tocopy); + ms->offset += tocopy; + memstream_update(ms); +#ifdef DEBUG + fprintf(stderr, "MS: write(%p, %d) = %zd\n", ms, len, tocopy); +#endif + return (tocopy); +} + +static fpos_t +memstream_seek(void *cookie, fpos_t pos, int whence) +{ + struct memstream *ms; +#ifdef DEBUG + fpos_t old; +#endif + + ms = cookie; +#ifdef DEBUG + old = ms->offset; +#endif + switch (whence) { + case SEEK_SET: + /* _fseeko() checks for negative offsets. */ + assert(pos >= 0); + ms->offset = pos; + break; + case SEEK_CUR: + /* This is only called by _ftello(). */ + assert(pos == 0); + break; + case SEEK_END: + if (pos < 0) { + if (pos + ms->len < 0) { +#ifdef DEBUG + fprintf(stderr, + "MS: bad SEEK_END: pos %jd, len %zd\n", + (intmax_t)pos, ms->len); +#endif + errno = EINVAL; + return (-1); + } + } else { + if (FPOS_MAX - ms->len < pos) { +#ifdef DEBUG + fprintf(stderr, + "MS: bad SEEK_END: pos %jd, len %zd\n", + (intmax_t)pos, ms->len); +#endif + errno = EOVERFLOW; + return (-1); + } + } + ms->offset = ms->len + pos; + break; + } + memstream_update(ms); +#ifdef DEBUG + fprintf(stderr, "MS: seek(%p, %jd, %d) %jd -> %jd\n", ms, (intmax_t)pos, + whence, (intmax_t)old, (intmax_t)ms->offset); +#endif + return (ms->offset); +} + +static int +memstream_close(void *cookie) +{ + + free(cookie); + return (0); +} + +FILE * +open_memstream(char **bufp, size_t *sizep) +{ + struct memstream *ms; + int save_errno; + FILE *fp; + + if (bufp == NULL || sizep == NULL) { + errno = EINVAL; + return (NULL); + } + *bufp = calloc(1, 1); + if (*bufp == NULL) + return (NULL); + ms = malloc(sizeof(*ms)); + if (ms == NULL) { + save_errno = errno; + free(*bufp); + *bufp = NULL; + errno = save_errno; + return (NULL); + } + ms->bufp = bufp; + ms->sizep = sizep; + ms->len = 0; + ms->offset = 0; + memstream_update(ms); + fp = funopen(ms, NULL, memstream_write, memstream_seek, + memstream_close); + if (fp == NULL) { + save_errno = errno; + free(ms); + free(*bufp); + *bufp = NULL; + errno = save_errno; + return (NULL); + } + fwide(fp, -1); + return (fp); +} diff --git a/lib/libc/stdio/open_wmemstream.c b/lib/libc/stdio/open_wmemstream.c new file mode 100644 index 0000000..cf2968a --- /dev/null +++ b/lib/libc/stdio/open_wmemstream.c @@ -0,0 +1,271 @@ +/*- + * Copyright (c) 2013 Advanced Computing Technologies LLC + * Written by: John H. Baldwin <jhb@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "namespace.h" +#include <assert.h> +#include <errno.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> +#include "un-namespace.h" + +/* XXX: There is no FPOS_MAX. This assumes fpos_t is an off_t. */ +#define FPOS_MAX OFF_MAX + +struct wmemstream { + wchar_t **bufp; + size_t *sizep; + ssize_t len; + fpos_t offset; + mbstate_t mbstate; +}; + +static int +wmemstream_grow(struct wmemstream *ms, fpos_t newoff) +{ + wchar_t *buf; + ssize_t newsize; + + if (newoff < 0 || newoff >= SSIZE_MAX / sizeof(wchar_t)) + newsize = SSIZE_MAX / sizeof(wchar_t) - 1; + else + newsize = newoff; + if (newsize > ms->len) { + buf = realloc(*ms->bufp, (newsize + 1) * sizeof(wchar_t)); + if (buf != NULL) { +#ifdef DEBUG + fprintf(stderr, "WMS: %p growing from %zd to %zd\n", + ms, ms->len, newsize); +#endif + wmemset(buf + ms->len + 1, 0, newsize - ms->len); + *ms->bufp = buf; + ms->len = newsize; + return (1); + } + return (0); + } + return (1); +} + +static void +wmemstream_update(struct wmemstream *ms) +{ + + assert(ms->len >= 0 && ms->offset >= 0); + *ms->sizep = ms->len < ms->offset ? ms->len : ms->offset; +} + +/* + * Based on a starting multibyte state and an input buffer, determine + * how many wchar_t's would be output. This doesn't use mbsnrtowcs() + * so that it can handle embedded null characters. + */ +static size_t +wbuflen(const mbstate_t *state, const char *buf, int len) +{ + mbstate_t lenstate; + size_t charlen, count; + + count = 0; + lenstate = *state; + while (len > 0) { + charlen = mbrlen(buf, len, &lenstate); + if (charlen == (size_t)-1) + return (-1); + if (charlen == (size_t)-2) + break; + if (charlen == 0) + /* XXX: Not sure how else to handle this. */ + charlen = 1; + len -= charlen; + buf += charlen; + count++; + } + return (count); +} + +static int +wmemstream_write(void *cookie, const char *buf, int len) +{ + struct wmemstream *ms; + ssize_t consumed, wlen; + size_t charlen; + + ms = cookie; + wlen = wbuflen(&ms->mbstate, buf, len); + if (wlen < 0) { + errno = EILSEQ; + return (-1); + } + if (!wmemstream_grow(ms, ms->offset + wlen)) + return (-1); + + /* + * This copies characters one at a time rather than using + * mbsnrtowcs() so it can properly handle embedded null + * characters. + */ + consumed = 0; + while (len > 0 && ms->offset < ms->len) { + charlen = mbrtowc(*ms->bufp + ms->offset, buf, len, + &ms->mbstate); + if (charlen == (size_t)-1) { + if (consumed == 0) { + errno = EILSEQ; + return (-1); + } + /* Treat it as a successful short write. */ + break; + } + if (charlen == 0) + /* XXX: Not sure how else to handle this. */ + charlen = 1; + if (charlen == (size_t)-2) { + consumed += len; + len = 0; + } else { + consumed += charlen; + buf += charlen; + len -= charlen; + ms->offset++; + } + } + wmemstream_update(ms); +#ifdef DEBUG + fprintf(stderr, "WMS: write(%p, %d) = %zd\n", ms, len, consumed); +#endif + return (consumed); +} + +static fpos_t +wmemstream_seek(void *cookie, fpos_t pos, int whence) +{ + struct wmemstream *ms; + fpos_t old; + + ms = cookie; + old = ms->offset; + switch (whence) { + case SEEK_SET: + /* _fseeko() checks for negative offsets. */ + assert(pos >= 0); + ms->offset = pos; + break; + case SEEK_CUR: + /* This is only called by _ftello(). */ + assert(pos == 0); + break; + case SEEK_END: + if (pos < 0) { + if (pos + ms->len < 0) { +#ifdef DEBUG + fprintf(stderr, + "WMS: bad SEEK_END: pos %jd, len %zd\n", + (intmax_t)pos, ms->len); +#endif + errno = EINVAL; + return (-1); + } + } else { + if (FPOS_MAX - ms->len < pos) { +#ifdef DEBUG + fprintf(stderr, + "WMS: bad SEEK_END: pos %jd, len %zd\n", + (intmax_t)pos, ms->len); +#endif + errno = EOVERFLOW; + return (-1); + } + } + ms->offset = ms->len + pos; + break; + } + /* Reset the multibyte state if a seek changes the position. */ + if (ms->offset != old) + memset(&ms->mbstate, 0, sizeof(ms->mbstate)); + wmemstream_update(ms); +#ifdef DEBUG + fprintf(stderr, "WMS: seek(%p, %jd, %d) %jd -> %jd\n", ms, + (intmax_t)pos, whence, (intmax_t)old, (intmax_t)ms->offset); +#endif + return (ms->offset); +} + +static int +wmemstream_close(void *cookie) +{ + + free(cookie); + return (0); +} + +FILE * +open_wmemstream(wchar_t **bufp, size_t *sizep) +{ + struct wmemstream *ms; + int save_errno; + FILE *fp; + + if (bufp == NULL || sizep == NULL) { + errno = EINVAL; + return (NULL); + } + *bufp = calloc(1, sizeof(wchar_t)); + if (*bufp == NULL) + return (NULL); + ms = malloc(sizeof(*ms)); + if (ms == NULL) { + save_errno = errno; + free(*bufp); + *bufp = NULL; + errno = save_errno; + return (NULL); + } + ms->bufp = bufp; + ms->sizep = sizep; + ms->len = 0; + ms->offset = 0; + memset(&ms->mbstate, 0, sizeof(mbstate_t)); + wmemstream_update(ms); + fp = funopen(ms, NULL, wmemstream_write, wmemstream_seek, + wmemstream_close); + if (fp == NULL) { + save_errno = errno; + free(ms); + free(*bufp); + *bufp = NULL; + errno = save_errno; + return (NULL); + } + fwide(fp, 1); + return (fp); +} diff --git a/lib/libc/stdio/setbuf.3 b/lib/libc/stdio/setbuf.3 index 2eda0e6..d1ae70b 100644 --- a/lib/libc/stdio/setbuf.3 +++ b/lib/libc/stdio/setbuf.3 @@ -32,7 +32,7 @@ .\" @(#)setbuf.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd February 18, 2013 .Dt SETBUF 3 .Os .Sh NAME @@ -196,18 +196,5 @@ functions conform to .St -isoC . .Sh BUGS -The -.Fn setbuffer -and -.Fn setlinebuf -functions are not portable to versions of -.Bx -before -.Bx 4.2 . -On -.Bx 4.2 -and -.Bx 4.3 -systems, .Fn setbuf -always uses a suboptimal buffer size and should be avoided. +usually uses a suboptimal buffer size and should be avoided. diff --git a/lib/libc/stdlib/bsearch.3 b/lib/libc/stdlib/bsearch.3 index b3591f8e..25be842 100644 --- a/lib/libc/stdlib/bsearch.3 +++ b/lib/libc/stdlib/bsearch.3 @@ -32,7 +32,7 @@ .\" @(#)bsearch.3 8.3 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd April 19, 1994 +.Dd February 22, 2013 .Dt BSEARCH 3 .Os .Sh NAME @@ -71,6 +71,12 @@ less than, equal to, or greater than zero if the .Fa key object is found, respectively, to be less than, to match, or be greater than the array member. +See the +.Fa int_compare +sample function in +.Xr qsort 3 +for a comparison function that is also compatible with +.Fn bsearch . .Sh RETURN VALUES The .Fn bsearch diff --git a/lib/libc/stdlib/qsort.3 b/lib/libc/stdlib/qsort.3 index 0f7ef73..f34d260 100644 --- a/lib/libc/stdlib/qsort.3 +++ b/lib/libc/stdlib/qsort.3 @@ -32,7 +32,7 @@ .\" @(#)qsort.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd September 30, 2003 +.Dd February 20, 2013 .Dt QSORT 3 .Os .Sh NAME @@ -205,6 +205,46 @@ functions return no value. .Pp .Rv -std heapsort mergesort +.Sh EXAMPLES +A sample program that sorts an array of +.Vt int +values in place using +.Fn qsort , +and then prints the sorted array to standard output is: +.Bd -literal +#include <stdio.h> +#include <stdlib.h> + +/* + * Custom comparison function that can compare 'int' values through pointers + * passed by qsort(3). + */ +static int +int_compare(const void *p1, const void *p2) +{ + int left = *(const int *)p1; + int right = *(const int *)p2; + + return ((left > right) - (left < right)); +} + +/* + * Sort an array of 'int' values and print it to standard output. + */ +int +main(void) +{ + int int_array[] = { 4, 5, 9, 3, 0, 1, 7, 2, 8, 6 }; + const size_t array_size = sizeof(int_array) / sizeof(int_array[0]); + size_t k; + + qsort(&int_array, array_size, sizeof(int_array[0]), int_compare); + for (k = 0; k < array_size; k++) + printf(" %d", int_array[k]); + puts(""); + return (EXIT_SUCCESS); +} +.Ed .Sh COMPATIBILITY Previous versions of .Fn qsort diff --git a/lib/libc/stdlib/rand.3 b/lib/libc/stdlib/rand.3 index 390a40b..bf50e3d 100644 --- a/lib/libc/stdlib/rand.3 +++ b/lib/libc/stdlib/rand.3 @@ -32,7 +32,7 @@ .\" @(#)rand.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd September 4, 2012 +.Dd April 2, 2013 .Dt RAND 3 .Os .Sh NAME @@ -91,9 +91,7 @@ seeded with a value of 1. .Pp The .Fn sranddev -function initializes a seed using the -.Xr random 4 -random number device which returns good random numbers. +function initializes a seed using pseudo-random numbers obtained from the kernel. .Pp The .Fn rand_r diff --git a/lib/libc/stdlib/rand.c b/lib/libc/stdlib/rand.c index 7041818..0cbd948 100644 --- a/lib/libc/stdlib/rand.c +++ b/lib/libc/stdlib/rand.c @@ -36,11 +36,10 @@ static char sccsid[] = "@(#)rand.c 8.1 (Berkeley) 6/14/93"; __FBSDID("$FreeBSD$"); #include "namespace.h" -#include <sys/time.h> /* for sranddev() */ +#include <sys/param.h> +#include <sys/sysctl.h> #include <sys/types.h> -#include <fcntl.h> /* for sranddev() */ #include <stdlib.h> -#include <unistd.h> /* for sranddev() */ #include "un-namespace.h" #ifdef TEST @@ -112,28 +111,20 @@ u_int seed; * sranddev: * * Many programs choose the seed value in a totally predictable manner. - * This often causes problems. We seed the generator using the much more - * secure random(4) interface. + * This often causes problems. We seed the generator using pseudo-random + * data from the kernel. */ void sranddev() { - int fd, done; - - done = 0; - fd = _open("/dev/random", O_RDONLY | O_CLOEXEC, 0); - if (fd >= 0) { - if (_read(fd, (void *) &next, sizeof(next)) == sizeof(next)) - done = 1; - _close(fd); - } - - if (!done) { - struct timeval tv; - - gettimeofday(&tv, NULL); - srand((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec); - } + int mib[2]; + size_t len; + + len = sizeof(next); + + mib[0] = CTL_KERN; + mib[1] = KERN_ARND; + sysctl(mib, 2, (void *)&next, &len, NULL, 0); } diff --git a/lib/libc/stdlib/random.3 b/lib/libc/stdlib/random.3 index 4817440..a1e585b 100644 --- a/lib/libc/stdlib/random.3 +++ b/lib/libc/stdlib/random.3 @@ -28,7 +28,7 @@ .\" @(#)random.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd September 4, 2012 +.Dd April 2, 2013 .Dt RANDOM 3 .Os .Sh NAME @@ -106,8 +106,8 @@ as the seed. .Pp The .Fn srandomdev -routine initializes a state array using data from -.Xr random 4 . +routine initializes a state array using +pseudo-random numbers obtained from the kernel. Note that this particular seeding procedure can generate states which are impossible to reproduce by calling diff --git a/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c index a3c054e..4c88ecb 100644 --- a/lib/libc/stdlib/random.c +++ b/lib/libc/stdlib/random.c @@ -34,12 +34,11 @@ static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95"; __FBSDID("$FreeBSD$"); #include "namespace.h" -#include <sys/time.h> /* for srandomdev() */ -#include <fcntl.h> /* for srandomdev() */ +#include <sys/param.h> +#include <sys/sysctl.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> /* for srandomdev() */ #include "un-namespace.h" /* @@ -284,39 +283,28 @@ srandom(unsigned long x) * srandomdev: * * Many programs choose the seed value in a totally predictable manner. - * This often causes problems. We seed the generator using the much more - * secure random(4) interface. Note that this particular seeding - * procedure can generate states which are impossible to reproduce by - * calling srandom() with any value, since the succeeding terms in the - * state buffer are no longer derived from the LC algorithm applied to - * a fixed seed. + * This often causes problems. We seed the generator using pseudo-random + * data from the kernel. + * + * Note that this particular seeding procedure can generate states + * which are impossible to reproduce by calling srandom() with any + * value, since the succeeding terms in the state buffer are no longer + * derived from the LC algorithm applied to a fixed seed. */ void srandomdev(void) { - int fd, done; + int mib[2]; size_t len; if (rand_type == TYPE_0) - len = sizeof state[0]; + len = sizeof(state[0]); else - len = rand_deg * sizeof state[0]; - - done = 0; - fd = _open("/dev/random", O_RDONLY | O_CLOEXEC, 0); - if (fd >= 0) { - if (_read(fd, (void *) state, len) == (ssize_t) len) - done = 1; - _close(fd); - } + len = rand_deg * sizeof(state[0]); - if (!done) { - struct timeval tv; - - gettimeofday(&tv, NULL); - srandom((getpid() << 16) ^ tv.tv_sec ^ tv.tv_usec); - return; - } + mib[0] = CTL_KERN; + mib[1] = KERN_ARND; + sysctl(mib, 2, state, &len, NULL, 0); if (rand_type != TYPE_0) { fptr = &state[rand_sep]; diff --git a/lib/libc/stdlib/realpath.3 b/lib/libc/stdlib/realpath.3 index c7384d6..33970fd 100644 --- a/lib/libc/stdlib/realpath.3 +++ b/lib/libc/stdlib/realpath.3 @@ -42,7 +42,7 @@ .Sh SYNOPSIS .In stdlib.h .Ft "char *" -.Fn realpath "const char *pathname" "char *resolved_path" +.Fn realpath "const char * restrict pathname" "char * restrict resolved_path" .Sh DESCRIPTION The .Fn realpath diff --git a/lib/libc/stdtime/Makefile.inc b/lib/libc/stdtime/Makefile.inc index 0cc038a..477049f 100644 --- a/lib/libc/stdtime/Makefile.inc +++ b/lib/libc/stdtime/Makefile.inc @@ -11,6 +11,9 @@ SYM_MAPS+= ${.CURDIR}/stdtime/Symbol.map CFLAGS+= -I${.CURDIR}/../../contrib/tzcode/stdtime -I${.CURDIR}/stdtime +CFLAGS.localtime.c= -fwrapv +CFLAGS+= ${CFLAGS.${.IMPSRC:T}} + MAN+= ctime.3 strftime.3 strptime.3 time2posix.3 MAN+= tzfile.5 diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index cd06fc8..b997b7b 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -10,9 +10,9 @@ MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \ memccpy.c memchr.c memrchr.c memcmp.c \ memcpy.c memmem.c memmove.c memset.c \ stpcpy.c stpncpy.c strcasecmp.c \ - strcat.c strcasestr.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c \ - strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c \ - strncmp.c strncpy.c strndup.c strnlen.c strnstr.c \ + strcat.c strcasestr.c strchr.c strchrnul.c strcmp.c strcoll.c strcpy.c\ + strcspn.c strdup.c strerror.c strlcat.c strlcpy.c strlen.c strmode.c \ + strncat.c strncmp.c strncpy.c strndup.c strnlen.c strnstr.c \ strpbrk.c strrchr.c strsep.c strsignal.c strspn.c strstr.c strtok.c \ strxfrm.c swab.c wcpcpy.c wcpncpy.c wcscasecmp.c wcscat.c \ wcschr.c wcscmp.c wcscoll.c wcscpy.c wcscspn.c wcsdup.c \ @@ -46,7 +46,8 @@ MLINKS+=strcasecmp.3 strncasecmp.3 \ strcasecmp.3 strcasecmp_l.3 \ strcasecmp.3 strncasecmp_l.3 MLINKS+=strcat.3 strncat.3 -MLINKS+=strchr.3 strrchr.3 +MLINKS+=strchr.3 strrchr.3 \ + strchr.3 strchrnul.3 MLINKS+=strcmp.3 strncmp.3 MLINKS+=strcoll.3 strcoll_l.3 MLINKS+=strcpy.3 stpcpy.3 \ diff --git a/lib/libc/string/Symbol.map b/lib/libc/string/Symbol.map index ef23465..8e80165 100644 --- a/lib/libc/string/Symbol.map +++ b/lib/libc/string/Symbol.map @@ -94,6 +94,7 @@ FBSD_1.1 { FBSD_1.3 { strcasecmp_l; strcasestr_l; + strchrnul; strncasecmp_l; wcswidth_l; wcwidth_l; diff --git a/lib/libc/string/strchr.3 b/lib/libc/string/strchr.3 index 984eb06..019b923 100644 --- a/lib/libc/string/strchr.3 +++ b/lib/libc/string/strchr.3 @@ -32,11 +32,11 @@ .\" @(#)strchr.3 8.2 (Berkeley) 4/19/94 .\" $FreeBSD$ .\" -.Dd April 19, 1994 +.Dd February 13, 2013 .Dt STRCHR 3 .Os .Sh NAME -.Nm strchr , strrchr +.Nm strchr , strrchr , strchrnul .Nd locate character in string .Sh LIBRARY .Lb libc @@ -46,6 +46,8 @@ .Fn strchr "const char *s" "int c" .Ft "char *" .Fn strrchr "const char *s" "int c" +.Ft "char *" +.Fn strchrnul "const char *s" "int c" .Sh DESCRIPTION The .Fn strchr @@ -69,6 +71,18 @@ function is identical to .Fn strchr except it locates the last occurrence of .Fa c . +.Pp +The +.Fn strchrnul +function is identical to +.Fn strchr +except that if +.Fa c +is not found in +.Fa s +a pointer to the terminating +.Ql \e0 +is returned. .Sh RETURN VALUES The functions .Fn strchr @@ -77,6 +91,11 @@ and return a pointer to the located character, or .Dv NULL if the character does not appear in the string. +.Pp +.Fn strchrnul +returns a pointer to the terminating +.Ql \e0 +if the character does not appear in the string. .Sh SEE ALSO .Xr memchr 3 , .Xr memmem 3 , @@ -94,3 +113,11 @@ and .Fn strrchr conform to .St -isoC . +The +.Fn strchrnul +is a GNU extension . +.Sh History +The +.Fn strchrnul +function first appeared in glibc 2.1.1 and was added in +.Fx 10.0 . diff --git a/lib/libprocstat/ntfs.c b/lib/libc/string/strchrnul.c index 888e6cd..98e652d 100644 --- a/lib/libprocstat/ntfs.c +++ b/lib/libc/string/strchrnul.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2005-2009 Stanislav Sedov <stas@FreeBSD.org> + * Copyright (c) 2013 Niclas Zeising * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -22,50 +22,27 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * */ + #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/vnode.h> -#include <sys/mount.h> - -#include <netinet/in.h> - -#include <assert.h> -#include <err.h> -#include <kvm.h> -#include <stdlib.h> +#include <stddef.h> +#include <string.h> -#include <fs/ntfs/ntfs.h> -#include <fs/ntfs/ntfs_inode.h> +__weak_reference(__strchrnul, strchrnul); -#include "libprocstat.h" -#include "common_kvm.h" - -int -ntfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) +char * +__strchrnul(const char *p, int ch) { - struct fnode fnod; - struct ntnode node; - int error; + char c; - assert(kd); - assert(vn); - error = kvm_read_all(kd, (unsigned long)VTOF(vp), &fnod, sizeof(fnod)); - if (error != 0) { - warnx("can't read ntfs fnode at %p", (void *)VTOF(vp)); - return (1); - } - error = kvm_read_all(kd, (unsigned long)FTONT(&fnod), &node, - sizeof(node)); - if (error != 0) { - warnx("can't read ntfs node at %p", (void *)FTONT(&fnod)); - return (1); + c = ch; + for (;; ++p) { + if (*p == c || *p == '\0') + return ((char *)p); } - vn->vn_fileid = node.i_number; - vn->vn_fsid = dev2udev(kd, node.i_dev); - return (0); + /* NOTREACHED */ } + diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index a35ed5d..fef0f3c 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -78,59 +78,219 @@ ${SPSEUDO}: >> ${.TARGET} printf ${NOTE_GNU_STACK} >>${.TARGET} -MAN+= abort2.2 accept.2 access.2 acct.2 adjtime.2 \ - aio_cancel.2 aio_error.2 aio_read.2 aio_return.2 \ - aio_suspend.2 aio_waitcomplete.2 aio_write.2 \ - bind.2 brk.2 cap_enter.2 cap_new.2 chdir.2 chflags.2 \ - chmod.2 chown.2 chroot.2 clock_gettime.2 close.2 closefrom.2 \ - connect.2 cpuset.2 cpuset_getaffinity.2 dup.2 execve.2 _exit.2 \ - extattr_get_file.2 fcntl.2 ffclock.2 fhopen.2 flock.2 fork.2 fsync.2 \ - getdirentries.2 getdtablesize.2 \ - getfh.2 getfsstat.2 getgid.2 getgroups.2 getitimer.2 getlogin.2 \ - getloginclass.2 getpeername.2 getpgrp.2 getpid.2 getpriority.2 \ - getrlimit.2 getrusage.2 getsid.2 getsockname.2 \ - getsockopt.2 gettimeofday.2 getuid.2 \ - intro.2 ioctl.2 issetugid.2 jail.2 kenv.2 kill.2 \ - kldfind.2 kldfirstmod.2 kldload.2 kldnext.2 kldstat.2 kldsym.2 \ - kldunload.2 kqueue.2 ktrace.2 link.2 lio_listio.2 listen.2 \ +MAN+= abort2.2 \ + accept.2 \ + access.2 \ + acct.2 \ + adjtime.2 \ + aio_cancel.2 \ + aio_error.2 \ + aio_read.2 \ + aio_return.2 \ + aio_suspend.2 \ + aio_waitcomplete.2 \ + aio_write.2 \ + bind.2 \ + bindat.2 \ + brk.2 \ + cap_enter.2 \ + cap_fcntls_limit.2 \ + cap_ioctls_limit.2 \ + cap_rights_limit.2 \ + chdir.2 \ + chflags.2 \ + chmod.2 \ + chown.2 \ + chroot.2 \ + clock_gettime.2 \ + close.2 \ + closefrom.2 \ + connect.2 \ + connectat.2 \ + cpuset.2 \ + cpuset_getaffinity.2 \ + dup.2 \ + execve.2 \ + _exit.2 \ + extattr_get_file.2 \ + fcntl.2 \ + ffclock.2 \ + fhopen.2 \ + flock.2 \ + fork.2 \ + fsync.2 \ + getdirentries.2 \ + getdtablesize.2 \ + getfh.2 \ + getfsstat.2 \ + getgid.2 \ + getgroups.2 \ + getitimer.2 \ + getlogin.2 \ + getloginclass.2 \ + getpeername.2 \ + getpgrp.2 \ + getpid.2 \ + getpriority.2 \ + getrlimit.2 \ + getrusage.2 \ + getsid.2 \ + getsockname.2 \ + getsockopt.2 \ + gettimeofday.2 \ + getuid.2 \ + intro.2 \ + ioctl.2 \ + issetugid.2 \ + jail.2 \ + kenv.2 \ + kill.2 \ + kldfind.2 \ + kldfirstmod.2 \ + kldload.2 \ + kldnext.2 \ + kldstat.2 \ + kldsym.2 \ + kldunload.2 \ + kqueue.2 \ + ktrace.2 \ + link.2 \ + lio_listio.2 \ + listen.2 \ lseek.2 \ - madvise.2 mincore.2 minherit.2 mkdir.2 mkfifo.2 mknod.2 mlock.2 \ - mlockall.2 mmap.2 modfind.2 modnext.2 modstat.2 mount.2 mprotect.2 \ - mq_close.2 mq_getattr.2 mq_notify.2 mq_open.2 mq_receive.2 mq_send.2 \ + madvise.2 \ + mincore.2 \ + minherit.2 \ + mkdir.2 \ + mkfifo.2 \ + mknod.2 \ + mlock.2 \ + mlockall.2 \ + mmap.2 \ + modfind.2 \ + modnext.2 \ + modstat.2 \ + mount.2 \ + mprotect.2 \ + mq_close.2 \ + mq_getattr.2 \ + mq_notify.2 \ + mq_open.2 \ + mq_receive.2 \ + mq_send.2 \ mq_setattr.2 \ - msgctl.2 msgget.2 msgrcv.2 msgsnd.2 \ - msync.2 munmap.2 nanosleep.2 nfssvc.2 ntp_adjtime.2 open.2 \ - pathconf.2 pdfork.2 pipe.2 poll.2 posix_fadvise.2 posix_fallocate.2 \ - posix_openpt.2 profil.2 \ - pselect.2 ptrace.2 quotactl.2 \ - read.2 readlink.2 reboot.2 recv.2 rename.2 revoke.2 rfork.2 rmdir.2 \ + msgctl.2 \ + msgget.2 \ + msgrcv.2 \ + msgsnd.2 \ + msync.2 \ + munmap.2 \ + nanosleep.2 \ + nfssvc.2 \ + ntp_adjtime.2 \ + open.2 \ + pathconf.2 \ + pdfork.2 \ + pipe.2 \ + poll.2 \ + posix_fadvise.2 \ + posix_fallocate.2 \ + posix_openpt.2 \ + profil.2 \ + pselect.2 \ + ptrace.2 \ + quotactl.2 \ + read.2 \ + readlink.2 \ + reboot.2 \ + recv.2 \ + rename.2 \ + revoke.2 \ + rfork.2 \ + rmdir.2 \ rtprio.2 .if !defined(NO_P1003_1B) -MAN+= sched_get_priority_max.2 sched_setparam.2 \ - sched_setscheduler.2 sched_yield.2 +MAN+= sched_get_priority_max.2 \ + sched_setparam.2 \ + sched_setscheduler.2 \ + sched_yield.2 .endif -MAN+= sctp_generic_recvmsg.2 sctp_generic_sendmsg.2 sctp_peeloff.2 \ - select.2 semctl.2 semget.2 semop.2 send.2 setfib.2 sendfile.2 \ - setgroups.2 setpgid.2 setregid.2 setresuid.2 setreuid.2 setsid.2 \ - setuid.2 shmat.2 shmctl.2 shmget.2 shm_open.2 shutdown.2 \ - sigaction.2 sigaltstack.2 sigpending.2 sigprocmask.2 sigqueue.2 \ - sigreturn.2 sigstack.2 sigsuspend.2 sigwait.2 sigwaitinfo.2 \ - socket.2 socketpair.2 stat.2 statfs.2 \ - swapon.2 symlink.2 sync.2 sysarch.2 syscall.2 \ - timer_create.2 timer_delete.2 timer_settime.2 \ - truncate.2 umask.2 undelete.2 \ - unlink.2 utimes.2 utrace.2 uuidgen.2 vfork.2 wait.2 write.2 - -MLINKS+=access.2 eaccess.2 access.2 faccessat.2 +MAN+= sctp_generic_recvmsg.2 \ + sctp_generic_sendmsg.2 \ + sctp_peeloff.2 \ + select.2 \ + semctl.2 \ + semget.2 \ + semop.2 \ + send.2 \ + setfib.2 \ + sendfile.2 \ + setgroups.2 \ + setpgid.2 \ + setregid.2 \ + setresuid.2 \ + setreuid.2 \ + setsid.2 \ + setuid.2 \ + shmat.2 \ + shmctl.2 \ + shmget.2 \ + shm_open.2 \ + shutdown.2 \ + sigaction.2 \ + sigaltstack.2 \ + sigpending.2 \ + sigprocmask.2 \ + sigqueue.2 \ + sigreturn.2 \ + sigstack.2 \ + sigsuspend.2 \ + sigwait.2 \ + sigwaitinfo.2 \ + socket.2 \ + socketpair.2 \ + stat.2 \ + statfs.2 \ + swapon.2 \ + symlink.2 \ + sync.2 \ + sysarch.2 \ + syscall.2 \ + timer_create.2 \ + timer_delete.2 \ + timer_settime.2 \ + truncate.2 \ + umask.2 \ + undelete.2 \ + unlink.2 \ + utimes.2 \ + utrace.2 \ + uuidgen.2 \ + vfork.2 \ + wait.2 \ + write.2 + +MLINKS+=access.2 eaccess.2 \ + access.2 faccessat.2 MLINKS+=brk.2 sbrk.2 MLINKS+=cap_enter.2 cap_getmode.2 -MLINKS+=cap_new.2 cap_getrights.2 +MLINKS+=cap_fcntls_limit.2 cap_fcntls_get.2 +MLINKS+=cap_ioctls_limit.2 cap_ioctls_get.2 +MLINKS+=cap_rights_limit.2 cap_rights_get.2 MLINKS+=chdir.2 fchdir.2 -MLINKS+=chflags.2 fchflags.2 chflags.2 lchflags.2 -MLINKS+=chmod.2 fchmod.2 chmod.2 fchmodat.2 chmod.2 lchmod.2 -MLINKS+=chown.2 fchown.2 chown.2 fchownat.2 chown.2 lchown.2 -MLINKS+=clock_gettime.2 clock_getres.2 clock_gettime.2 clock_settime.2 -MLINKS+=cpuset.2 cpuset_getid.2 cpuset.2 cpuset_setid.2 +MLINKS+=chflags.2 chflagsat.2 \ + chflags.2 fchflags.2 \ + chflags.2 lchflags.2 +MLINKS+=chmod.2 fchmod.2 \ + chmod.2 fchmodat.2 \ + chmod.2 lchmod.2 +MLINKS+=chown.2 fchown.2 \ + chown.2 fchownat.2 \ + chown.2 lchown.2 +MLINKS+=clock_gettime.2 clock_getres.2 \ + clock_gettime.2 clock_settime.2 +MLINKS+=cpuset.2 cpuset_getid.2 \ + cpuset.2 cpuset_setid.2 MLINKS+=cpuset_getaffinity.2 cpuset_setaffinity.2 MLINKS+=dup.2 dup2.2 MLINKS+=execve.2 fexecve.2 @@ -146,7 +306,8 @@ MLINKS+=extattr_get_file.2 extattr.2 \ extattr_get_file.2 extattr_set_fd.2 \ extattr_get_file.2 extattr_set_file.2 \ extattr_get_file.2 extattr_set_link.2 -MLINKS+=ffclock.2 ffclock_getcounter.2 ffclock.2 ffclock_getestimate.2 \ +MLINKS+=ffclock.2 ffclock_getcounter.2 \ + ffclock.2 ffclock_getestimate.2 \ ffclock.2 ffclock_setestimate.2 MLINKS+=fhopen.2 fhstat.2 fhopen.2 fhstatfs.2 MLINKS+=getdirentries.2 getdents.2 @@ -169,7 +330,8 @@ MLINKS+=jail.2 jail_attach.2 \ jail.2 jail_remove.2 \ jail.2 jail_set.2 MLINKS+=kldunload.2 kldunloadf.2 -MLINKS+=kqueue.2 kevent.2 kqueue.2 EV_SET.3 +MLINKS+=kqueue.2 kevent.2 \ + kqueue.2 EV_SET.3 MLINKS+=link.2 linkat.2 MLINKS+=madvise.2 posix_madvise.2 MLINKS+=mkdir.2 mkdirat.2 @@ -178,7 +340,8 @@ MLINKS+=mknod.2 mknodat.2 MLINKS+=mlock.2 munlock.2 MLINKS+=mlockall.2 munlockall.2 MLINKS+=modnext.2 modfnext.2 -MLINKS+=mount.2 nmount.2 mount.2 unmount.2 +MLINKS+=mount.2 nmount.2 \ + mount.2 unmount.2 MLINKS+=mq_receive.2 mq_timedreceive.2 MLINKS+=mq_send.2 mq_timedsend.2 MLINKS+=ntp_adjtime.2 ntp_gettime.2 @@ -188,9 +351,12 @@ MLINKS+=pathconf.2 lpathconf.2 MLINKS+=pdfork.2 pdgetpid.2\ pdfork.2 pdkill.2 \ pdfork.2 pdwait4.2 -MLINKS+=read.2 pread.2 read.2 preadv.2 read.2 readv.2 +MLINKS+=read.2 pread.2 \ + read.2 preadv.2 \ + read.2 readv.2 MLINKS+=readlink.2 readlinkat.2 -MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 +MLINKS+=recv.2 recvfrom.2 \ + recv.2 recvmsg.2 MLINKS+=rename.2 renameat.2 MLINKS+=rtprio.2 rtprio_thread.2 .if !defined(NO_P1003_1B) @@ -199,24 +365,41 @@ MLINKS+=sched_get_priority_max.2 sched_get_priority_min.2 \ MLINKS+=sched_setparam.2 sched_getparam.2 MLINKS+=sched_setscheduler.2 sched_getscheduler.2 .endif -MLINKS+=select.2 FD_CLR.3 select.2 FD_ISSET.3 select.2 FD_SET.3 \ +MLINKS+=select.2 FD_CLR.3 \ + select.2 FD_ISSET.3 \ + select.2 FD_SET.3 \ select.2 FD_ZERO.3 -MLINKS+=send.2 sendmsg.2 send.2 sendto.2 +MLINKS+=send.2 sendmsg.2 \ + send.2 sendto.2 MLINKS+=setpgid.2 setpgrp.2 -MLINKS+=setresuid.2 getresgid.2 setresuid.2 getresuid.2 setresuid.2 setresgid.2 -MLINKS+=setuid.2 setegid.2 setuid.2 seteuid.2 setuid.2 setgid.2 +MLINKS+=setresuid.2 getresgid.2 \ + setresuid.2 getresuid.2 \ + setresuid.2 setresgid.2 +MLINKS+=setuid.2 setegid.2 \ + setuid.2 seteuid.2 \ + setuid.2 setgid.2 MLINKS+=shmat.2 shmdt.2 MLINKS+=shm_open.2 shm_unlink.2 MLINKS+=sigwaitinfo.2 sigtimedwait.2 -MLINKS+=stat.2 fstat.2 stat.2 fstatat.2 stat.2 lstat.2 +MLINKS+=stat.2 fstat.2 \ + stat.2 fstatat.2 \ + stat.2 lstat.2 MLINKS+=statfs.2 fstatfs.2 MLINKS+=swapon.2 swapoff.2 MLINKS+=symlink.2 symlinkat.2 MLINKS+=syscall.2 __syscall.2 -MLINKS+=timer_settime.2 timer_getoverrun.2 timer_settime.2 timer_gettime.2 +MLINKS+=timer_settime.2 timer_getoverrun.2 \ + timer_settime.2 timer_gettime.2 MLINKS+=truncate.2 ftruncate.2 MLINKS+=unlink.2 unlinkat.2 -MLINKS+=utimes.2 futimes.2 utimes.2 futimesat.2 utimes.2 lutimes.2 -MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 \ - wait.2 waitid.2 wait.2 wait6.2 -MLINKS+=write.2 pwrite.2 write.2 pwritev.2 write.2 writev.2 +MLINKS+=utimes.2 futimes.2 \ + utimes.2 futimesat.2 \ + utimes.2 lutimes.2 +MLINKS+=wait.2 wait3.2 \ + wait.2 wait4.2 \ + wait.2 waitpid.2 \ + wait.2 waitid.2 \ + wait.2 wait6.2 +MLINKS+=write.2 pwrite.2 \ + write.2 pwritev.2 \ + write.2 writev.2 diff --git a/lib/libc/sys/Symbol.map b/lib/libc/sys/Symbol.map index babae30..6faa0af 100644 --- a/lib/libc/sys/Symbol.map +++ b/lib/libc/sys/Symbol.map @@ -364,7 +364,6 @@ FBSD_1.2 { cap_enter; cap_getmode; cap_new; - cap_getrights; getloginclass; pdfork; pdgetpid; @@ -379,7 +378,17 @@ FBSD_1.2 { }; FBSD_1.3 { + bindat; + cap_fcntls_get; + cap_fcntls_limit; + cap_ioctls_get; + cap_ioctls_limit; + cap_rights_get; + cap_rights_limit; + cap_sandboxed; + chflagsat; clock_getcpuclockid2; + connectat; ffclock_getcounter; ffclock_getestimate; ffclock_setestimate; diff --git a/lib/libc/sys/accept.2 b/lib/libc/sys/accept.2 index df6c0b1..978b948 100644 --- a/lib/libc/sys/accept.2 +++ b/lib/libc/sys/accept.2 @@ -28,7 +28,7 @@ .\" @(#)accept.2 8.2 (Berkeley) 12/11/93 .\" $FreeBSD$ .\" -.Dd December 11, 1993 +.Dd March 26, 2013 .Dt ACCEPT 2 .Os .Sh NAME @@ -57,7 +57,13 @@ queue of pending connections, creates a new socket, and allocates a new file descriptor for the socket which inherits the state of the .Dv O_NONBLOCK -property from the original socket +and +.Dv O_ASYNC +properties and the destination of +.Dv SIGIO +and +.Dv SIGURG +signals from the original socket .Fa s . .Pp If no pending connections are @@ -129,7 +135,11 @@ to pre-process incoming connections. .Pp Portable programs should not rely on the .Dv O_NONBLOCK -property being inherited. +and +.Dv O_ASYNC +properties and the signal destination being inherited, +but should set them explicitly using +.Xr fcntl 2 . .Sh RETURN VALUES The call returns \-1 on error. If it succeeds, it returns a non-negative diff --git a/lib/libc/sys/bindat.2 b/lib/libc/sys/bindat.2 new file mode 100644 index 0000000..9274679 --- /dev/null +++ b/lib/libc/sys/bindat.2 @@ -0,0 +1,109 @@ +.\" Copyright (c) 2013 The FreeBSD Foundation +.\" All rights reserved. +.\" +.\" This documentation was written by Pawel Jakub Dawidek under sponsorship from +.\" the FreeBSD Foundation. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd February 13, 2013 +.Dt BINDAT 2 +.Os +.Sh NAME +.Nm bindat +.Nd assign a local protocol address to a socket +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.Pp +.In fcntl.h +.Ft int +.Fn bindat "int fd" "int s" "const struct sockaddr *addr" "socklen_t addrlen" +.Sh DESCRIPTION +The +.Fn bindat +system call assigns the local protocol address to a socket. +It works just like the +.Xr bind 2 +system call with two exceptions: +.Pp +.Bl -enum -offset indent -compact +.It +It is limited to sockets in the PF_LOCAL domain. +.Pp +.It +If the file path stored in the +.Fa sun_path +field of the sockaddr_un structure is a relative path, it is located relative +to the directory associated with the file descriptor +.Fa fd . +If +.Fn bindat +is passed the special value +.Dv AT_FDCWD +in the +.Fa fd +parameter, the current working directory is used and the behavior is identical +to a call to +.Xr bind 2 . +.El +.Sh RETURN VALUES +.Rv -std bindat +.Sh ERRORS +The +.Fn bindat +system call may fail with the same errors as the +.Xr bind 2 +system call for a UNIX domain socket or with the following errors: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa sun_path +field does not specify an absolute path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa sun_path +field is not an absolute path and +.Fa fd +is neither +.Dv AT_FDCWD +nor a file descriptor associated with a directory. +.El +.Sh SEE ALSO +.Xr bind 2 , +.Xr connectat 2 , +.Xr socket 2 , +.Xr unix 4 +.Sh AUTHORS +The +.Nm +was developed by +.An Pawel Jakub Dawidek Aq pawel@dawidek.net +under sponsorship from the FreeBSD Foundation. diff --git a/lib/libc/sys/cap_enter.2 b/lib/libc/sys/cap_enter.2 index 5454ec9..3369669 100644 --- a/lib/libc/sys/cap_enter.2 +++ b/lib/libc/sys/cap_enter.2 @@ -58,8 +58,10 @@ or .Xr pdfork 2 will be placed in capability mode from inception. .Pp -When combined with capabilities created with -.Xr cap_new 2 , +When combined with +.Xr cap_rights_limit 2 , +.Xr cap_ioctls_limit 2 , +.Xr cap_fcntls_limit 2 , .Fn cap_enter may be used to create kernel-enforced sandboxes in which appropriately-crafted applications or application components may be run. @@ -71,11 +73,6 @@ sandbox. Creating effective process sandboxes is a tricky process that involves identifying the least possible rights required by the process and then passing those rights into the process in a safe manner. -See the CAVEAT -section of -.Xr cap_new 2 -for why this is particularly tricky with UNIX file descriptors as the -canonical representation of a right. Consumers of .Fn cap_enter should also be aware of other inherited rights, such as access to VM @@ -87,9 +84,35 @@ to create a runtime environment inside the sandbox that has as few implicitly acquired rights as possible. .Sh RETURN VALUES .Rv -std cap_enter cap_getmode +.Sh ERRORS +The +.Fn cap_enter +and +.Fn cap_getmode +system calls +will fail if: +.Bl -tag -width Er +.It Bq Er ENOSYS +The kernel is compiled without: +.Pp +.Cd "options CAPABILITY_MODE" +.El +.Pp +The +.Fn cap_getmode +system call may also return the following error: +.Bl -tag -width Er +.It Bq Er EFAULT +Pointer +.Fa modep +points outside the process's allocated address space. +.El .Sh SEE ALSO -.Xr cap_new 2 , +.Xr cap_fcntls_limit 2 , +.Xr cap_ioctls_limit 2 , +.Xr cap_rights_limit 2 , .Xr fexecve 2 , +.Xr cap_sandboxed 3 , .Xr capsicum 4 .Sh HISTORY Support for capabilities and capabilities mode was developed as part of the diff --git a/lib/libc/sys/cap_fcntls_limit.2 b/lib/libc/sys/cap_fcntls_limit.2 new file mode 100644 index 0000000..b1fca2c --- /dev/null +++ b/lib/libc/sys/cap_fcntls_limit.2 @@ -0,0 +1,126 @@ +.\" +.\" Copyright (c) 2012 The FreeBSD Foundation +.\" All rights reserved. +.\" +.\" This documentation was written by Pawel Jakub Dawidek under sponsorship +.\" the FreeBSD Foundation. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 20, 2012 +.Dt CAP_FCNTLS_LIMIT 2 +.Os +.Sh NAME +.Nm cap_fcntls_limit , +.Nm cap_fcntls_get +.Nd manage allowed fcntl commands +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/capability.h +.Ft int +.Fn cap_fcntls_limit "int fd" "uint32_t fcntlrights" +.Ft int +.Fn cap_fcntls_get "int fd" "uint32_t *fcntlrightsp" +.Sh DESCRIPTION +If a file descriptor is granted the +.Dv CAP_FCNTL +capability right, the list of allowed +.Xr fcntl 2 +commands can be selectively reduced (but never expanded) with the +.Fn cap_fcntls_limit +system call. +.Pp +A bitmask of allowed fcntls commands for a given file descriptor can be obtained +with the +.Fn cap_fcntls_get +system call. +.Sh FLAGS +The following flags may be specified in the +.Fa fcntlrights +argument or returned in the +.Fa fcntlrightsp +argument: +.Bl -tag -width CAP_FCNTL_GETOWN +.It Dv CAP_FCNTL_GETFL +Permit +.Dv F_GETFL +command. +.It Dv CAP_FCNTL_SETFL +Permit +.Dv F_SETFL +command. +.It Dv CAP_FCNTL_GETOWN +Permit +.Dv F_GETOWN +command. +.It Dv CAP_FCNTL_SETOWN +Permit +.Dv F_SETOWN +command. +.El +.Sh RETURN VALUES +.Rv -std +.Sh ERRORS +.Fn cap_fcntls_limit +succeeds unless: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument is not a valid descriptor. +.It Bq Er EINVAL +An invalid flag has been passed in +.Fa fcntlrights . +.It Bq Er ENOTCAPABLE +.Fa fcntlrights +would expand the list of allowed +.Xr fcntl 2 +commands. +.El +.Pp +.Fn cap_fcntls_get +succeeds unless: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument is not a valid descriptor. +.It Bq Er EFAULT +The +.Fa fcntlrightsp +argument points at an invalid address. +.El +.Sh SEE ALSO +.Xr cap_ioctls_limit 2 , +.Xr cap_rights_limit 2 , +.Xr fcntl 2 +.Sh HISTORY +Support for capabilities and capabilities mode was developed as part of the +.Tn TrustedBSD +Project. +.Sh AUTHORS +This function was created by +.An Pawel Jakub Dawidek Aq pawel@dawidek.net +under sponsorship of the FreeBSD Foundation. diff --git a/lib/libc/sys/cap_ioctls_limit.2 b/lib/libc/sys/cap_ioctls_limit.2 new file mode 100644 index 0000000..2c21211 --- /dev/null +++ b/lib/libc/sys/cap_ioctls_limit.2 @@ -0,0 +1,157 @@ +.\" +.\" Copyright (c) 2012 The FreeBSD Foundation +.\" All rights reserved. +.\" +.\" This documentation was written by Pawel Jakub Dawidek under sponsorship +.\" the FreeBSD Foundation. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 20, 2012 +.Dt CAP_IOCTLS_LIMIT 2 +.Os +.Sh NAME +.Nm cap_ioctls_limit , +.Nm cap_ioctls_get +.Nd manage allowed ioctl commands +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/capability.h +.Ft int +.Fn cap_ioctls_limit "int fd" "const unsigned long *cmds" "size_t ncmds" +.Ft ssize_t +.Fn cap_ioctls_get "int fd" "unsigned long *cmds" "size_t maxcmds" +.Sh DESCRIPTION +If a file descriptor is granted the +.Dv CAP_IOCTL +capability right, the list of allowed +.Xr ioctl 2 +commands can be selectively reduced (but never expanded) with the +.Fn cap_ioctls_limit +system call. +The +.Fa cmds +argument is an array of +.Xr ioctl 2 +commands and the +.Fa ncmds +argument specifies the number of elements in the array. +There might be up to +.Va 256 +elements in the array. +.Pp +The list of allowed ioctl commands for a given file descriptor can be obtained +with the +.Fn cap_ioctls_get +system call. +The +.Fa cmds +argument points at memory that can hold up to +.Fa maxcmds +values. +The function populates the provided buffer with up to +.Fa maxcmds +elements, but always returns the total number of ioctl commands allowed for the +given file descriptor. +The total number of ioctls commands for the given file descriptor can be +obtained by passing +.Dv NULL as the +.Fa cmds +argument and +.Va 0 +as the +.Fa maxcmds +argument. +If all ioctl commands are allowed +.Dv ( CAP_IOCTL +capability right is assigned to the file descriptor and the +.Fn cap_ioctls_limit +system call was never called for this file descriptor), the +.Fn cap_ioctls_get +system call will return +.Dv CAP_IOCTLS_ALL +and won't modify the buffer pointed out by the +.Fa cmds +argument. +.Sh RETURN VALUES +.Rv -std cap_ioctls_limit +.Pp +The +.Fn cap_ioctls_limit +function, if successfull, returns the total number of allowed ioctl commands or +the value +.Dv INT_MAX +if all ioctls commands are allowed. +On failure the value +.Va -1 +is returned and the global variable errno is set to indicate the error. +.Sh ERRORS +.Fn cap_ioctls_limit +succeeds unless: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument is not a valid descriptor. +.It Bq Er EFAULT +The +.Fa cmds +argument points at an invalid address. +.It Bq Er EINVAL +The +.Fa ncmds +argument is greater than +.Va 256 . +.It Bq Er ENOTCAPABLE +.Fa cmds +would expand the list of allowed +.Xr ioctl 2 +commands. +.El +.Pp +.Fn cap_ioctls_get +succeeds unless: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa fd +argument is not a valid descriptor. +.It Bq Er EFAULT +The +.Fa cmds +argument points at invalid address. +.El +.Sh SEE ALSO +.Xr cap_fcntls_limit 2 , +.Xr cap_rights_limit 2 , +.Xr ioctl 2 +.Sh HISTORY +Support for capabilities and capabilities mode was developed as part of the +.Tn TrustedBSD +Project. +.Sh AUTHORS +This function was created by +.An Pawel Jakub Dawidek Aq pawel@dawidek.net +under sponsorship of the FreeBSD Foundation. diff --git a/lib/libc/sys/cap_new.2 b/lib/libc/sys/cap_rights_limit.2 index a18fd3b..2e18dd2 100644 --- a/lib/libc/sys/cap_new.2 +++ b/lib/libc/sys/cap_rights_limit.2 @@ -1,10 +1,14 @@ .\" .\" Copyright (c) 2008-2010 Robert N. M. Watson +.\" Copyright (c) 2012-2013 The FreeBSD Foundation .\" All rights reserved. .\" .\" This software was developed at the University of Cambridge Computer .\" Laboratory with support from a grant from Google, Inc. .\" +.\" Portions of this documentation were written by Pawel Jakub Dawidek +.\" under sponsorship from the FreeBSD Foundation. +.\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: @@ -28,76 +32,48 @@ .\" .\" $FreeBSD$ .\" -.Dd July 20, 2011 -.Dt CAP_NEW 2 +.Dd February 23, 2013 +.Dt CAP_RIGHTS_LIMIT 2 .Os .Sh NAME -.Nm cap_new , -.Nm cap_getrights -.Nd System calls to manipulate capabilities +.Nm cap_rights_limit , +.Nm cap_rights_get +.Nd manage capability rights .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In sys/capability.h .Ft int -.Fn cap_new "int fd" "cap_rights_t rights" +.Fn cap_rights_limit "int fd" "cap_rights_t rights" .Ft int -.Fn cap_getrights "int fd" "cap_rights_t *rightsp" +.Fn cap_rights_get "int fd" "cap_rights_t *rightsp" .Sh DESCRIPTION -Capabilities are special file descriptors derived from an existing file -descriptor, such as one returned by +When a file descriptor is created by a function such as .Xr fhopen 2 , .Xr kqueue 2 , .Xr mq_open 2 , .Xr open 2 , +.Xr openat 2 , +.Xr pdfork 2 , .Xr pipe 2 , .Xr shm_open 2 , .Xr socket 2 , or .Xr socketpair 2 , -but with a restricted set of permitted operations determined by a rights -mask set when the capability is created. -These restricted rights cannot be changed after the capability is created, -although further capabilities with yet more restricted rights may be created -from an existing capability. -In every other sense, a capability behaves in the same way as the file -descriptor it was created from. -.Pp -.Fn cap_new -creates a new capability for the existing file descriptor -.Fa fd , -and returns a file descriptor for it. -Operations on the capability will be limited to those permitted by -.Fa rights , -which is static for the lifetime of the capability. -If -.Fa fd -refers to an existing capability, then -.Fa rights -must be equal to or a subset of the rights on that capability. -As with -.Xr dup 2 -and -.Xr dup2 2 , -many properties are shared between the new capability and the existing file -descriptor, including open file flags, blocking disposition, and file offset. -Many applications will prefer to use the -.Xr cap_limitfd 3 -library call, part of -.Xr libcapsicum 3 , -as it offers a more convenient interface. -.Pp -.Fn cap_getrights -queries the rights associated with the capability referred to by file -descriptor -.Fa fd . +it is assigned all capability rights. +Those rights can be reduced (but never expanded) by using the +.Fn cap_rights_limit +system call. +Once capability rights are reduced, operations on the file descriptor will be +limited to those permitted by +.Fa rights . .Pp -These system calls, when combined with -.Xr cap_enter 2 , -may be used to construct process sandboxes with highly granular rights -assignment. +A bitmask of capability rights assigned to a file descriptor can be obtained with +the +.Fn cap_rights_get +system call. .Sh RIGHTS -The following rights may be specified in a new capability rights mask: +The following rights may be specified in a rights mask: .Bl -tag -width CAP_EXTATTR_DELETE .It Dv CAP_ACCEPT Permit @@ -128,12 +104,27 @@ or and that socket options set with .Xr setsockopt 2 may also affect binding behavior. +.It Dv CAP_BINDAT +Permit +.Xr bindat 2 . +This right has to be present on the directory descriptor. .It Dv CAP_CONNECT Permit .Xr connect 2 ; also required for .Xr sendto 2 with a non-NULL destination address. +.It Dv CAP_CONNECTAT +Permit +.Xr connectat 2 . +This right has to be present on the directory descriptor. +.It Dv CAP_CREATE +Permit +.Xr openat 2 +with the +.Dv O_CREAT +flag. +.\" XXXPJD: Doesn't exist anymore. .It Dv CAP_EVENT Permit .Xr select 2 , @@ -143,7 +134,12 @@ and to be used in monitoring the file descriptor for events. .It Dv CAP_FEXECVE Permit -.Xr fexecve 2 ; +.Xr fexecve 2 +and +.Xr openat 2 +with the +.Dv O_EXEC +flag; .Dv CAP_READ will also be required. .It Dv CAP_EXTATTR_DELETE @@ -163,22 +159,57 @@ Permit .Xr fchdir 2 . .It Dv CAP_FCHFLAGS Permit -.Xr fchflags 2 . +.Xr fchflags 2 +and +.Xr chflagsat 2 . +.It Dv CAP_CHFLAGSAT +An alias to +.Dv CAP_FCHFLAGS . .It Dv CAP_FCHMOD Permit -.Xr fchmod 2 . +.Xr fchmod 2 +and +.Xr fchmodat 2 . +.It Dv CAP_FCHMODAT +An alias to +.Dv CAP_FCHMOD . .It Dv CAP_FCHOWN Permit -.Xr fchown 2 . +.Xr fchown 2 +and +.Xr fchownat 2 . +.It Dv CAP_FCHOWNAT +An alias to +.Dv CAP_FCHOWN . .It Dv CAP_FCNTL Permit -.Xr fcntl 2 ; -be aware that this call provides indirect access to other operations, such as -.Xr flock 2 . +.Xr fcntl 2 . +Note that only the +.Dv F_GETFL , +.Dv F_SETFL , +.Dv F_GETOWN +and +.Dv F_SETOWN +commands require this capability right. +Also note that the list of permitted commands can be further limited with the +.Xr cap_fcntls_limit 2 +system call. .It Dv CAP_FLOCK Permit -.Xr flock 2 -and related calls. +.Xr flock 2 , +.Xr fcntl 2 +(with +.Dv F_GETLK , +.Dv F_SETLK +or +.Dv F_SETLKW +flag) and +.Xr openat 2 +(with +.Dv O_EXLOCK +or +.Dv O_SHLOCK +flag). .It Dv CAP_FPATHCONF Permit .Xr fpathconf 2 . @@ -186,22 +217,42 @@ Permit Permit UFS background-fsck operations on the descriptor. .It Dv CAP_FSTAT Permit -.Xr fstat 2 . +.Xr fstat 2 +and +.Xr fstatat 2 . +.It Dv CAP_FSTATAT +An alias to +.Dv CAP_FSTAT . .It Dv CAP_FSTATFS Permit .Xr fstatfs 2 . .It Dv CAP_FSYNC Permit -.Xr aio_fsync 2 +.Xr aio_fsync 2 , +.Xr fsync 2 and -.Xr fsync 2 . -.Pp +.Xr openat 2 +with +.Dv O_FSYNC +or +.Dv O_SYNC +flag. .It Dv CAP_FTRUNCATE Permit -.Xr ftruncate 2 . +.Xr ftruncate 2 +and +.Xr openat 2 +with the +.Dv O_TRUNC +flag. .It Dv CAP_FUTIMES Permit -.Xr futimes 2 . +.Xr futimes 2 +and +.Xr futimesat 2 . +.It Dv CAP_FUTIMESAT +An alias to +.Dv CAP_FUTIMES . .It Dv CAP_GETPEERNAME Permit .Xr getpeername 2 . @@ -216,42 +267,106 @@ Permit .Xr ioctl 2 . Be aware that this system call has enormous scope, including potentially global scope for some objects. +The list of permitted ioctl commands can be further limited with the +.Xr cap_ioctls_limit 2 +system call. +.\" XXXPJD: Doesn't exist anymore. .It Dv CAP_KEVENT Permit .Xr kevent 2 ; .Dv CAP_EVENT is also required on file descriptors that will be monitored using .Xr kevent 2 . +.It Dv CAP_LINKAT +Permit +.Xr linkat 2 +and +.Xr renameat 2 . +This right is required for the destination directory descriptor. .It Dv CAP_LISTEN Permit .Xr listen 2 ; not much use (generally) without .Dv CAP_BIND . .It Dv CAP_LOOKUP -Permit the file descriptor to be used as a starting directory for calls such -as +Permit the file descriptor to be used as a starting directory for calls such as .Xr linkat 2 , .Xr openat 2 , and .Xr unlinkat 2 . -Note that these calls are not available in capability mode as they manipulate -a global name space; see -.Xr cap_enter 2 -for details. .It Dv CAP_MAC_GET Permit .Xr mac_get_fd 3 . .It Dv CAP_MAC_SET Permit .Xr mac_set_fd 3 . +.It Dv CAP_MKDIRAT +Permit +.Xr mkdirat 2 . +.It Dv CAP_MKFIFOAT +Permit +.Xr mkfifoat 2 . +.It Dv CAP_MKNODAT +Permit +.Xr mknodat 2 . .It Dv CAP_MMAP Permit -.Xr mmap 2 ; -specific invocations may also require +.Xr mmap 2 +with the +.Dv PROT_NONE +protection. +.It Dv CAP_MMAP_R +Permit +.Xr mmap 2 +with the +.Dv PROT_READ +protection. +This also implies .Dv CAP_READ -or -.Dv CAP_WRITE . -.Pp +and +.Dv CAP_SEEK +rights. +.It Dv CAP_MMAP_W +Permit +.Xr mmap 2 +with the +.Dv PROT_WRITE +protection. +This also implies +.Dv CAP_WRITE +and +.Dv CAP_SEEK +rights. +.It Dv CAP_MMAP_X +Permit +.Xr mmap 2 +with the +.Dv PROT_EXEC +protection. +This also implies +.Dv CAP_SEEK +right. +.It Dv CAP_MMAP_RW +Implies +.Dv CAP_MMAP_R +and +.Dv CAP_MMAP_W . +.It Dv CAP_MMAP_RX +Implies +.Dv CAP_MMAP_R +and +.Dv CAP_MMAP_X . +.It Dv CAP_MMAP_WX +Implies +.Dv CAP_MMAP_W +and +.Dv CAP_MMAP_X . +.It Dv CAP_MMAP_RWX +Implies +.Dv CAP_MMAP_R , +.Dv CAP_MMAP_W +and +.Dv CAP_MMAP_X . .It Dv CAP_PDGETPID Permit .Xr pdgetpid 2 . @@ -264,30 +379,46 @@ Permit .It Dv CAP_PEELOFF Permit .Xr sctp_peeloff 2 . +.\" XXXPJD: Not documented. +.It Dv CAP_POLL_EVENT +.\" XXXPJD: Not documented. +.It Dv CAP_POST_EVENT +.It Dv CAP_PREAD +Implies +.Dv CAP_SEEK +and +.Dv CAP_READ . +.It Dv CAP_PWRITE +Implies +.Dv CAP_SEEK +and +.Dv CAP_WRITE . .It Dv CAP_READ Allow .Xr aio_read 2 , -.Xr pread 2 , +.Xr openat +with the +.Dv O_RDONLY flag, .Xr read 2 , .Xr recv 2 , .Xr recvfrom 2 , -.Xr recvmsg 2 , +.Xr recvmsg 2 and related system calls. -.Pp -For files and other seekable objects, -.Dv CAP_SEEK -may also be required. -.It Dv CAP_REVOKE +.It Dv CAP_RECV +An alias to +.Dv CAP_READ . +.It Dv CAP_RENAMEAT Permit -.Xr frevoke 2 -in certain ABI compatibility modes that support this system call. +.Xr renameat 2 . +This right is required for the source directory descriptor. .It Dv CAP_SEEK Permit operations that seek on the file descriptor, such as .Xr lseek 2 , -but also required for I/O system calls that modify the file offset, such as -.Xr read 2 +but also required for I/O system calls that can read or write at any position +in the file, such as +.Xr pread 2 and -.Xr write 2 . +.Xr pwrite 2 . .It Dv CAP_SEM_GETVALUE Permit .Xr sem_getvalue 3 . @@ -299,6 +430,9 @@ Permit .Xr sem_wait 3 and .Xr sem_trywait 3 . +.It Dv CAP_SEND +An alias to +.Dv CAP_WRITE . .It Dv CAP_SETSOCKOPT Permit .Xr setsockopt 2 ; @@ -308,49 +442,56 @@ connecting, and other behaviors with global scope. Permit explicit .Xr shutdown 2 ; closing the socket will also generally shut down any connections on it. +.It Dv CAP_SYMLINKAT +Permit +.Xr symlinkat 2 . .It Dv CAP_TTYHOOK Allow configuration of TTY hooks, such as .Xr snp 4 , on the file descriptor. +.It Dv CAP_UNLINKAT +Permit +.Xr unlinkat 2 +and +.Xr renameat 2 . +This right is only required for +.Xr renameat 2 +on the destination directory descriptor if the destination object already +exists and will be removed by the rename. .It Dv CAP_WRITE Allow .Xr aio_write 2 , -.Xr pwrite 2 , +.Xr openat 2 +with +.Dv O_WRONLY +and +.Dv O_APPEND +flags, .Xr send 2 , .Xr sendmsg 2 , .Xr sendto 2 , .Xr write 2 , and related system calls. -.Pp -For files and other seekable objects, -.Dv CAP_SEEK -may also be required. -.Pp For .Xr sendto 2 with a non-NULL connection address, .Dv CAP_CONNECT is also required. +For +.Xr openat 2 +with the +.Dv O_WRONLY +flag, but without the +.Dv O_APPEND +flag, +.Dv CAP_SEEK +is also required. .El -.Sh CAVEAT -The -.Fn cap_new -system call and the capabilities it creates may be used to assign -fine-grained rights to sandboxed processes running in capability mode. -However, the semantics of objects accessed via file descriptors are complex, -so caution should be exercised in passing object capabilities into sandboxes. .Sh RETURN VALUES -If successful, -.Fn cap_new -returns a non-negative integer, termed a file descriptor. -It returns -1 on failure, and sets -.Va errno -to indicate the error. -.Pp -.Rv -std cap_getrights +.Rv -std .Sh ERRORS -.Fn cap_new -may return the following errors: +.Fn cap_rights_limit +succeeds unless: .Bl -tag -width Er .It Bq Er EBADF The @@ -359,29 +500,23 @@ argument is not a valid active descriptor. .It Bq Er EINVAL An invalid right has been requested in .Fa rights . -.It Bq Er EMFILE -The process has already reached its limit for open file descriptors. -.It Bq Er ENFILE -The system file table is full. -.It Bq Er EPERM +.It Bq Er ENOTCAPABLE .Fa rights contains requested rights not present in the current rights mask associated -with the capability referenced by -.Fa fd , -if any. +with the given file descriptor. .El .Pp -.Fn cap_getrights -may return the following errors: +.Fn cap_rights_get +succeeds unless: .Bl -tag -width Er .It Bq Er EBADF The .Fa fd argument is not a valid active descriptor. -.It Bq Er EINVAL +.It Bq Er EFAULT The -.Fa fd -argument is not a capability. +.Fa rightsp +argument points at an invalid address. .El .Sh SEE ALSO .Xr accept 2 , @@ -389,8 +524,13 @@ argument is not a capability. .Xr aio_read 2 , .Xr aio_write 2 , .Xr bind 2 , +.Xr bindat 2 , .Xr cap_enter 2 , +.Xr cap_fcntls_limit 2 , +.Xr cap_ioctls_limit 2 , +.Xr cap_rights_limit 2 , .Xr connect 2 , +.Xr connectat 2 , .Xr dup 2 , .Xr dup2 2 , .Xr extattr_delete_fd 2 , @@ -421,6 +561,7 @@ argument is not a capability. .Xr mq_open 2 , .Xr open 2 , .Xr openat 2 , +.Xr pdfork 2 , .Xr pdgetpid 2 , .Xr pdkill 2 , .Xr pdwait4 2 , @@ -432,6 +573,7 @@ argument is not a capability. .Xr recv 2 , .Xr recvfrom 2 , .Xr recvmsg 2 , +.Xr renameat 2 , .Xr sctp_peeloff 2 , .Xr select 2 , .Xr send 2 , @@ -442,6 +584,7 @@ argument is not a capability. .Xr shutdown 2 , .Xr socket 2 , .Xr socketpair 2 , +.Xr symlinkat 2 , .Xr unlinkat 2 , .Xr write 2 , .Xr acl_delete_fd_np 3 , @@ -463,10 +606,9 @@ Support for capabilities and capabilities mode was developed as part of the .Tn TrustedBSD Project. .Sh AUTHORS -These functions and the capability facility were created by -.An "Robert N. M. Watson" -at the University of Cambridge Computer Laboratory with support from a grant -from Google, Inc. +This function was created by +.An Pawel Jakub Dawidek Aq pawel@dawidek.net +under sponsorship of the FreeBSD Foundation. .Sh BUGS This man page should list the set of permitted system calls more specifically for each capability right. diff --git a/lib/libc/sys/chflags.2 b/lib/libc/sys/chflags.2 index 1c2eb78..5bc2ba2 100644 --- a/lib/libc/sys/chflags.2 +++ b/lib/libc/sys/chflags.2 @@ -28,7 +28,7 @@ .\" @(#)chflags.2 8.3 (Berkeley) 5/2/95 .\" $FreeBSD$ .\" -.Dd Apr 13, 2012 +.Dd March 22, 2013 .Dt CHFLAGS 2 .Os .Sh NAME @@ -42,11 +42,13 @@ .In sys/stat.h .In unistd.h .Ft int -.Fn chflags "const char *path" "u_long flags" +.Fn chflags "const char *path" "unsigned long flags" .Ft int -.Fn lchflags "const char *path" "int flags" +.Fn lchflags "const char *path" "unsigned long flags" .Ft int -.Fn fchflags "int fd" "u_long flags" +.Fn fchflags "int fd" "unsigned long flags" +.Ft int +.Fn chflagsat "int fd" "const char *path" "unsigned long flags" "int atflag" .Sh DESCRIPTION The file whose name is given by @@ -66,6 +68,45 @@ in which case will change the flags of the link itself, rather than the file it points to. .Pp +The +.Fn chflagsat +is equivalent to either +.Fn chflags +or +.Fn lchflags +depending on the +.Fa atflag +except in the case where +.Fa path +specifies a relative path. +In this case the file to be changed is determined relative to the directory +associated with the file descriptor +.Fa fd +instead of the current working directory. +The values for the +.Fa atflag +are constructed by a bitwise-inclusive OR of flags from the following list, +defined in +.In fcntl.h : +.Bl -tag -width indent +.It Dv AT_SYMLINK_NOFOLLOW +If +.Fa path +names a symbolic link, then the flags of the symbolic link are changed. +.El +.Pp +If +.Fn chflagsat +is passed the special value +.Dv AT_FDCWD +in the +.Fa fd +parameter, the current working directory is used. +If also +.Fa atflag +is zero, the behavior is identical to a call to +.Fn chflags . +.Pp The flags specified are formed by .Em or Ns 'ing the following values @@ -98,7 +139,7 @@ If one of or .Dv SF_NOUNLINK is set a non-super-user cannot change any flags and even the super-user -can change flags only if securelevel is greater than 0. +can change flags only if securelevel is 0. (See .Xr init 8 for details.) @@ -232,3 +273,11 @@ and .Fn fchflags system calls first appeared in .Bx 4.4 . +The +.Fn lchflags +system call first appeared in +.Fx 5.0 . +The +.Fn chflagsat +system call first appeared in +.Fx 10.0 . diff --git a/lib/libc/sys/connectat.2 b/lib/libc/sys/connectat.2 new file mode 100644 index 0000000..8cebf98 --- /dev/null +++ b/lib/libc/sys/connectat.2 @@ -0,0 +1,109 @@ +.\" Copyright (c) 2013 The FreeBSD Foundation +.\" All rights reserved. +.\" +.\" This documentation was written by Pawel Jakub Dawidek under sponsorship from +.\" the FreeBSD Foundation. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd February 13, 2013 +.Dt CONNECTAT 2 +.Os +.Sh NAME +.Nm connectat +.Nd initiate a connection on a socket +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/socket.h +.Pp +.In fcntl.h +.Ft int +.Fn connectat "int fd" "int s" "const struct sockaddr *name" "socklen_t namelen" +.Sh DESCRIPTION +The +.Fn connectat +system call initiates a connection on a socket. +It works just like the +.Xr connect 2 +system call with two exceptions: +.Pp +.Bl -enum -offset indent -compact +.It +It is limited to sockets in the PF_LOCAL domain. +.Pp +.It +If the file path stored in the +.Fa sun_path +field of the sockaddr_un structure is a relative path, it is located relative +to the directory associated with the file descriptor +.Fa fd . +If +.Fn connectat +is passed the special value +.Dv AT_FDCWD +in the +.Fa fd +parameter, the current working directory is used and the behavior is identical +to a call to +.Xr connect 2 . +.El +.Sh RETURN VALUES +.Rv -std connectat +.Sh ERRORS +The +.Fn connectat +system call may fail with the same errors as the +.Xr connect 2 +system call for a UNIX domain socket or with the following errors: +.Bl -tag -width Er +.It Bq Er EBADF +The +.Fa sun_path +field does not specify an absolute path and the +.Fa fd +argument is neither +.Dv AT_FDCWD +nor a valid file descriptor. +.It Bq Er ENOTDIR +The +.Fa sun_path +field is not an absolute path and +.Fa fd +is neither +.Dv AT_FDCWD +nor a file descriptor associated with a directory. +.El +.Sh SEE ALSO +.Xr bindat 2 , +.Xr connect 2 , +.Xr socket 2 , +.Xr unix 4 +.Sh AUTHORS +The +.Nm +was developed by +.An Pawel Jakub Dawidek Aq pawel@dawidek.net +under sponsorship from the FreeBSD Foundation. diff --git a/lib/libc/sys/dup.2 b/lib/libc/sys/dup.2 index 7a07c21..6e1de20 100644 --- a/lib/libc/sys/dup.2 +++ b/lib/libc/sys/dup.2 @@ -115,11 +115,6 @@ and is a valid descriptor, then .Fn dup2 is successful, and does nothing. -.Pp -The related -.Xr cap_new 2 -system call allows file descriptors to be duplicated with restrictions on -their use. .Sh RETURN VALUES The value -1 is returned if an error occurs in either call. The external variable @@ -152,7 +147,6 @@ argument is negative or exceeds the maximum allowable descriptor number .El .Sh SEE ALSO .Xr accept 2 , -.Xr cap_new 2 , .Xr close 2 , .Xr fcntl 2 , .Xr getdtablesize 2 , diff --git a/lib/libc/sys/extattr_get_file.2 b/lib/libc/sys/extattr_get_file.2 index e8faa13..db4ea92 100644 --- a/lib/libc/sys/extattr_get_file.2 +++ b/lib/libc/sys/extattr_get_file.2 @@ -50,7 +50,7 @@ .In sys/extattr.h .Ft ssize_t .Fn extattr_get_fd "int fd" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes" -.Ft int +.Ft ssize_t .Fn extattr_set_fd "int fd" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes" .Ft int .Fn extattr_delete_fd "int fd" "int attrnamespace" "const char *attrname" @@ -58,7 +58,7 @@ .Fn extattr_list_fd "int fd" "int attrnamespace" "void *data" "size_t nbytes" .Ft ssize_t .Fn extattr_get_file "const char *path" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes" -.Ft int +.Ft ssize_t .Fn extattr_set_file "const char *path" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes" .Ft int .Fn extattr_delete_file "const char *path" "int attrnamespace" "const char *attrname" @@ -66,7 +66,7 @@ .Fn extattr_list_file "const char *path" "int attrnamespace" "void *data" "size_t nbytes" .Ft ssize_t .Fn extattr_get_link "const char *path" "int attrnamespace" "const char *attrname" "void *data" "size_t nbytes" -.Ft int +.Ft ssize_t .Fn extattr_set_link "const char *path" "int attrnamespace" "const char *attrname" "const void *data" "size_t nbytes" .Ft int .Fn extattr_delete_link "const char *path" "int attrnamespace" "const char *attrname" diff --git a/lib/libc/sys/fcntl.2 b/lib/libc/sys/fcntl.2 index c174563..8e0ca73 100644 --- a/lib/libc/sys/fcntl.2 +++ b/lib/libc/sys/fcntl.2 @@ -28,7 +28,7 @@ .\" @(#)fcntl.2 8.2 (Berkeley) 1/12/94 .\" $FreeBSD$ .\" -.Dd July 27, 2012 +.Dd February 8, 2013 .Dt FCNTL 2 .Os .Sh NAME @@ -171,7 +171,7 @@ argument, which is rounded up to the nearest block size. A zero value in .Fa arg -turns off read ahead. +turns off read ahead, a negative value restores the system default. .It Dv F_RDAHEAD Equivalent to Darwin counterpart which sets read ahead amount of 128KB when the third argument, diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 index 1e0d3f91..5c68698b 100644 --- a/lib/libc/sys/getsockopt.2 +++ b/lib/libc/sys/getsockopt.2 @@ -28,7 +28,7 @@ .\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95 .\" $FreeBSD$ .\" -.Dd February 26, 2012 +.Dd April 5, 2013 .Dt GETSOCKOPT 2 .Os .Sh NAME @@ -437,7 +437,7 @@ The .Vt cmsghdr fields have the following values for TIMESTAMP: .Bd -literal - cmsg_len = sizeof(struct timeval); + cmsg_len = CMSG_LEN(sizeof(struct timeval)); cmsg_level = SOL_SOCKET; cmsg_type = SCM_TIMESTAMP; .Ed @@ -445,7 +445,7 @@ fields have the following values for TIMESTAMP: and for .Dv SO_BINTIME : .Bd -literal - cmsg_len = sizeof(struct bintime); + cmsg_len = CMSG_LEN(sizeof(struct bintime)); cmsg_level = SOL_SOCKET; cmsg_type = SCM_BINTIME; .Ed diff --git a/lib/libc/sys/mlock.2 b/lib/libc/sys/mlock.2 index 0e5fef8..42acc97 100644 --- a/lib/libc/sys/mlock.2 +++ b/lib/libc/sys/mlock.2 @@ -28,7 +28,7 @@ .\" @(#)mlock.2 8.2 (Berkeley) 12/11/93 .\" $FreeBSD$ .\" -.Dd December 25, 2012 +.Dd March 18, 2013 .Dt MLOCK 2 .Os .Sh NAME @@ -138,7 +138,12 @@ is set to 0 and the caller is not the super-user. .It Bq Er EINVAL The address given is not page aligned or the length is negative. .It Bq Er ENOMEM -Some portion of the indicated address range is not allocated. +Some or all of the address range specified by the addr and len +arguments does not correspond to valid mapped pages in the address space +of the process. +.It Bq Er ENOMEM +Locking the pages mapped by the specified range would exceed a limit on +the amount of memory that the process may lock. .El .Sh "SEE ALSO" .Xr fork 2 , diff --git a/lib/libc/sys/posix_openpt.2 b/lib/libc/sys/posix_openpt.2 index 2633847..9ba2606 100644 --- a/lib/libc/sys/posix_openpt.2 +++ b/lib/libc/sys/posix_openpt.2 @@ -37,7 +37,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 20, 2008 +.Dd March 21, 2013 .Dt POSIX_OPENPT 2 .Os .Sh NAME @@ -71,7 +71,7 @@ Values for are constructed by a bitwise-inclusive OR of flags from the following list, defined in .In fcntl.h : -.Bl -tag -width ".Dv O_NOCTTY" +.Bl -tag -width ".Dv O_CLOEXEC" .It Dv O_RDWR Open for reading and writing. .It Dv O_NOCTTY @@ -79,6 +79,8 @@ If set .Fn posix_openpt shall not cause the terminal device to become the controlling terminal for the process. +.It Dv O_CLOEXEC +Set the close-on-exec flag for the new file descriptor. .El .Pp The @@ -116,6 +118,9 @@ The .Fn posix_openpt function conforms to .St -p1003.1-2001 . +The ability to use +.Dv O_CLOEXEC +is an extension to the standard. .Sh HISTORY The .Fn posix_openpt diff --git a/lib/libc/sys/recv.2 b/lib/libc/sys/recv.2 index 74f275c..e0a1f04 100644 --- a/lib/libc/sys/recv.2 +++ b/lib/libc/sys/recv.2 @@ -28,7 +28,7 @@ .\" @(#)recv.2 8.3 (Berkeley) 2/21/94 .\" $FreeBSD$ .\" -.Dd September 12, 2012 +.Dd March 19, 2013 .Dt RECV 2 .Os .Sh NAME @@ -121,11 +121,12 @@ argument to a function is formed by .Em or Ap ing one or more of the values: -.Bl -column ".Dv MSG_DONTWAIT" -offset indent +.Bl -column ".Dv MSG_CMSG_CLOEXEC" -offset indent .It Dv MSG_OOB Ta process out-of-band data .It Dv MSG_PEEK Ta peek at incoming message .It Dv MSG_WAITALL Ta wait for full request or error .It Dv MSG_DONTWAIT Ta do not block +.It Dv MSG_CMSG_CLOEXEC Ta set received fds close-on-exec .El .Pp The @@ -227,6 +228,10 @@ and .Fa cmsg_type set to .Dv SCM_RIGHTS . +The close-on-exec flag on received descriptors is set according to the +.Dv MSG_CMSG_CLOEXEC +flag passed to +.Fn recvmsg . .Pp Process credentials can also be passed as ancillary data for .Dv AF_UNIX diff --git a/lib/libc/sys/sigqueue.2 b/lib/libc/sys/sigqueue.2 index 8069e98..04e101b 100644 --- a/lib/libc/sys/sigqueue.2 +++ b/lib/libc/sys/sigqueue.2 @@ -117,7 +117,7 @@ or a system-wide resource limit has been exceeded. The value of the .Fa signo argument is an invalid or unsupported signal number. -.It Bq Er EEPERM +.It Bq Er EPERM The process does not have the appropriate privilege to send the signal to the receiving process. .It Bq Er ESRCH diff --git a/lib/libc/sys/socket.2 b/lib/libc/sys/socket.2 index 24e4293..74730be 100644 --- a/lib/libc/sys/socket.2 +++ b/lib/libc/sys/socket.2 @@ -28,7 +28,7 @@ .\" From: @(#)socket.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd December 7, 2012 +.Dd March 19, 2013 .Dt SOCKET 2 .Os .Sh NAME @@ -115,6 +115,15 @@ which is available only to the super-user, and which is planned, but not yet implemented, are not described here. .Pp +Additionally, the following flags are allowed in the +.Fa type +argument: +.Pp +.Bd -literal -offset indent -compact +SOCK_CLOEXEC Set close-on-exec on the new descriptor, +SOCK_NONBLOCK Set non-blocking mode on the new socket +.Ed +.Pp The .Fa protocol argument diff --git a/lib/libc/sys/socketpair.2 b/lib/libc/sys/socketpair.2 index c86db43..08d00d3 100644 --- a/lib/libc/sys/socketpair.2 +++ b/lib/libc/sys/socketpair.2 @@ -28,7 +28,7 @@ .\" @(#)socketpair.2 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd March 19, 2013 .Dt SOCKETPAIR 2 .Os .Sh NAME @@ -57,6 +57,14 @@ are returned in and .Fa sv Ns [1] . The two sockets are indistinguishable. +.Pp +The +.Dv SOCK_CLOEXEC +and +.Dv SOCK_NONBLOCK +flags in the +.Fa type +argument apply to both descriptors. .Sh RETURN VALUES .Rv -std socketpair .Sh ERRORS @@ -79,6 +87,7 @@ process address space. .Sh SEE ALSO .Xr pipe 2 , .Xr read 2 , +.Xr socket 2 , .Xr write 2 .Sh HISTORY The diff --git a/lib/libdwarf/dwarf_die.c b/lib/libdwarf/dwarf_die.c index 143e708..486811e 100644 --- a/lib/libdwarf/dwarf_die.c +++ b/lib/libdwarf/dwarf_die.c @@ -29,8 +29,6 @@ #include <stdlib.h> #include "_libdwarf.h" -static const char *anon_name = "__anon__"; - int dwarf_die_add(Dwarf_CU cu, int level, uint64_t offset, uint64_t abnum, Dwarf_Abbrev a, Dwarf_Die *diep, Dwarf_Error *err) { @@ -57,7 +55,7 @@ dwarf_die_add(Dwarf_CU cu, int level, uint64_t offset, uint64_t abnum, Dwarf_Abb die->die_abnum = abnum; die->die_a = a; die->die_cu = cu; - die->die_name = anon_name; + die->die_name = ""; /* Initialise the list of attribute values. */ STAILQ_INIT(&die->die_attrval); diff --git a/lib/libelf/elf_data.c b/lib/libelf/elf_data.c index c34c4ad..d3bd390 100644 --- a/lib/libelf/elf_data.c +++ b/lib/libelf/elf_data.c @@ -78,8 +78,10 @@ elf_getdata(Elf_Scn *s, Elf_Data *d) sh_align = s->s_shdr.s_shdr64.sh_addralign; } - if (sh_type == SHT_NULL) + if (sh_type == SHT_NULL) { + LIBELF_SET_ERROR(SECTION, 0); return (NULL); + } if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST || elftype > ELF_T_LAST || (sh_type != SHT_NOBITS && @@ -219,8 +221,10 @@ elf_rawdata(Elf_Scn *s, Elf_Data *d) sh_align = s->s_shdr.s_shdr64.sh_addralign; } - if (sh_type == SHT_NULL) + if (sh_type == SHT_NULL) { + LIBELF_SET_ERROR(SECTION, 0); return (NULL); + } if ((d = _libelf_allocate_data(s)) == NULL) return (NULL); diff --git a/lib/libelf/elf_getdata.3 b/lib/libelf/elf_getdata.3 index 97766d8..7961220 100644 --- a/lib/libelf/elf_getdata.3 +++ b/lib/libelf/elf_getdata.3 @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd January 26, 2011 +.Dd February 18, 2013 .Dt ELF_GETDATA 3 .Os .Sh NAME @@ -186,6 +186,23 @@ was not associated with section descriptor .Ar scn . .It Bq Er ELF_E_RESOURCE An out of memory condition was detected. +.It Bq Er ELF_E_SECTION +Section +.Ar scn +had type +.Dv SHT_NULL . +.It Bq Er ELF_E_SECTION +The type of the section +.Ar scn +was not recognized by the library. +.It Bq Er ELF_E_SECTION +The size of the section +.Ar scn +is not a multiple of the file size for its section type. +.It Bq Er ELF_E_SECTION +The file offset for section +.Ar scn +is incorrect. .El .Sh SEE ALSO .Xr elf 3 , diff --git a/lib/libelf/elf_update.c b/lib/libelf/elf_update.c index 5880c07..813d2bcb 100644 --- a/lib/libelf/elf_update.c +++ b/lib/libelf/elf_update.c @@ -41,89 +41,79 @@ __FBSDID("$FreeBSD$"); #include "_libelf.h" /* - * Update the internal data structures associated with an ELF object. - * Returns the size in bytes the ELF object would occupy in its file - * representation. + * Layout strategy: * - * After a successful call to this function, the following structures - * are updated: + * - Case 1: ELF_F_LAYOUT is asserted + * In this case the application has full control over where the + * section header table, program header table, and section data + * will reside. The library only perform error checks. * - * - The ELF header is updated. - * - All sections are sorted in order of ascending addresses and their - * section header table entries updated. An error is signalled - * if an overlap was detected among sections. - * - All data descriptors associated with a section are sorted in order - * of ascending addresses. Overlaps, if detected, are signalled as - * errors. Other sanity checks for alignments, section types etc. are - * made. + * - Case 2: ELF_F_LAYOUT is not asserted * - * After a resync_elf() successfully returns, the ELF descriptor is - * ready for being handed over to _libelf_write_elf(). + * The library will do the object layout using the following + * ordering: + * - The executable header is placed first, are required by the + * ELF specification. + * - The program header table is placed immediately following the + * executable header. + * - Section data, if any, is placed after the program header + * table, aligned appropriately. + * - The section header table, if needed, is placed last. * - * File alignments: - * PHDR - Addr - * SHDR - Addr + * There are two sub-cases to be taken care of: * - * XXX: how do we handle 'flags'. + * - Case 2a: e->e_cmd == ELF_C_READ or ELF_C_RDWR + * + * In this sub-case, the underlying ELF object may already have + * content in it, which the application may have modified. The + * library will retrieve content from the existing object as + * needed. + * + * - Case 2b: e->e_cmd == ELF_C_WRITE + * + * The ELF object is being created afresh in this sub-case; + * there is no pre-existing content in the underlying ELF + * object. */ /* * Compute the extents of a section, by looking at the data - * descriptors associated with it. The function returns zero if an - * error was detected. `*rc' holds the maximum file extent seen so - * far. + * descriptors associated with it. The function returns 1 if + * successful, or zero if an error was detected. */ static int -_libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc) +_libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t rc) { int ec; - Elf_Data *d, *td; + size_t fsz, msz; + Elf_Data *d; + Elf32_Shdr *shdr32; + Elf64_Shdr *shdr64; unsigned int elftype; uint32_t sh_type; uint64_t d_align; uint64_t sh_align, sh_entsize, sh_offset, sh_size; uint64_t scn_size, scn_alignment; - /* - * We need to recompute library private data structures if one - * or more of the following is true: - * - The underlying Shdr structure has been marked `dirty'. Significant - * fields include: `sh_offset', `sh_type', `sh_size', `sh_addralign'. - * - The Elf_Data structures part of this section have been marked - * `dirty'. Affected members include `d_align', `d_offset', `d_type', - * and `d_size'. - * - The section as a whole is `dirty', e.g., it has been allocated - * using elf_newscn(), or if a new Elf_Data structure was added using - * elf_newdata(). - * - * Each of these conditions would result in the ELF_F_DIRTY bit being - * set on the section descriptor's `s_flags' field. - */ - ec = e->e_class; + shdr32 = &s->s_shdr.s_shdr32; + shdr64 = &s->s_shdr.s_shdr64; if (ec == ELFCLASS32) { - sh_type = s->s_shdr.s_shdr32.sh_type; - sh_align = (uint64_t) s->s_shdr.s_shdr32.sh_addralign; - sh_entsize = (uint64_t) s->s_shdr.s_shdr32.sh_entsize; - sh_offset = (uint64_t) s->s_shdr.s_shdr32.sh_offset; - sh_size = (uint64_t) s->s_shdr.s_shdr32.sh_size; + sh_type = shdr32->sh_type; + sh_align = (uint64_t) shdr32->sh_addralign; + sh_entsize = (uint64_t) shdr32->sh_entsize; + sh_offset = (uint64_t) shdr32->sh_offset; + sh_size = (uint64_t) shdr32->sh_size; } else { - sh_type = s->s_shdr.s_shdr64.sh_type; - sh_align = s->s_shdr.s_shdr64.sh_addralign; - sh_entsize = s->s_shdr.s_shdr64.sh_entsize; - sh_offset = s->s_shdr.s_shdr64.sh_offset; - sh_size = s->s_shdr.s_shdr64.sh_size; + sh_type = shdr64->sh_type; + sh_align = shdr64->sh_addralign; + sh_entsize = shdr64->sh_entsize; + sh_offset = shdr64->sh_offset; + sh_size = shdr64->sh_size; } - if (sh_type == SHT_NULL || sh_type == SHT_NOBITS) - return (1); - - if ((s->s_flags & ELF_F_DIRTY) == 0) { - if ((size_t) *rc < sh_offset + sh_size) - *rc = sh_offset + sh_size; - return (1); - } + assert(sh_type != SHT_NULL && sh_type != SHT_NOBITS); elftype = _libelf_xlate_shtype(sh_type); if (elftype > ELF_T_LAST) { @@ -131,15 +121,52 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc) return (0); } - /* - * Compute the extent of the data descriptors associated with - * this section. - */ - scn_alignment = 0; if (sh_align == 0) sh_align = _libelf_falign(elftype, ec); - /* Compute the section alignment. */ + /* + * Check the section's data buffers for sanity and compute the + * section's alignment. + * Compute the section's size and alignment using the data + * descriptors associated with the section. + */ + if (STAILQ_EMPTY(&s->s_data)) { + /* + * The section's content (if any) has not been read in + * yet. If section is not dirty marked dirty, we can + * reuse the values in the 'sh_size' and 'sh_offset' + * fields of the section header. + */ + if ((s->s_flags & ELF_F_DIRTY) == 0) { + /* + * If the library is doing the layout, then we + * compute the new start offset for the + * section based on the current offset and the + * section's alignment needs. + * + * If the application is doing the layout, we + * can use the value in the 'sh_offset' field + * in the section header directly. + */ + if (e->e_flags & ELF_F_LAYOUT) + goto updatedescriptor; + else + goto computeoffset; + } + + /* + * Otherwise, we need to bring in the section's data + * from the underlying ELF object. + */ + if (e->e_cmd != ELF_C_WRITE && elf_getdata(s, NULL) == NULL) + return (0); + } + + /* + * Loop through the section's data descriptors. + */ + scn_size = 0L; + scn_alignment = 0L; STAILQ_FOREACH(d, &s->s_data, d_next) { if (d->d_type > ELF_T_LAST) { LIBELF_SET_ERROR(DATA, 0); @@ -153,23 +180,40 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc) LIBELF_SET_ERROR(DATA, 0); return (0); } - if (d_align > scn_alignment) - scn_alignment = d_align; - } - scn_size = 0L; + /* + * The buffer's size should be a multiple of the + * memory size of the underlying type. + */ + msz = _libelf_msize(d->d_type, ec, e->e_version); + if (d->d_size % msz) { + LIBELF_SET_ERROR(DATA, 0); + return (0); + } - STAILQ_FOREACH_SAFE(d, &s->s_data, d_next, td) { + /* + * Compute the section's size. + */ if (e->e_flags & ELF_F_LAYOUT) { if ((uint64_t) d->d_off + d->d_size > scn_size) scn_size = d->d_off + d->d_size; } else { scn_size = roundup2(scn_size, d->d_align); d->d_off = scn_size; - scn_size += d->d_size; + fsz = _libelf_fsize(d->d_type, ec, d->d_version, + d->d_size / msz); + scn_size += fsz; } + + /* + * The section's alignment is the maximum alignment + * needed for its data buffers. + */ + if (d_align > scn_alignment) + scn_alignment = d_align; } + /* * If the application is requesting full control over the layout * of the section, check its values for sanity. @@ -180,46 +224,60 @@ _libelf_compute_section_extents(Elf *e, Elf_Scn *s, off_t *rc) LIBELF_SET_ERROR(LAYOUT, 0); return (0); } - } else { - /* - * Otherwise compute the values in the section header. - */ + goto updatedescriptor; + } - if (scn_alignment > sh_align) - sh_align = scn_alignment; + /* + * Otherwise compute the values in the section header. + * + * The section alignment is the maximum alignment for any of + * its contained data descriptors. + */ + if (scn_alignment > sh_align) + sh_align = scn_alignment; - /* - * If the section entry size is zero, try and fill in an - * appropriate entry size. Per the elf(5) manual page - * sections without fixed-size entries should have their - * 'sh_entsize' field set to zero. - */ - if (sh_entsize == 0 && - (sh_entsize = _libelf_fsize(elftype, ec, e->e_version, - (size_t) 1)) == 1) - sh_entsize = 0; + /* + * If the section entry size is zero, try and fill in an + * appropriate entry size. Per the elf(5) manual page + * sections without fixed-size entries should have their + * 'sh_entsize' field set to zero. + */ + if (sh_entsize == 0 && + (sh_entsize = _libelf_fsize(elftype, ec, e->e_version, + (size_t) 1)) == 1) + sh_entsize = 0; - sh_size = scn_size; - sh_offset = roundup(*rc, sh_align); + sh_size = scn_size; - if (ec == ELFCLASS32) { - s->s_shdr.s_shdr32.sh_addralign = (uint32_t) sh_align; - s->s_shdr.s_shdr32.sh_entsize = (uint32_t) sh_entsize; - s->s_shdr.s_shdr32.sh_offset = (uint32_t) sh_offset; - s->s_shdr.s_shdr32.sh_size = (uint32_t) sh_size; - } else { - s->s_shdr.s_shdr64.sh_addralign = sh_align; - s->s_shdr.s_shdr64.sh_entsize = sh_entsize; - s->s_shdr.s_shdr64.sh_offset = sh_offset; - s->s_shdr.s_shdr64.sh_size = sh_size; - } - } +computeoffset: + /* + * Compute the new offset for the section based on + * the section's alignment needs. + */ + sh_offset = roundup(rc, sh_align); - if ((size_t) *rc < sh_offset + sh_size) - *rc = sh_offset + sh_size; + /* + * Update the section header. + */ + if (ec == ELFCLASS32) { + shdr32->sh_addralign = (uint32_t) sh_align; + shdr32->sh_entsize = (uint32_t) sh_entsize; + shdr32->sh_offset = (uint32_t) sh_offset; + shdr32->sh_size = (uint32_t) sh_size; + } else { + shdr64->sh_addralign = sh_align; + shdr64->sh_entsize = sh_entsize; + shdr64->sh_offset = sh_offset; + shdr64->sh_size = sh_size; + } +updatedescriptor: + /* + * Update the section descriptor. + */ s->s_size = sh_size; s->s_offset = sh_offset; + return (1); } @@ -267,13 +325,16 @@ _libelf_insert_section(Elf *e, Elf_Scn *s) return (1); } +/* + * Recompute section layout. + */ + static off_t _libelf_resync_sections(Elf *e, off_t rc) { int ec; - off_t nrc; + Elf_Scn *s; size_t sh_type, shdr_start, shdr_end; - Elf_Scn *s, *ts; ec = e->e_class; @@ -281,13 +342,7 @@ _libelf_resync_sections(Elf *e, off_t rc) * Make a pass through sections, computing the extent of each * section. Order in increasing order of addresses. */ - - nrc = rc; - STAILQ_FOREACH(s, &e->e_u.e_elf.e_scn, s_next) - if (_libelf_compute_section_extents(e, s, &nrc) == 0) - return ((off_t) -1); - - STAILQ_FOREACH_SAFE(s, &e->e_u.e_elf.e_scn, s_next, ts) { + STAILQ_FOREACH(s, &e->e_u.e_elf.e_scn, s_next) { if (ec == ELFCLASS32) sh_type = s->s_shdr.s_shdr32.sh_type; else @@ -296,21 +351,22 @@ _libelf_resync_sections(Elf *e, off_t rc) if (sh_type == SHT_NOBITS || sh_type == SHT_NULL) continue; - if (s->s_offset < (uint64_t) rc) { - if (s->s_offset + s->s_size < (uint64_t) rc) { - /* - * Try insert this section in the - * correct place in the list, - * detecting overlaps if any. - */ - STAILQ_REMOVE(&e->e_u.e_elf.e_scn, s, _Elf_Scn, - s_next); - if (_libelf_insert_section(e, s) == 0) - return ((off_t) -1); - } else { - LIBELF_SET_ERROR(LAYOUT, 0); + if (_libelf_compute_section_extents(e, s, rc) == 0) + return ((off_t) -1); + + if (s->s_size == 0) + continue; + + if (s->s_offset + s->s_size < (size_t) rc) { + /* + * Try insert this section in the + * correct place in the list, + * detecting overlaps if any. + */ + STAILQ_REMOVE(&e->e_u.e_elf.e_scn, s, _Elf_Scn, + s_next); + if (_libelf_insert_section(e, s) == 0) return ((off_t) -1); - } } else rc = s->s_offset + s->s_size; } @@ -338,8 +394,6 @@ _libelf_resync_sections(Elf *e, off_t rc) } } - assert(nrc == rc); - return (rc); } diff --git a/lib/libexpat/expat_config.h b/lib/libexpat/expat_config.h index 9808129..6deefc4 100644 --- a/lib/libexpat/expat_config.h +++ b/lib/libexpat/expat_config.h @@ -45,6 +45,9 @@ /* Define to 1 if you have the <string.h> header file. */ #define HAVE_STRING_H 1 +/* Define to 1 if you have the <sys/param.h> header file. */ +#define HAVE_SYS_PARAM_H 1 + /* Define to 1 if you have the <sys/stat.h> header file. */ #define HAVE_SYS_STAT_H 1 @@ -54,20 +57,27 @@ /* Define to 1 if you have the <unistd.h> header file. */ #define HAVE_UNISTD_H 1 +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#undef LT_OBJDIR + /* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "expat-bugs@mail.libexpat.org" +#define PACKAGE_BUGREPORT "expat-bugs@libexpat.org" /* Define to the full name of this package. */ #define PACKAGE_NAME "expat" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "expat 1.95.5" +#define PACKAGE_STRING "expat 2.1.0" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "expat" +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + /* Define to the version of this package. */ -#define PACKAGE_VERSION "1.95.5" +#define PACKAGE_VERSION "2.1.0" /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 @@ -89,11 +99,14 @@ /* Define to make XML Namespaces functionality available. */ #define XML_NS 1 +/* Define to __FUNCTION__ or "" if `__func__' does not conform to ANSI C. */ +/* #undef __func__ */ + /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ -/* Define to `long' if <sys/types.h> does not define. */ +/* Define to `long int' if <sys/types.h> does not define. */ /* #undef off_t */ -/* Define to `unsigned' if <sys/types.h> does not define. */ +/* Define to `unsigned int' if <sys/types.h> does not define. */ /* #undef size_t */ diff --git a/lib/libexpat/libbsdxml.3 b/lib/libexpat/libbsdxml.3 index 555bc9a..04887f0 100644 --- a/lib/libexpat/libbsdxml.3 +++ b/lib/libexpat/libbsdxml.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\"/ -.Dd December 12, 2009 +.Dd February 26, 2013 .Dt LIBBSDXML 3 .Os .Sh NAME @@ -36,7 +36,7 @@ .Sh DESCRIPTION The .Nm -library is a verbatim copy of the eXpat XML library version 2.0.1. +library is a verbatim copy of the eXpat XML library version 2.1.0. .Pp The .Nm diff --git a/lib/libipsec/test-policy.c b/lib/libipsec/test-policy.c index c1dfc79..a24a0b41 100644 --- a/lib/libipsec/test-policy.c +++ b/lib/libipsec/test-policy.c @@ -75,14 +75,13 @@ struct req_t { { 1, "out ipsec ah/transport esp/use" }, { 1, "in ipsec ah/transport esp/tunnel" }, { 0, "in ipsec ah/transport esp/tunnel/::1-::1" }, -{ 0, "in ipsec - ah / transport - esp / tunnel / ::1-::2" }, -{ 0, "out ipsec - ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require - ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require - ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require - " }, +{ 0, "in ipsec\n" + "ah / transport\n" + "esp / tunnel / ::1-::2" }, +{ 0, "out ipsec\n" + "ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require\n" + "ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require\n" + "ah/transport/::1-::2 esp/tunnel/::3-::4/use ah/transport/::5-::6/require\n" }, { 0, "out ipsec esp/transport/fec0::10-fec0::11/use" }, }; diff --git a/lib/libkiconv/kiconv.3 b/lib/libkiconv/kiconv.3 index affacf1..ed250a1 100644 --- a/lib/libkiconv/kiconv.3 +++ b/lib/libkiconv/kiconv.3 @@ -126,5 +126,4 @@ not using .Sh SEE ALSO .Xr iconv 3 , .Xr tolower 3 , -.Xr toupper 3 , -.Xr iconv 9 +.Xr toupper 3 diff --git a/lib/libkvm/Makefile b/lib/libkvm/Makefile index 1250bf7..5b5ad43 100644 --- a/lib/libkvm/Makefile +++ b/lib/libkvm/Makefile @@ -25,8 +25,10 @@ MAN= kvm.3 kvm_getcptime.3 kvm_geterr.3 kvm_getfiles.3 kvm_getloadavg.3 \ kvm_getpcpu.3 kvm_getprocs.3 kvm_getswapinfo.3 kvm_nlist.3 kvm_open.3 \ kvm_read.3 -MLINKS+=kvm_getpcpu.3 kvm_getmaxcpu.3 -MLINKS+=kvm_getpcpu.3 kvm_dpcpu_setcpu.3 +MLINKS+=kvm_getpcpu.3 kvm_getmaxcpu.3 \ + kvm_getpcpu.3 kvm_dpcpu_setcpu.3 \ + kvm_getpcpu.3 kvm_read_zpcpu.3 \ + kvm_getpcpu.3 kvm_counter_u64_fetch.3 MLINKS+=kvm_getprocs.3 kvm_getargv.3 kvm_getprocs.3 kvm_getenvv.3 MLINKS+=kvm_open.3 kvm_close.3 kvm_open.3 kvm_openfiles.3 MLINKS+=kvm_read.3 kvm_write.3 diff --git a/lib/libkvm/kvm.h b/lib/libkvm/kvm.h index 912f1d4..43b0551 100644 --- a/lib/libkvm/kvm.h +++ b/lib/libkvm/kvm.h @@ -34,7 +34,7 @@ #define _KVM_H_ #include <sys/cdefs.h> -#include <sys/_types.h> +#include <sys/types.h> #include <nlist.h> /* Default version symbol. */ @@ -78,6 +78,7 @@ char *kvm_getfiles(kvm_t *, int, int, int *); int kvm_getloadavg(kvm_t *, double [], int); int kvm_getmaxcpu(kvm_t *); void *kvm_getpcpu(kvm_t *, int); +uint64_t kvm_counter_u64_fetch(kvm_t *, u_long); struct kinfo_proc * kvm_getprocs(kvm_t *, int, int, int *); int kvm_getswapinfo(kvm_t *, struct kvm_swap *, int, int); @@ -87,6 +88,7 @@ kvm_t *kvm_open kvm_t *kvm_openfiles (const char *, const char *, const char *, int, char *); ssize_t kvm_read(kvm_t *, unsigned long, void *, size_t); +ssize_t kvm_read_zpcpu(kvm_t *, void *, u_long, size_t, int); ssize_t kvm_uread (kvm_t *, const struct kinfo_proc *, unsigned long, char *, size_t); ssize_t kvm_write(kvm_t *, unsigned long, const void *, size_t); diff --git a/lib/libkvm/kvm_getpcpu.3 b/lib/libkvm/kvm_getpcpu.3 index 1e0c1f4..4087f1c 100644 --- a/lib/libkvm/kvm_getpcpu.3 +++ b/lib/libkvm/kvm_getpcpu.3 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 28, 2010 +.Dd April 11, 2013 .Dt KVM_GETPCPU 3 .Os .Sh NAME @@ -49,6 +49,10 @@ .Fn kvm_getmaxcpu "kvm_t *kd" .Ft void * .Fn kvm_getpcpu "kvm_t *kd" "int cpu" +.Ft ssize_t +.Fn kvm_read_zpcpu "kvm_t *kd" "void *buf" "u_long base" "size_t size" "int cpu" +.Ft uint64_t +.Fn kvm_counter_u64_fetch "kvm_t *kd" "u_long base" .Sh DESCRIPTION The .Fn kvm_dpcpu_setcpu , @@ -83,6 +87,28 @@ is not active, then .Dv NULL is returned instead. .Pp +The +.Fn kvm_read_zpcpu +function is used to obtain private per-CPU copy from a +.Dv UMA_ZONE_PCPU +.Xr zone 9 . +It takes +.Fa base +argument as base address of an allocation and copyies +.Fa size +bytes into +.Fa buf +from the part of allocation that is private to +.Fa cpu . +.Pp +The +.Fn kvm_counter_u64_fetch +function fetches value of a +.Xr counter 9 +pointed by +.Fa base +address. +.Pp Symbols for dynamic per-CPU data are accessed via .Xr kvm_nlist 3 as with other symbols. @@ -122,9 +148,16 @@ On success, the .Fn kvm_dpcpu_setcpu call returns 0; if an error occurs, it returns -1 instead. .Pp +On success, the +.Fn kvm_read_zpcpu +function returns number of bytes copied. +If an error occurs, it returns -1 instead. +.Pp If any function encounters an error, then an error message may be retrieved via .Xr kvm_geterr 3 . .Sh SEE ALSO .Xr free 3 , -.Xr kvm 3 +.Xr kvm 3 , +.Xr counter 9 , +.Xr zone 9 diff --git a/lib/libkvm/kvm_pcpu.c b/lib/libkvm/kvm_pcpu.c index d7108b4..2d7fb41 100644 --- a/lib/libkvm/kvm_pcpu.c +++ b/lib/libkvm/kvm_pcpu.c @@ -1,4 +1,5 @@ /*- + * Copyright (c) 2013 Gleb Smirnoff <glebius@FreeBSD.org> * Copyright (c) 2010 Juniper Networks, Inc. * Copyright (c) 2009 Robert N. M. Watson * Copyright (c) 2009 Bjoern A. Zeeb <bz@FreeBSD.org> @@ -50,8 +51,12 @@ __FBSDID("$FreeBSD$"); static struct nlist kvm_pcpu_nl[] = { { .n_name = "_cpuid_to_pcpu" }, { .n_name = "_mp_maxcpus" }, + { .n_name = "_mp_ncpus" }, { .n_name = NULL }, }; +#define NL_CPUID_TO_PCPU 0 +#define NL_MP_MAXCPUS 1 +#define NL_MP_NCPUS 2 /* * Kernel per-CPU data state. We cache this stuff on the first @@ -63,9 +68,7 @@ static struct nlist kvm_pcpu_nl[] = { */ static void **pcpu_data; static int maxcpu; - -#define NL_CPUID_TO_PCPU 0 -#define NL_MP_MAXCPUS 1 +static int mp_ncpus; static int _kvm_pcpu_init(kvm_t *kd) @@ -89,6 +92,15 @@ _kvm_pcpu_init(kvm_t *kd) _kvm_err(kd, kd->program, "cannot read mp_maxcpus"); return (-1); } + if (kvm_pcpu_nl[NL_MP_NCPUS].n_value == 0) { + _kvm_err(kd, kd->program, "unable to find mp_ncpus"); + return (-1); + } + if (kvm_read(kd, kvm_pcpu_nl[NL_MP_NCPUS].n_value, &mp_ncpus, + sizeof(mp_ncpus)) != sizeof(mp_ncpus)) { + _kvm_err(kd, kd->program, "cannot read mp_ncpus"); + return (-1); + } len = max * sizeof(void *); data = malloc(len); if (data == NULL) { @@ -289,3 +301,36 @@ kvm_dpcpu_setcpu(kvm_t *kd, u_int cpu) return (_kvm_dpcpu_setcpu(kd, cpu, 1)); } + +/* + * Obtain a per-CPU copy for given cpu from UMA_ZONE_PCPU allocation. + */ +ssize_t +kvm_read_zpcpu(kvm_t *kd, void *buf, u_long base, size_t size, int cpu) +{ + + return (kvm_read(kd, (uintptr_t)(base + sizeof(struct pcpu) * cpu), + buf, size)); +} + +/* + * Fetch value of a counter(9). + */ +uint64_t +kvm_counter_u64_fetch(kvm_t *kd, u_long base) +{ + uint64_t r, c; + + if (mp_ncpus == 0) + if (_kvm_pcpu_init(kd) < 0) + return (0); + + r = 0; + for (int i = 0; i < mp_ncpus; i++) { + if (kvm_read_zpcpu(kd, &c, base, sizeof(c), i) != sizeof(c)) + return (0); + r += c; + } + + return (r); +} diff --git a/lib/libldns/Makefile b/lib/libldns/Makefile new file mode 100644 index 0000000..c0b30b0 --- /dev/null +++ b/lib/libldns/Makefile @@ -0,0 +1,45 @@ +# $FreeBSD$ + +# Vendor sources and generated files +LDNSDIR = ${.CURDIR}/../../contrib/ldns + +.PATH: ${LDNSDIR} + +LIB = ldns +INTERNALLIB = true + +CFLAGS += -I${LDNSDIR} + +SRCS += buffer.c +SRCS += dane.c +SRCS += dname.c +SRCS += dnssec.c +SRCS += dnssec_sign.c +SRCS += dnssec_verify.c +SRCS += dnssec_zone.c +SRCS += duration.c +SRCS += error.c +SRCS += higher.c +SRCS += host2str.c +SRCS += host2wire.c +SRCS += keys.c +SRCS += net.c +SRCS += packet.c +SRCS += parse.c +SRCS += rbtree.c +SRCS += rdata.c +SRCS += resolver.c +SRCS += rr.c +SRCS += rr_functions.c +SRCS += sha1.c +SRCS += sha2.c +SRCS += str2host.c +SRCS += tsig.c +SRCS += update.c +SRCS += util.c +SRCS += wire2host.c +SRCS += zone.c + +WARNS ?= 3 + +.include <bsd.lib.mk> diff --git a/lib/libncp/CREDITS b/lib/libncp/CREDITS deleted file mode 100644 index 4338055..0000000 --- a/lib/libncp/CREDITS +++ /dev/null @@ -1,27 +0,0 @@ -# $FreeBSD$ - -In the development of NetWare client for FreeBSD next sources was used: - -ncpfs for Linux - written by Volker Lendecke (lendecke@math.uni-goettingen.de), - thanks to him for giving a permission to publish his code under BSD-style - license. - -"Interrupt List" from Ralf Brown, - -Many files from the /sys directory. - -NDK documentation from Novell Inc. - - -Also thanks to thouse who gets time to testing, reporting problems and give -a good suggestions (in alphabet order): - -Anatoly A. Orehovsky -Andrew Petrenko -Jesus Rodriguez -Matthew N. Dodd -Mike Pitt -Vadim Mikhailov - - -Author - Boris Popov <bp@butya.kz>, <bp@freebsd.org> diff --git a/lib/libncp/Makefile b/lib/libncp/Makefile deleted file mode 100644 index d7870a0..0000000 --- a/lib/libncp/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -# $FreeBSD$ - -LIB= ncp - -SHLIB_MAJOR= 4 - -DPADD= ${LIBIPX} -LDADD= -lipx - -SRCS= ncpl_subr.c ncpl_bind.c ncpl_queue.c ncpl_file.c ncpl_misc.c \ - ncpl_net.c ncpl_rcfile.c ncpl_conn.c ncpl_nls.c ncpl_msg.c \ - ncpl_rpc.c ncpl_crypt.c ipx.c sap.c - -WARNS?= 0 - -.include <bsd.lib.mk> diff --git a/lib/libncp/Makefile.depend b/lib/libncp/Makefile.depend deleted file mode 100644 index 29fda55..0000000 --- a/lib/libncp/Makefile.depend +++ /dev/null @@ -1,14 +0,0 @@ -# Autogenerated - do NOT edit! - -DEP_RELDIR := ${_PARSEDIR:S,${SRCTOP}/,,} - -DEP_MACHINE := ${.PARSEFILE:E} - -DIRDEPS = \ - - -.include <dirdeps.mk> - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif diff --git a/lib/libncp/ipx.c b/lib/libncp/ipx.c deleted file mode 100644 index d658b5a..0000000 --- a/lib/libncp/ipx.c +++ /dev/null @@ -1,352 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/socket.h> -#include <sys/sysctl.h> -#include <sys/time.h> - -#include <arpa/inet.h> -#include <net/if.h> -#include <net/if_var.h> -#include <net/if_dl.h> -#include <net/if_types.h> -#include <net/route.h> - -/* IPX */ -#include <netipx/ipx.h> -#include <netipx/ipx_if.h> - -#include <ctype.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <netncp/ncp_lib.h> - -#define IPX_NODE_LEN 6 - -typedef u_long IPXNet; -typedef u_short IPXPort; -typedef union ipx_host IPXNode; - - -void -ipx_fprint_node(FILE * file, IPXNode node){ - fprintf(file, "%02X%02X%02X%02X%02X%02X", - (unsigned char) node.c_host[0], - (unsigned char) node.c_host[1], - (unsigned char) node.c_host[2], - (unsigned char) node.c_host[3], - (unsigned char) node.c_host[4], - (unsigned char) node.c_host[5] - ); -} - -void -ipx_fprint_network(FILE * file, const IPXNet net){ - fprintf(file, "%08X", (u_int32_t)ntohl(net)); -} - -void -ipx_fprint_port(FILE * file, IPXPort port) -{ - fprintf(file, "%04X", ntohs(port)); -} - -void -ipx_fprint_addr(FILE * file, struct ipx_addr *ipx) -{ - ipx_fprint_network(file, ipx_netlong(*ipx)); - fprintf(file, ":"); - ipx_fprint_node(file, ipx->x_host); - fprintf(file, ":"); - ipx_fprint_port(file, ipx->x_port); -} - -void -ipx_print_node(IPXNode node) -{ - ipx_fprint_node(stdout, node); -} - -void -ipx_print_network(IPXNet net) -{ - ipx_fprint_network(stdout, net); -} - -void -ipx_print_port(IPXPort port) -{ - ipx_fprint_port(stdout, port); -} - -void -ipx_print_addr(struct ipx_addr *ipx) -{ - ipx_fprint_addr(stdout, ipx); -} - -int -ipx_sscanf_node(char *buf, unsigned char node[6]) -{ - int i; - int n[6]; - - if ((i = sscanf(buf, "%2x%2x%2x%2x%2x%2x", - &(n[0]), &(n[1]), &(n[2]), - &(n[3]), &(n[4]), &(n[5]))) != 6) - { - return i; - } - for (i = 0; i < 6; i++) - { - node[i] = n[i]; - } - return 6; -} - -int -ipx_sscanf_saddr(char *buf, struct sockaddr_ipx *target) -{ - char *p; - struct sockaddr_ipx addr; - unsigned long sipx_net; - - addr.sipx_family = AF_IPX; -/*!! addr.sipx_type = NCP_PTYPE;*/ - - if (sscanf(buf, "%lx", &sipx_net) != 1) - { - return 1; - } - ((union ipx_net_u*)(&addr.sipx_addr.x_net))->long_e = htonl(sipx_net); - if ((p = strchr(buf, ':')) == NULL){ - return 1; - } - p += 1; - if (ipx_sscanf_node(p, addr.sipx_node) != 6) - { - return 1; - } - if ((p = strchr(p, ':')) == NULL) - { - return 1; - } - p += 1; - if (sscanf(p, "%hx", &addr.sipx_port) != 1) - { - return 1; - } - addr.sipx_port = htons(addr.sipx_port); - *target = addr; - return 0; -} - - -void ipx_assign_node(IPXNode *dest, IPXNode *src) { - memcpy(dest, src, IPX_NODE_LEN); -} - - -static void rt_xaddrs(caddr_t, caddr_t, struct rt_addrinfo *); -static int if_ipxscan(int addrcount, struct sockaddr_dl *sdl, - struct if_msghdr *ifm, struct ifa_msghdr *ifam, - struct ipx_addr *addr); - -/* - * Find an IPX interface. - * ifname specifies interface name, if NULL search for all interfaces - * if ifname[0]='0', also all interfaces, but return its name - * addr on input preferred net address can be specified or 0 for any, - * on return contains full address (except port) - * returns 0 if interface was found - */ -int -ipx_iffind(char *ifname,struct ipx_addr *addr){ - char name[32]; - int all=0, flags, foundit = 0, addrcount; - struct if_msghdr *ifm, *nextifm; - struct ifa_msghdr *ifam; - struct sockaddr_dl *sdl; - char *buf, *lim, *next; - size_t needed; - int mib[6]; - - if( ifname!=NULL ) { - strncpy(name,ifname,sizeof(name)-1); - if( name[0]==0 ) - all=1; - } else - all = 1; - - mib[0] = CTL_NET; - mib[1] = PF_ROUTE; - mib[2] = 0; - mib[3] = AF_IPX; - mib[4] = NET_RT_IFLIST; - mib[5] = 0; - - if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0) - return(1); - if ((buf = malloc(needed)) == NULL) - return(1); - if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) { - free(buf); - return(1); - } - lim = buf + needed; - - next = buf; - while (next < lim) { - ifm = (struct if_msghdr *)next; - if (ifm->ifm_type == RTM_IFINFO) { - sdl = (struct sockaddr_dl *)(ifm + 1); - flags = ifm->ifm_flags; - } else { - fprintf(stderr, "if_ipxfind: out of sync parsing NET_RT_IFLIST\n"); - fprintf(stderr, "expected %d, got %d\n", RTM_IFINFO, ifm->ifm_type); - fprintf(stderr, "msglen = %d\n", ifm->ifm_msglen); - fprintf(stderr, "buf:%p, next:%p, lim:%p\n", buf, next, lim); - free(buf); - return(1); - } - - next += ifm->ifm_msglen; - ifam = NULL; - addrcount = 0; - while (next < lim) { - nextifm = (struct if_msghdr *)next; - if (nextifm->ifm_type != RTM_NEWADDR) - break; - if (ifam == NULL) - ifam = (struct ifa_msghdr *)nextifm; - addrcount++; - next += nextifm->ifm_msglen; - } - - if (all) { - if ((flags & IFF_UP) == 0) - continue; /* not up */ - strncpy(name, sdl->sdl_data, sdl->sdl_nlen); - name[sdl->sdl_nlen] = '\0'; - } else { - if (strlen(name) != sdl->sdl_nlen) - continue; /* not same len */ - if (strncmp(name, sdl->sdl_data, sdl->sdl_nlen) != 0) - continue; /* not same name */ - } - - foundit=if_ipxscan(addrcount, sdl, ifm, ifam, addr); - if( foundit ) { - if( ifname!=NULL && ifname[0]==0) { - strncpy(ifname,sdl->sdl_data, sdl->sdl_nlen); - ifname[sdl->sdl_nlen]=0; - } - break; - } - } - free(buf); - - return foundit ? 0:1; -} - - -int -if_ipxscan(addrcount, sdl, ifm, ifam, addr) - int addrcount; - struct sockaddr_dl *sdl; - struct if_msghdr *ifm; - struct ifa_msghdr *ifam; - struct ipx_addr *addr; -{ - struct rt_addrinfo info; - struct sockaddr_ipx *sipx; - int s; - - if ((s = socket(AF_IPX, SOCK_DGRAM, 0)) < 0) { - perror("ifconfig: socket"); - return 0; - } - - while (addrcount > 0) { - info.rti_addrs = ifam->ifam_addrs; - /* Expand the compacted addresses */ - rt_xaddrs((char *)(ifam + 1), ifam->ifam_msglen + (char *)ifam, &info); - addrcount--; - ifam = (struct ifa_msghdr *)((char *)ifam + ifam->ifam_msglen); - if (info.rti_info[RTAX_IFA]->sa_family == AF_IPX) { - sipx = (struct sockaddr_ipx *)info.rti_info[RTAX_IFA]; - if( ipx_nullnet(sipx->sipx_addr) ) continue; - if( ipx_nullnet(*addr) || - ipx_neteq(sipx->sipx_addr,*addr) ) { - *addr=sipx->sipx_addr; - close(s); - return(1); - } - } - } - close(s); - return(0); -} -/* - * Expand the compacted form of addresses as returned via the - * configuration read via sysctl(). - */ - -#define ROUNDUP(a) \ - ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) -#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) - -static void -rt_xaddrs(cp, cplim, rtinfo) - caddr_t cp, cplim; - struct rt_addrinfo *rtinfo; -{ - struct sockaddr *sa; - int i; - - memset(rtinfo->rti_info, 0, sizeof(rtinfo->rti_info)); - for (i = 0; (i < RTAX_MAX) && (cp < cplim); i++) { - if ((rtinfo->rti_addrs & (1 << i)) == 0) - continue; - rtinfo->rti_info[i] = sa = (struct sockaddr *)cp; - ADVANCE(cp, sa); - } -} - diff --git a/lib/libncp/ipxsap.h b/lib/libncp/ipxsap.h deleted file mode 100644 index 2b26b6a..0000000 --- a/lib/libncp/ipxsap.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ -#ifndef _IPXSAP_H_ -#define _IPXSAP_H_ - -#define IPX_SAP_GENERAL_QUERY 1 -#define IPX_SAP_GENERAL_RESPONSE 2 -#define IPX_SAP_NEAREST_QUERY 3 -#define IPX_SAP_NEAREST_RESPONSE 4 - - -#define IPX_SAP_MAX_ENTRIES 7 -#define IPX_SAP_SERVER_DOWN 16 -#define IPX_SAP_SERVER_NAME_LEN 48 -#define IPX_SAP_REQUEST_LEN 4 - -/* Values for server_type */ -#define IPX_SAP_FILE_SERVER 4 - -struct sap_query { - u_short query_type; /* net order */ - u_short server_type; /* net order */ -} __packed; - -struct sap_entry { - u_short server_type; - u_char server_name[IPX_SAP_SERVER_NAME_LEN]; - struct ipx_addr ipx; - u_short hops; -} __packed; - -struct sap_packet { - u_short operation; - struct sap_entry sap_entries[1]; -} __packed; - -struct sap_rq { - struct sockaddr_ipx dest_addr; - int sock; - int entries; - struct sap_packet* buffer; -}; -/* -#define sap_name_equal(n1,n2) (strncmp(n1,n2,IPX_SAP_SERVER_NAME_LEN) == 0); -#define sap_type_equal(t1,t2) (t1==IPX_SAP_GENERAL_RQ || t2==IPX_SAP_GENERAL_RQ || t1==t2); -*/ -void sap_copy_name(char *dest,char *src); -int sap_getsock(int *rsock); - - -int sap_rq_init(struct sap_rq* out,int sock); -int sap_rq_flush(struct sap_rq* out); -void sap_rq_general(struct sap_rq* out,u_short ser_type); -void sap_rq_gns_request(struct sap_rq* out,u_short ser_type); -void sap_rq_response(struct sap_rq* out,u_short type,char *name,struct sockaddr_ipx* addr,u_short hops,int down_allow); -void sap_rq_gns_response(struct sap_rq* out,u_short type,char * name,struct sockaddr_ipx* addr,u_short hops); -void sap_rq_set_destination(struct sap_rq* out,struct ipx_addr *dest); - -int sap_find_nearest(int server_type, struct sockaddr_ipx *result,char *server_name); - -extern int (*sap_sendto_func)(void* buffer,int size,struct sockaddr_ipx* daddr,int sock); -int ipx_iffind(char *ifname, struct ipx_addr *addr); - -#endif /* !_IPXSAP_H_ */ diff --git a/lib/libncp/ncpl_bind.c b/lib/libncp/ncpl_bind.c deleted file mode 100644 index d00cfa8..0000000 --- a/lib/libncp/ncpl_bind.c +++ /dev/null @@ -1,267 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <arpa/inet.h> -#include <errno.h> -#include <string.h> -#include <netncp/ncp_lib.h> - -static void nw_passencrypt(char *old, char *new, char *out); - -int -ncp_get_bindery_object_id(NWCONN_HANDLE connid, u_int16_t object_type, - const char *object_name, struct ncp_bindery_object *target) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 53); - ncp_add_word_hl(conn, object_type); - ncp_add_pstring(conn, object_name); - - if ((error = ncp_request(connid, 23, conn)) != 0) { - return error; - } - if (conn->rpsize < 54) { - return EACCES; - } - target->object_id = ncp_reply_dword_hl(conn, 0); - target->object_type = ncp_reply_word_hl(conn, 4); - memcpy(target->object_name, ncp_reply_data(conn, 6), 48); - return 0; -} - -int -ncp_read_property_value(NWCONN_HANDLE connid, int object_type, - const char *object_name, int segment, const char *prop_name, - struct nw_property *target) -{ - int error; - struct ncp_buf conn; - ncp_init_request_s(&conn, 61); - ncp_add_word_hl(&conn, object_type); - ncp_add_pstring(&conn, object_name); - ncp_add_byte(&conn, segment); - ncp_add_pstring(&conn, prop_name); - - if ((error = ncp_request(connid,23,&conn)) != 0) { - return error; - } - memcpy(&(target->value), ncp_reply_data(&conn, 0), 128); - target->more_flag = ncp_reply_byte(&conn, 128); - target->property_flag = ncp_reply_byte(&conn, 129); - return 0; -} - -int -ncp_scan_bindery_object(NWCONN_HANDLE connid, u_int32_t last_id, - u_int16_t object_type, const char *search_string, - struct ncp_bindery_object *target) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 55); - ncp_add_dword_hl(conn, last_id); - ncp_add_word_hl(conn, object_type); - ncp_add_pstring(conn, search_string); - error = ncp_request(connid, 23, conn); - if (error) return error; - target->object_id = ncp_reply_dword_hl(conn, 0); - target->object_type = ncp_reply_word_hl(conn, 4); - memcpy(target->object_name, ncp_reply_data(conn, 6),NCP_BINDERY_NAME_LEN); - target->object_flags = ncp_reply_byte(conn, 54); - target->object_security = ncp_reply_byte(conn, 55); - target->object_has_prop = ncp_reply_byte(conn, 56); - return 0; -} - -int -ncp_get_bindery_object_name(NWCONN_HANDLE connid, u_int32_t object_id, - struct ncp_bindery_object *target) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 54); - ncp_add_dword_hl(conn, object_id); - if ((error = ncp_request(connid, 23, conn)) != 0) - return error; - target->object_id = ncp_reply_dword_hl(conn, 0); - target->object_type = ncp_reply_word_hl(conn, 4); - memcpy(target->object_name, ncp_reply_data(conn, 6), 48); - return 0; -} - -int -ncp_change_obj_passwd(NWCONN_HANDLE connid, - const struct ncp_bindery_object *object, - const u_char *key, - const u_char *oldpasswd, - const u_char *newpasswd) -{ - long id = htonl(object->object_id); - u_char cryptkey[8]; - u_char newpwd[16]; /* new passwd as stored by server */ - u_char oldpwd[16]; /* old passwd as stored by server */ - u_char len; - DECLARE_RQ; - - memcpy(cryptkey, key, 8); - nw_keyhash((u_char *)&id, oldpasswd, strlen(oldpasswd), oldpwd); - nw_keyhash((u_char *)&id, newpasswd, strlen(newpasswd), newpwd); - nw_encrypt(cryptkey, oldpwd, cryptkey); - nw_passencrypt(oldpwd, newpwd, newpwd); - nw_passencrypt(oldpwd + 8, newpwd + 8, newpwd + 8); - if ((len = strlen(newpasswd)) > 63) { - len = 63; - } - len = ((len ^ oldpwd[0] ^ oldpwd[1]) & 0x7f) | 0x40; - - ncp_init_request_s(conn, 75); - ncp_add_mem(conn, cryptkey, 8); - ncp_add_word_hl(conn, object->object_type); - ncp_add_pstring(conn, object->object_name); - ncp_add_byte(conn, len); - ncp_add_mem(conn, newpwd, 16); - return ncp_request(connid, 23, conn); -} - -/* - * target is a 8-byte buffer - */ -int -ncp_get_encryption_key(NWCONN_HANDLE cH, char *target) { - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 23); - - error = ncp_request(cH, 23, conn); - if (error) - return error; - if (conn->rpsize < 8) - return EACCES; - memcpy(target, ncp_reply_data(conn, 0), 8); - return 0; -} - -int -ncp_keyed_verify_password(NWCONN_HANDLE cH, char *key, char *passwd, - struct ncp_bindery_object *objinfo) -{ - u_long id = htonl(objinfo->object_id); - u_char cryptkey[8]; - u_char buf[128]; - DECLARE_RQ; - - nw_keyhash((u_char *)&id, passwd, strlen(passwd), buf); - nw_encrypt(key, buf, cryptkey); - - ncp_init_request_s(conn, 74); - ncp_add_mem(conn, cryptkey, sizeof(cryptkey)); - ncp_add_word_hl(conn, objinfo->object_type); - ncp_add_pstring(conn, objinfo->object_name); - - return ncp_request(cH, 23, conn); -} - -static char passkeys[256 + 16] = { - 0x0f, 0x08, 0x05, 0x07, 0x0c, 0x02, 0x0e, 0x09, - 0x00, 0x01, 0x06, 0x0d, 0x03, 0x04, 0x0b, 0x0a, - 0x02, 0x0c, 0x0e, 0x06, 0x0f, 0x00, 0x01, 0x08, - 0x0d, 0x03, 0x0a, 0x04, 0x09, 0x0b, 0x05, 0x07, - 0x05, 0x02, 0x09, 0x0f, 0x0c, 0x04, 0x0d, 0x00, - 0x0e, 0x0a, 0x06, 0x08, 0x0b, 0x01, 0x03, 0x07, - 0x0f, 0x0d, 0x02, 0x06, 0x07, 0x08, 0x05, 0x09, - 0x00, 0x04, 0x0c, 0x03, 0x01, 0x0a, 0x0b, 0x0e, - 0x05, 0x0e, 0x02, 0x0b, 0x0d, 0x0a, 0x07, 0x00, - 0x08, 0x06, 0x04, 0x01, 0x0f, 0x0c, 0x03, 0x09, - 0x08, 0x02, 0x0f, 0x0a, 0x05, 0x09, 0x06, 0x0c, - 0x00, 0x0b, 0x01, 0x0d, 0x07, 0x03, 0x04, 0x0e, - 0x0e, 0x08, 0x00, 0x09, 0x04, 0x0b, 0x02, 0x07, - 0x0c, 0x03, 0x0a, 0x05, 0x0d, 0x01, 0x06, 0x0f, - 0x01, 0x04, 0x08, 0x0a, 0x0d, 0x0b, 0x07, 0x0e, - 0x05, 0x0f, 0x03, 0x09, 0x00, 0x02, 0x06, 0x0c, - 0x05, 0x03, 0x0c, 0x08, 0x0b, 0x02, 0x0e, 0x0a, - 0x04, 0x01, 0x0d, 0x00, 0x06, 0x07, 0x0f, 0x09, - 0x06, 0x00, 0x0b, 0x0e, 0x0d, 0x04, 0x0c, 0x0f, - 0x07, 0x02, 0x08, 0x0a, 0x01, 0x05, 0x03, 0x09, - 0x0b, 0x05, 0x0a, 0x0e, 0x0f, 0x01, 0x0c, 0x00, - 0x06, 0x04, 0x02, 0x09, 0x03, 0x0d, 0x07, 0x08, - 0x07, 0x02, 0x0a, 0x00, 0x0e, 0x08, 0x0f, 0x04, - 0x0c, 0x0b, 0x09, 0x01, 0x05, 0x0d, 0x03, 0x06, - 0x07, 0x04, 0x0f, 0x09, 0x05, 0x01, 0x0c, 0x0b, - 0x00, 0x03, 0x08, 0x0e, 0x02, 0x0a, 0x06, 0x0d, - 0x09, 0x04, 0x08, 0x00, 0x0a, 0x03, 0x01, 0x0c, - 0x05, 0x0f, 0x07, 0x02, 0x0b, 0x0e, 0x06, 0x0d, - 0x09, 0x05, 0x04, 0x07, 0x0e, 0x08, 0x03, 0x01, - 0x0d, 0x0b, 0x0c, 0x02, 0x00, 0x0f, 0x06, 0x0a, - 0x09, 0x0a, 0x0b, 0x0d, 0x05, 0x03, 0x0f, 0x00, - 0x01, 0x0c, 0x08, 0x07, 0x06, 0x04, 0x0e, 0x02, - 0x03, 0x0e, 0x0f, 0x02, 0x0d, 0x0c, 0x04, 0x05, - 0x09, 0x06, 0x00, 0x01, 0x0b, 0x07, 0x0a, 0x08 -}; - -static void -nw_passencrypt(char *old, char *new, char *out) -{ - char *p, v; - char copy[8]; - int i, di, ax; - -#define HIGH(x) (((x) >> 4) & 0xf) -#define LOW(x) ((x) & 0xf) - memcpy(copy, new, 8); - - for (i = 0; i < 16; i++) { - for (di = 0, ax = 0, p = old; di < 8; di++, ax += 0x20, p++) { - v = copy[di] ^ *p; - copy[di] = (passkeys[HIGH(v) + ax + 0x10] << 4) | - passkeys[LOW(v) + ax]; - } - v = old[7]; - for (p = old + 7; p > old; p--) { - *p = HIGH(p[-1]) | ((*p) << 4); - } - *old = HIGH(v) | (*old) << 4; - bzero(out, 8); - - for (di = 0; di < 16; di++) { - v = passkeys[di + 0x100]; - v = (v & 1) ? HIGH(copy[v / 2]) : LOW(copy[v / 2]); - out[di / 2] |= ((di & 1) ? v << 4 : v); - } - memcpy(copy, out, 8); - } -} diff --git a/lib/libncp/ncpl_conn.c b/lib/libncp/ncpl_conn.c deleted file mode 100644 index 669f836..0000000 --- a/lib/libncp/ncpl_conn.c +++ /dev/null @@ -1,511 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -/* - * - * Current scheme to create/open connection: - * 1. ncp_li_init() - lookup -S [-U] options in command line - * 2. ncp_li_init() - try to find existing connection - * 3. ncp_li_init() - if no server name and no accessible connections - bail out - * 4. This is connection candidate, read .rc file, override with command line - * and go ahead - * Note: connection referenced only via ncp_login() call. Although it is - * possible to get connection handle in other way, it will be unwise to use - * it, since conn can be destroyed at any time. - * - */ -#include <sys/param.h> -#include <sys/sysctl.h> -#include <sys/ioctl.h> -#include <sys/time.h> -#include <sys/mount.h> -#include <fcntl.h> -#include <ctype.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <pwd.h> -#include <grp.h> -#include <unistd.h> - -#include <netncp/ncp_lib.h> -#include <netncp/ncp_rcfile.h> -#include <fs/nwfs/nwfs.h> - -static char *server_name; /* need a better way ! */ - - - -int -ncp_li_setserver(struct ncp_conn_loginfo *li, const char *arg) { - if (strlen(arg) >= NCP_BINDERY_NAME_LEN) { - ncp_error("server name '%s' too long", 0, arg); - return ENAMETOOLONG; - } - ncp_str_upper(strcpy(li->server, arg)); - return 0; -} - -int -ncp_li_setuser(struct ncp_conn_loginfo *li, char *arg) { - if (arg && strlen(arg) >= NCP_BINDERY_NAME_LEN) { - ncp_error("user name '%s' too long", 0, arg); - return ENAMETOOLONG; - } - if (li->user) - free(li->user); - if (arg) { - li->user = strdup(arg); - if (li->user == NULL) - return ENOMEM; - ncp_str_upper(li->user); - } else - li->user = NULL; - return 0; -} - -int -ncp_li_setpassword(struct ncp_conn_loginfo *li, const char *passwd) { - if (passwd && strlen(passwd) >= 127) { - ncp_error("password too long", 0); - return ENAMETOOLONG; - } - if (li->password) { - bzero(li->password, strlen(li->password)); - free(li->password); - } - if (passwd) { - li->password = strdup(passwd); - if (li->password == NULL) - return ENOMEM; - } else - li->password = NULL; - return 0; -} -/* - * Prescan command line for [-S server] [-U user] arguments - * and fill li structure with defaults - */ -int -ncp_li_init(struct ncp_conn_loginfo *li, int argc, char *argv[]) { - int opt, error = 0; - char *arg; - - bzero(li,sizeof(*li)); - li->timeout = 15; /* these values should be large enough to handle */ - li->retry_count = 4; /* slow servers, even on ethernet */ - li->access_mode = 0; - li->password = NULL; - li->sig_level = 1; - li->objtype = NCP_BINDERY_USER; - li->owner = NCP_DEFAULT_OWNER; - li->group = NCP_DEFAULT_GROUP; - server_name = NULL; - if (argv == NULL) return 0; - while (error == 0 && (opt = ncp_getopt(argc, argv, ":S:U:")) != -1) { - arg = ncp_optarg; - switch (opt) { - case 'S': - error = ncp_li_setserver(li, arg); - break; - case 'U': - error = ncp_li_setuser(li, arg); - break; - } - } - ncp_optind = ncp_optreset = 1; - return error; -} - -void -ncp_li_done(struct ncp_conn_loginfo *li) { - if (li->user) - free(li->user); - if (li->password) - free(li->password); -} - -/* - * Lookup existing connection based on li structure, if connection - * found, it will be referenced. Otherwise full login sequence performed. - */ -int -ncp_li_login(struct ncp_conn_loginfo *li, int *aconnid) { - int connHandle, error; - - if ((error = ncp_conn_scan(li, &connHandle)) == 0) { - *aconnid = connHandle; - return 0; - } - error = ncp_connect(li, &connHandle); - if (error) return errno; - error = ncp_login(connHandle, li->user, li->objtype, li->password); - if (error) { - ncp_disconnect(connHandle); - } else - *aconnid = connHandle; - return error; -} - -/* - * read rc file as follows: - * 1. read [server] section - * 2. override with [server:user] section - * Since abcence of rcfile is not a bug, silently ignore that fact. - * rcfile never closed to reduce number of open/close operations. - */ -int -ncp_li_readrc(struct ncp_conn_loginfo *li) { - int i, val, error; - char uname[NCP_BINDERY_NAME_LEN*2+1]; - char *sect = NULL, *p; - - /* - * if info from cmd line incomplete, try to find existing - * connection and fill server/user from it. - */ - if (li->server[0] == 0 || li->user == NULL) { - int connHandle; - struct ncp_conn_stat cs; - - if ((error = ncp_conn_scan(li, &connHandle)) != 0) { - ncp_error("no default connection found", errno); - return error; - } - ncp_conn_getinfo(connHandle, &cs); - ncp_li_setserver(li, cs.li.server); - ncp_li_setuser(li, cs.user); - ncp_li_setpassword(li, ""); - ncp_disconnect(connHandle); - } - if (ncp_open_rcfile()) return 0; - - for (i = 0; i < 2; i++) { - switch (i) { - case 0: - sect = li->server; - break; - case 1: - strcat(strcat(strcpy(uname,li->server),":"),li->user ? li->user : "default"); - sect = uname; - break; - } - rc_getstringptr(ncp_rc, sect, "password", &p); - if (p) - ncp_li_setpassword(li, p); - rc_getint(ncp_rc,sect, "timeout", &li->timeout); - rc_getint(ncp_rc,sect, "retry_count", &li->retry_count); - rc_getint(ncp_rc,sect, "sig_level", &li->sig_level); - if (rc_getint(ncp_rc,sect,"access_mode",&val) == 0) - li->access_mode = val; - if(rc_getbool(ncp_rc,sect,"bindery",&val) == 0 && val) { - li->opt |= NCP_OPT_BIND; - } - } - return 0; -} - -/* - * check for all uncompleted fields - */ -int -ncp_li_check(struct ncp_conn_loginfo *li) { - int error = 0; - char *p; - - do { - if (li->server[0] == 0) { - ncp_error("no server name specified", 0); - error = 1; - break; - } - error = ncp_find_fileserver(li, - (server_name==NULL) ? AF_IPX : AF_INET, server_name); - if (error) { - ncp_error("can't find server %s", error, li->server); - break; - } - if (li->user == NULL || li->user[0] == 0) { - ncp_error("no user name specified for server %s", - 0, li->server); - error = 1; - break; - } - if (li->password == NULL) { - p = getpass("Netware password:"); - error = ncp_li_setpassword(li, p) ? 1 : 0; - } - } while (0); - return error; -} - -int -ncp_conn_cnt(void) { - int error, cnt = 0; - size_t len = sizeof(cnt); - - error = sysctlbyname("net.ncp.conn_cnt", &cnt, &len, NULL, 0); - if (error) cnt = 0; - return cnt; -} - -/* - * Find an existing connection and reference it - */ -int -ncp_conn_find(char *server,char *user) { - struct ncp_conn_args ca; - int connid, error; - - if (server == NULL && user == NULL) { - error = ncp_conn_scan(NULL,&connid); - if (error) return -2; - return connid; - } - if (server == NULL) - return -2; - ncp_str_upper(server); - if (user) ncp_str_upper(user); - bzero(&ca, sizeof(ca)); - ncp_li_setserver(&ca, server); - ncp_li_setuser(&ca, user); - error = ncp_conn_scan(&ca,&connid); - if (error) - connid = -1; - return connid; -} - -int -ncp_li_arg(struct ncp_conn_loginfo *li, int opt, char *arg) { - int error = 0, sig_level; - char *p, *cp; - struct group *gr; - struct passwd *pw; - - switch(opt) { - case 'S': /* we already fill server/[user] pair */ - case 'U': - break; - case 'A': - server_name = arg; - break; - case 'B': - li->opt |= NCP_OPT_BIND; - break; - case 'C': - li->opt |= NCP_OPT_NOUPCASEPASS; - break; - case 'I': - sig_level = atoi(arg); - if (sig_level < 0 || sig_level > 3) { - ncp_error("invalid NCP signature level option `%s'\ - (must be a number between 0 and 3)", 0, arg); - error = 1; - } - li->sig_level = sig_level; - if (sig_level > 1) li->opt |= NCP_OPT_SIGN; - break; - case 'M': - li->access_mode = strtol(arg, NULL, 8); - break; - case 'N': - ncp_li_setpassword(li, ""); - break; - case 'O': - p = strdup(arg); - cp = strchr(p, ':'); - if (cp) { - *cp++ = '\0'; - if (*cp) { - gr = getgrnam(cp); - if (gr) { - li->group = gr->gr_gid; - } else - ncp_error("invalid group name %s, ignored", - 0, cp); - } - } - if (*p) { - pw = getpwnam(p); - if (pw) { - li->owner = pw->pw_uid; - } else - ncp_error("invalid user name %s, ignored", 0, p); - } - endpwent(); - free(p); - break; - case 'P': - li->opt |= NCP_OPT_PERMANENT; - break; - case 'R': - li->retry_count = atoi(arg); - break; - case 'W': - li->timeout = atoi(arg); - break; - } - return error; -} - -void * -ncp_conn_list(void) { - int error, cnt = 0; - size_t len; - void *p; - - cnt = ncp_conn_cnt(); - if (cnt == 0) return NULL; - len = cnt*(sizeof(struct ncp_conn_stat))+sizeof(int); - p = malloc(len); - if (p == NULL) return NULL; - error = sysctlbyname("net.ncp.conn_stat", p, &len, NULL, 0); - if (error) { - free(p); - p = NULL; - } - return p; -} - - -int -ncp_conn_setflags(int connid, u_int16_t mask, u_int16_t flags) { - int error; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_SETFLAGS); - ncp_add_word_lh(conn, mask); - ncp_add_word_lh(conn, flags); - if ((error = ncp_conn_request(connid, conn)) < 0) - return -1; - return error; -} - -int -ncp_login(int connHandle, const char *user, int objtype, const char *password) { - int error; - struct ncp_conn_login *p; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_LOGIN); - p = (struct ncp_conn_login *)&conn->packet[conn->rqsize]; - p->username = (char *)user; - p->objtype = objtype; - p->password = (char *)password; - conn->rqsize += sizeof(*p); - if ((error = ncp_conn_request(connHandle, conn)) < 0) - return -1; - return error; -} - -int -ncp_connect_addr(struct sockaddr *sa, NWCONN_HANDLE *chp) { - int error; - struct ncp_conn_args li; - - bzero(&li, sizeof(li)); - bcopy(sa, &li.addr, sa->sa_len); - /* - * XXX Temporary !!!. server will be filled in kernel !!! - */ - strcpy(li.server,ipx_ntoa(li.ipxaddr.sipx_addr)); - error = ncp_connect(&li, chp); - return error; -} - -int -ncp_conn_getinfo(int connHandle, struct ncp_conn_stat *ps) { - int error; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_GETINFO); - if ((error = ncp_conn_request(connHandle, conn)) < 0) - return -1; - memcpy(ps, ncp_reply_data(conn,0), sizeof(*ps)); - return error; -} - -int -ncp_conn_getuser(int connHandle, char **user) { - int error; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_GETUSER); - if ((error = ncp_conn_request(connHandle, conn)) < 0) - return -1; - *user = strdup(ncp_reply_data(conn,0)); - return error; -} - -int -ncp_conn2ref(int connHandle, int *connRef) { - int error; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_CONN2REF); - if ((error = ncp_conn_request(connHandle, conn)) < 0) - return -1; - *connRef = *((int*)ncp_reply_data(conn,0)); - return error; -} - -int -ncp_path2conn(char *path, int *connHandle) { - struct statfs st; - int d, error; - - if ((error = statfs(path, &st)) != 0) return errno; - if (strcmp(st.f_fstypename,"nwfs") != 0) return EINVAL; - if ((d = open(path, O_RDONLY)) < 0) return errno; - if ((error = ioctl(d,NWFSIOC_GETCONN, connHandle)) != 0) return errno; - close(d); - return 0; -} - -int -ncp_conn_dup(NWCONN_HANDLE org, NWCONN_HANDLE *res) { - int error; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_DUP); - if ((error = ncp_conn_request(org, conn)) < 0) - return errno; - *res = *((int*)ncp_reply_data(conn, 0)); - return 0; -} diff --git a/lib/libncp/ncpl_crypt.c b/lib/libncp/ncpl_crypt.c deleted file mode 100644 index bc304c0..0000000 --- a/lib/libncp/ncpl_crypt.c +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Routines in this file based on the work of Volker Lendecke, - * Adapted for ncplib by Boris Popov - * Please note that ncpl_crypt.c file should be indentical to this one - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/errno.h> -#include <sys/malloc.h> -#include <string.h> - -/*$********************************************************* - $* - $* This code has been taken from DDJ 11/93, from an - $* article by Pawel Szczerbina. - $* - $* Password encryption routines follow. - $* Converted to C from Barry Nance's Pascal - $* prog published in the March -93 issue of Byte. - $* - $* Adapted to be useable for ncpfs by - $* Volker Lendecke <lendecke@namu01.gwdg.de> in - $* October 1995. - $* - $********************************************************* */ - - - -typedef unsigned char buf32[32]; - -static unsigned char encrypttable[256] = { -0x7, 0x8, 0x0, 0x8, 0x6, 0x4, 0xE, 0x4, 0x5, 0xC, 0x1, 0x7, 0xB, 0xF, 0xA, 0x8, -0xF, 0x8, 0xC, 0xC, 0x9, 0x4, 0x1, 0xE, 0x4, 0x6, 0x2, 0x4, 0x0, 0xA, 0xB, 0x9, -0x2, 0xF, 0xB, 0x1, 0xD, 0x2, 0x1, 0x9, 0x5, 0xE, 0x7, 0x0, 0x0, 0x2, 0x6, 0x6, -0x0, 0x7, 0x3, 0x8, 0x2, 0x9, 0x3, 0xF, 0x7, 0xF, 0xC, 0xF, 0x6, 0x4, 0xA, 0x0, -0x2, 0x3, 0xA, 0xB, 0xD, 0x8, 0x3, 0xA, 0x1, 0x7, 0xC, 0xF, 0x1, 0x8, 0x9, 0xD, -0x9, 0x1, 0x9, 0x4, 0xE, 0x4, 0xC, 0x5, 0x5, 0xC, 0x8, 0xB, 0x2, 0x3, 0x9, 0xE, -0x7, 0x7, 0x6, 0x9, 0xE, 0xF, 0xC, 0x8, 0xD, 0x1, 0xA, 0x6, 0xE, 0xD, 0x0, 0x7, -0x7, 0xA, 0x0, 0x1, 0xF, 0x5, 0x4, 0xB, 0x7, 0xB, 0xE, 0xC, 0x9, 0x5, 0xD, 0x1, -0xB, 0xD, 0x1, 0x3, 0x5, 0xD, 0xE, 0x6, 0x3, 0x0, 0xB, 0xB, 0xF, 0x3, 0x6, 0x4, -0x9, 0xD, 0xA, 0x3, 0x1, 0x4, 0x9, 0x4, 0x8, 0x3, 0xB, 0xE, 0x5, 0x0, 0x5, 0x2, -0xC, 0xB, 0xD, 0x5, 0xD, 0x5, 0xD, 0x2, 0xD, 0x9, 0xA, 0xC, 0xA, 0x0, 0xB, 0x3, -0x5, 0x3, 0x6, 0x9, 0x5, 0x1, 0xE, 0xE, 0x0, 0xE, 0x8, 0x2, 0xD, 0x2, 0x2, 0x0, -0x4, 0xF, 0x8, 0x5, 0x9, 0x6, 0x8, 0x6, 0xB, 0xA, 0xB, 0xF, 0x0, 0x7, 0x2, 0x8, -0xC, 0x7, 0x3, 0xA, 0x1, 0x4, 0x2, 0x5, 0xF, 0x7, 0xA, 0xC, 0xE, 0x5, 0x9, 0x3, -0xE, 0x7, 0x1, 0x2, 0xE, 0x1, 0xF, 0x4, 0xA, 0x6, 0xC, 0x6, 0xF, 0x4, 0x3, 0x0, -0xC, 0x0, 0x3, 0x6, 0xF, 0x8, 0x7, 0xB, 0x2, 0xD, 0xC, 0x6, 0xA, 0xA, 0x8, 0xD -}; - -static buf32 encryptkeys = { - 0x48, 0x93, 0x46, 0x67, 0x98, 0x3D, 0xE6, 0x8D, - 0xB7, 0x10, 0x7A, 0x26, 0x5A, 0xB9, 0xB1, 0x35, - 0x6B, 0x0F, 0xD5, 0x70, 0xAE, 0xFB, 0xAD, 0x11, - 0xF4, 0x47, 0xDC, 0xA7, 0xEC, 0xCF, 0x50, 0xC0 -}; - -/* - * Create table-based 16-bytes hash from a 32-bytes array - */ -static void -nw_hash(buf32 temp, unsigned char *target) { - short sum; - unsigned char b3; - int s, b2, i; - - sum = 0; - - for (b2 = 0; b2 <= 1; ++b2) { - for (s = 0; s <= 31; ++s) { - b3 = (temp[s] + sum) ^ (temp[(s + sum) & 31] - encryptkeys[s]); - sum += b3; - temp[s] = b3; - } - } - - for (i = 0; i <= 15; ++i) { - target[i] = encrypttable[temp[2 * i]] - | (encrypttable[temp[2 * i + 1]] << 4); - } -} - - -/* - * Create a 16-bytes pattern from given buffer based on a four bytes key - */ -void -nw_keyhash(const u_char *key, const u_char *buf, int buflen, u_char *target) { - int b2, d, s; - buf32 temp; - - while (buflen > 0 && buf[buflen - 1] == 0) - buflen--; - - bzero(temp, sizeof(temp)); - - d = 0; - while (buflen >= 32) { - for (s = 0; s <= 31; ++s) - temp[s] ^= buf[d++]; - buflen -= 32; - } - b2 = d; - if (buflen > 0) { - for (s = 0; s <= 31; ++s) { - if (d + buflen == b2) { - temp[s] ^= encryptkeys[s]; - b2 = d; - } else - temp[s] ^= buf[b2++]; - } - } - for (s = 0; s <= 31; ++s) - temp[s] ^= key[s & 3]; - - nw_hash(temp, target); -} - -/* - * Create an 8-bytes pattern from an 8-bytes key and 16-bytes of data - */ -void -nw_encrypt(const u_char *fra, const u_char *buf, u_char *target) { - buf32 k; - int s; - - nw_keyhash(fra, buf, 16, k); - nw_keyhash(fra + 4, buf, 16, k + 16); - - for (s = 0; s < 16; s++) - k[s] ^= k[31 - s]; - - for (s = 0; s < 8; s++) - *target++ = k[s] ^ k[15 - s]; -} - - diff --git a/lib/libncp/ncpl_file.c b/lib/libncp/ncpl_file.c deleted file mode 100644 index 042ae5a..0000000 --- a/lib/libncp/ncpl_file.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/ioctl.h> -#include <arpa/inet.h> -#include <errno.h> -#include <stdio.h> -#include <fcntl.h> -#include <unistd.h> -#include <string.h> - -#include <netncp/ncp_lib.h> -#include <netncp/ncp_file.h> -#include <fs/nwfs/nwfs.h> - -int -ncp_read(NWCONN_HANDLE connid, ncp_fh *fh, off_t offset, size_t count, char *target) { - int result; - struct ncp_rw rwrq; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_READ); - rwrq.nrw_fh = *fh; - rwrq.nrw_base = target; - rwrq.nrw_cnt = count; - rwrq.nrw_offset = offset; - ncp_add_mem(conn, &rwrq, sizeof(rwrq)); - if ((result = ncp_conn_request(connid, conn)) < 0) - return -1; - return result; -} - -int -ncp_write(NWCONN_HANDLE connid, ncp_fh *fh, off_t offset, size_t count, char *source) -{ - int result; - struct ncp_rw rwrq; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_WRITE); - rwrq.nrw_fh = *fh; - rwrq.nrw_base = source; - rwrq.nrw_cnt = count; - rwrq.nrw_offset = offset; - ncp_add_mem(conn, &rwrq, sizeof(rwrq)); - - if ((result = ncp_conn_request(connid, conn)) < 0) - return -1; - return result; -} - -int -ncp_geteinfo(char *path, struct nw_entry_info *fi) { - int d, error; - - if ((d = open(path, O_RDONLY)) < 0) return errno; - if ((error = ioctl(d, NWFSIOC_GETEINFO, fi)) != 0) return errno; - close(d); - return 0; -} - - -int -ncp_AllocTempDirHandle(char *path, NWDIR_HANDLE *pdh) { - int d; - - if ((d = open(path, O_RDONLY)) < 0) return errno; - *pdh = d; - return 0; -} - -int -ncp_DeallocateDirHandle(NWDIR_HANDLE dh) { - close(dh); - return 0; -} - -int -ncp_GetNSEntryInfo(NWDIR_HANDLE dh, struct nw_entry_info *fi, int *ns) { - int error; - - if ((error = ioctl(dh, NWFSIOC_GETEINFO, fi)) != 0) return errno; - if ((error = ioctl(dh, NWFSIOC_GETNS, ns)) != 0) return errno; - return 0; -} - -NWCCODE -ncp_ScanForDeletedFiles(NWCONN_HANDLE cH, pnuint32 iterHandle, - pnuint32 volNum, pnuint32 dirBase, nuint8 ns, - NWDELETED_INFO *entryInfo) -{ - int error; - struct nw_entry_info *pfi; - DECLARE_RQ; -#define UNITEDT(d,t) (((d) << 16) | (t)) - - bzero(entryInfo, sizeof(NWDELETED_INFO)); - ncp_init_request(conn); - ncp_add_byte(conn, 16); - ncp_add_byte(conn, ns); - ncp_add_byte(conn, 0); /* data stream */ - ncp_add_dword_lh(conn, IM_ALL & ~(IM_SPACE_ALLOCATED | IM_TOTAL_SIZE | IM_EA | IM_DIRECTORY)); - ncp_add_dword_lh(conn, *iterHandle); - - ncp_add_byte(conn, *volNum); - ncp_add_dword_lh(conn, *dirBase); - ncp_add_byte(conn, NCP_HF_DIRBASE); /* dirBase */ - ncp_add_byte(conn, 0); /* no component */ - if ((error = ncp_request(cH, 87, conn)) != 0) { - return error; - } - if (conn->rpsize < 0x61) { - return EBADRPC; /* EACCES ? */ - } - *iterHandle = entryInfo->sequence = ncp_reply_dword_lh(conn, 0x00); - entryInfo->deletedTime = ncp_reply_word_lh(conn, 0x04); - entryInfo->deletedDateAndTime = UNITEDT(ncp_reply_word_lh(conn, 0x06), entryInfo->deletedTime); - entryInfo->deletorID = ncp_reply_dword_hl(conn, 0x08); - *volNum = ncp_reply_dword_lh(conn, 0x0C); - *dirBase = ncp_reply_dword_lh(conn, 0x10); - entryInfo->parent = ncp_reply_dword_lh(conn, 0x10); - pfi = (struct nw_entry_info*) ncp_reply_data(conn, 0x14); - entryInfo->nameLength = pfi->nameLen; - memcpy(entryInfo->name, pfi->entryName, pfi->nameLen); - return error; -} - -NWCCODE -ncp_PurgeDeletedFile(NWCONN_HANDLE cH, nuint32 iterHandle, - nuint32 volNum, nuint32 dirBase, nuint8 ns) -{ - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, 18); - ncp_add_byte(conn, ns); - ncp_add_byte(conn, 0); /* reserved */ - ncp_add_dword_lh(conn, iterHandle); - ncp_add_dword_lh(conn, volNum); - ncp_add_dword_lh(conn, dirBase); - return ncp_request(cH, 87, conn); -} - - -static void -ncp_extract_entryInfo(char *data, NW_ENTRY_INFO *entry) { - u_char l; - const int info_struct_size = sizeof(NW_ENTRY_INFO) - 257; - - memcpy(entry, data, info_struct_size); - data += info_struct_size; - l = *data++; - entry->nameLen = l; - memcpy(entry->entryName, data, l); - entry->entryName[l] = '\0'; - return; -} - -NWCCODE -ncp_ScanNSEntryInfo(NWCONN_HANDLE cH, - nuint8 namSpc, nuint16 attrs, SEARCH_SEQUENCE *seq, - pnstr8 searchPattern, nuint32 retInfoMask, NW_ENTRY_INFO *entryInfo) -{ - int error, l; - DECLARE_RQ; - - if (seq->searchDirNumber == -1) { - seq->searchDirNumber = 0; - ncp_init_request(conn); - ncp_add_byte(conn, 2); - ncp_add_byte(conn, namSpc); - ncp_add_byte(conn, 0); - ncp_add_handle_path(conn, seq->volNumber, seq->dirNumber, - NCP_HF_DIRBASE, NULL); - error = ncp_request(cH, 87, conn); - if (error) return error; - memcpy(seq, ncp_reply_data(conn, 0), 9); - } - ncp_init_request(conn); - ncp_add_byte(conn, 3); - ncp_add_byte(conn, namSpc); - ncp_add_byte(conn, 0); /* dataStream */ - ncp_add_word_lh(conn, attrs); /* SearchAttributes */ - ncp_add_dword_lh(conn, retInfoMask); - ncp_add_mem(conn, seq, sizeof(*seq)); - l = strlen(searchPattern); - ncp_add_byte(conn, l); - ncp_add_mem(conn, searchPattern, l); - error = ncp_request(cH, 87, conn); - if (error) return error; - memcpy(seq, ncp_reply_data(conn, 0), sizeof(*seq)); - ncp_extract_entryInfo(ncp_reply_data(conn, 10), entryInfo); - return 0; -} - -int -ncp_NSEntryInfo(NWCONN_HANDLE cH, nuint8 ns, nuint8 vol, nuint32 dirent, - NW_ENTRY_INFO *entryInfo) -{ - DECLARE_RQ; - int error; - - ncp_init_request(conn); - ncp_add_byte(conn, 6); - ncp_add_byte(conn, ns); - ncp_add_byte(conn, ns); /* DestNameSpace */ - ncp_add_word_lh(conn, htons(0xff00)); /* get all */ - ncp_add_dword_lh(conn, IM_ALL); - ncp_add_handle_path(conn, vol, dirent, NCP_HF_DIRBASE, NULL); - error = ncp_request(cH, 87, conn); - if (error) return error; - ncp_extract_entryInfo(ncp_reply_data(conn, 0), entryInfo); - return 0; -} - -NWCCODE -NWGetVolumeName(NWCONN_HANDLE cH, u_char volume, char *name) { - int error, len; - DECLARE_RQ; - - ncp_init_request_s(conn, 44); - ncp_add_byte(conn, volume); - error = ncp_request(cH, 22, conn); - if (error) return error; - len = ncp_reply_byte(conn, 29); - if (len == 0) - return ENOENT; - bcopy(ncp_reply_data(conn, 30), name, len); - name[len] = 0; - return 0; -} diff --git a/lib/libncp/ncpl_misc.c b/lib/libncp/ncpl_misc.c deleted file mode 100644 index 67d19a9..0000000 --- a/lib/libncp/ncpl_misc.c +++ /dev/null @@ -1,294 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * calls that don't fit to any other category - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <sys/time.h> -#include <arpa/inet.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <strings.h> - -#include <netncp/ncp_lib.h> - -static time_t -ncp_nw_to_ctime(struct nw_time_buffer *source) { - struct tm u_time; - - bzero(&u_time,sizeof(struct tm)); - /* - * XXX: NW 4.x tracks daylight automatically - */ - u_time.tm_isdst = -1; - u_time.tm_sec = source->second; - u_time.tm_min = source->minute; - u_time.tm_hour = source->hour; - u_time.tm_mday = source->day; - u_time.tm_mon = source->month - 1; - u_time.tm_year = source->year; - - if (u_time.tm_year < 80) { - u_time.tm_year += 100; - } - return mktime(&u_time); -} - -int -ncp_get_file_server_information(NWCONN_HANDLE connid, - struct ncp_file_server_info *target) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 17); - if ((error = ncp_request(connid, 23, conn)) != 0) - return error; - memcpy(target, ncp_reply_data(conn, 0), sizeof(*target)); - target->MaximumServiceConnections - = htons(target->MaximumServiceConnections); - target->ConnectionsInUse - = htons(target->ConnectionsInUse); - target->MaxConnectionsEverUsed - = htons(target->MaxConnectionsEverUsed); - target->NumberMountedVolumes - = htons(target->NumberMountedVolumes); - return 0; -} - -int -ncp_get_stations_logged_info(NWCONN_HANDLE connid, u_int32_t connection, - struct ncp_bindery_object *target, time_t *login_time) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 28); - ncp_add_dword_lh(conn, connection); - - if ((error = ncp_request(connid, 23, conn)) != 0) - return error; - bzero(target, sizeof(*target)); - target->object_id = ncp_reply_dword_hl(conn, 0); - target->object_type = ncp_reply_word_hl(conn, 4); - memcpy(target->object_name, ncp_reply_data(conn, 6), - sizeof(target->object_name)); - *login_time = ncp_nw_to_ctime((struct nw_time_buffer *)ncp_reply_data(conn, 54)); - return 0; -} - -int -ncp_get_internet_address(NWCONN_HANDLE connid, u_int32_t connection, - struct ipx_addr *target, u_int8_t * conn_type) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 26); - ncp_add_dword_lh(conn, connection); - error = ncp_request(connid, 23, conn); - if (error) return error; - bzero(target, sizeof(*target)); - ipx_netlong(*target) = ncp_reply_dword_lh(conn, 0); - memcpy(&(target->x_host), ncp_reply_data(conn, 4), 6); - target->x_port = ncp_reply_word_lh(conn, 10); - *conn_type = ncp_reply_byte(conn, 12); - return 0; -} - -NWCCODE -NWGetObjectConnectionNumbers(NWCONN_HANDLE connHandle, - pnstr8 pObjName, nuint16 objType, - pnuint16 pNumConns, pnuint16 pConnHandleList, - nuint16 maxConns) -{ - int error, i, n; - nuint32 lastconn; - DECLARE_RQ; - - lastconn = 0; - ncp_init_request_s(conn, 27); - ncp_add_dword_lh(conn, lastconn); - ncp_add_word_hl(conn, objType); - ncp_add_pstring(conn, pObjName); - if ((error = ncp_request(connHandle, 23, conn)) != 0) return error; - n = min(ncp_reply_byte(conn, 0), maxConns); - *pNumConns = n; - for (i = 0; i < n ; i++) { - *pConnHandleList++ = ncp_reply_dword_lh(conn, i * 4 + 1); - } - return 0; -} - -void -NWUnpackDateTime(nuint32 dateTime, NW_DATE *sDate, NW_TIME *sTime) { - NWUnpackDate(dateTime >> 16, sDate); - NWUnpackTime(dateTime & 0xffff, sTime); -} - -void -NWUnpackDate(nuint16 date, NW_DATE *sDate) { - sDate->day = date & 0x1f; - sDate->month = (date >> 5) & 0xf; - sDate->year = ((date >> 9) & 0x7f) + 1980; -} - -void -NWUnpackTime(nuint16 time, NW_TIME *sTime) { - sTime->seconds = time & 0x1f; - sTime->minutes = (time >> 5) & 0x3f; - sTime->hours = (time >> 11) & 0x1f; -} - -nuint32 -NWPackDateTime(NW_DATE *sDate, NW_TIME *sTime) { - return 0; -} - -nuint16 -NWPackDate(NW_DATE *sDate) { - return 0; -} - -nuint16 -NWPackTime(NW_TIME *sTime) { - return 0; -} - -time_t -ncp_UnpackDateTime(nuint32 dateTime) { - struct tm u_time; - NW_DATE d; - NW_TIME t; - - NWUnpackDateTime(dateTime, &d, &t); - bzero(&u_time,sizeof(struct tm)); - u_time.tm_isdst = -1; - u_time.tm_sec = t.seconds; - u_time.tm_min = t.minutes; - u_time.tm_hour = t.hours; - u_time.tm_mday = d.day; - u_time.tm_mon = d.month - 1; - u_time.tm_year = d.year - 1900; - - return mktime(&u_time); -} - -int -ncp_GetFileServerDateAndTime(NWCONN_HANDLE cH, time_t *target) { - int error; - DECLARE_RQ; - - ncp_init_request(conn); - if ((error = ncp_request(cH, 20, conn)) != 0) - return error; - *target = ncp_nw_to_ctime((struct nw_time_buffer *) ncp_reply_data(conn, 0)); - return 0; -} - -int -ncp_SetFileServerDateAndTime(NWCONN_HANDLE cH, time_t * source) { - int year; - struct tm *utime = localtime(source); - DECLARE_RQ; - - year = utime->tm_year; - if (year > 99) { - year -= 100; - } - ncp_init_request_s(conn, 202); - ncp_add_byte(conn, year); - ncp_add_byte(conn, utime->tm_mon + 1); - ncp_add_byte(conn, utime->tm_mday); - ncp_add_byte(conn, utime->tm_hour); - ncp_add_byte(conn, utime->tm_min); - ncp_add_byte(conn, utime->tm_sec); - return ncp_request(cH, 23, conn); -} - -NWCCODE -NWDownFileServer(NWCONN_HANDLE cH, int force) { - DECLARE_RQ; - - ncp_init_request_s(conn, 211); - ncp_add_byte(conn, force ? 0 : 0xff); - return ncp_request(cH, 23, conn); -} - -NWCCODE -NWCloseBindery(NWCONN_HANDLE cH) { - DECLARE_RQ; - - ncp_init_request_s(conn, 68); - return ncp_request(cH, 23, conn); -} - -NWCCODE -NWOpenBindery(NWCONN_HANDLE cH) { - DECLARE_RQ; - - ncp_init_request_s(conn, 69); - return ncp_request(cH, 23, conn); -} - -NWCCODE -NWDisableTTS(NWCONN_HANDLE cH) { - DECLARE_RQ; - - ncp_init_request_s(conn, 207); - return ncp_request(cH, 23, conn); -} - -NWCCODE -NWEnableTTS(NWCONN_HANDLE cH) { - DECLARE_RQ; - - ncp_init_request_s(conn, 208); - return ncp_request(cH, 23, conn); -} - -NWCCODE -NWDisableFileServerLogin(NWCONN_HANDLE cH) { - DECLARE_RQ; - - ncp_init_request_s(conn, 203); - return ncp_request(cH, 23, conn); -} - -NWCCODE -NWEnableFileServerLogin(NWCONN_HANDLE cH) { - DECLARE_RQ; - - ncp_init_request_s(conn, 204); - return ncp_request(cH, 23, conn); -} diff --git a/lib/libncp/ncpl_msg.c b/lib/libncp/ncpl_msg.c deleted file mode 100644 index f2a6874..0000000 --- a/lib/libncp/ncpl_msg.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> - -#include <netncp/ncp_lib.h> -#include <netncp/ncp_nls.h> - -NWCCODE -NWDisableBroadcasts(NWCONN_HANDLE connHandle) { - DECLARE_RQ; - - ncp_init_request_s(conn, 2); - return ncp_request(connHandle, 21, conn); -} - -NWCCODE -NWEnableBroadcasts(NWCONN_HANDLE connHandle) { - DECLARE_RQ; - - ncp_init_request_s(conn, 3); - return ncp_request(connHandle, 21, conn); -} - -NWCCODE -NWBroadcastToConsole(NWCONN_HANDLE connHandle, pnstr8 message) { - int l, error; - DECLARE_RQ; - - l = strlen(message); - if (l > 60) return EMSGSIZE; - ncp_init_request_s(conn, 9); - ncp_add_byte(conn, l); - ncp_add_mem_nls(conn, message, l); - error = ncp_request(connHandle, 21, conn); - return error; -} - -NWCCODE -NWSendBroadcastMessage(NWCONN_HANDLE connHandle, pnstr8 message, - nuint16 connCount, pnuint16 connList, pnuint8 resultList) -{ - int l, i, error; - DECLARE_RQ; - - l = strlen(message); - if (l > 255) return EMSGSIZE; - if (connCount > 350) return EINVAL; - - ncp_init_request_s(conn, 0x0A); - ncp_add_word_lh(conn, connCount); - for (i = 0; i < connCount; i++) - ncp_add_dword_lh(conn, connList[i]); - ncp_add_byte(conn, l); - ncp_add_mem_nls(conn, message, l); - error = ncp_request(connHandle, 0x15, conn); - if (!error) { - l = ncp_reply_word_lh(conn, 0); - for (i = 0; i < l; i++) - resultList[i] = ncp_reply_dword_lh(conn, (i)*4 + 2); - return 0; - } - if (error != 0xfb) return error; - if (l > 58) return EMSGSIZE; - ncp_init_request_s(conn, 0); - ncp_add_byte(conn, connCount); - for (i = 0; i < connCount; i++) - ncp_add_byte(conn, connList[i]); - ncp_add_byte(conn, l); - ncp_add_mem_nls(conn, message, l); - error = ncp_request(connHandle, 0x15, conn); - if (error) return error; - i = ncp_reply_byte(conn, 0); - memcpy(resultList, ncp_reply_data(conn, 1), i); - return 0; -} - - -NWCCODE -NWGetBroadcastMessage(NWCONN_HANDLE connHandle, pnstr8 message) { - int i, error; - DECLARE_RQ; - - ncp_init_request_s(conn, 0x0B); - error = ncp_request(connHandle, 0x15, conn); - if (error) { - if (error != 0x89fb) return error; - ncp_init_request_s(conn, 0x01); - if ((error = ncp_request(connHandle, 0x15, conn)) != 0) - return error; - } - i = ncp_reply_byte(conn, 0); - if (i == 0) return ENOENT; - memcpy(message, ncp_reply_data(conn, 1), i); - message[i] = 0; - ncp_nls_str_n2u(message, message); - return 0; -} diff --git a/lib/libncp/ncpl_net.c b/lib/libncp/ncpl_net.c deleted file mode 100644 index e59bc11..0000000 --- a/lib/libncp/ncpl_net.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/errno.h> -#include <sys/syscall.h> -#include <ctype.h> -#include <netinet/in.h> -#include <netipx/ipx.h> -#include <netdb.h> -#include <string.h> -#include <stdio.h> -#include <unistd.h> - -#include "ipxsap.h" -#include <netncp/ncp_lib.h> - -static int ncp_find_server_in(struct ncp_conn_loginfo *li, int type, char *server_name); - -static int -ncp_find_server_ipx(struct ncp_conn_loginfo *li, int type) { - char server[NCP_BINDERY_NAME_LEN + 1]; - int error; - char nearest[NCP_BINDERY_NAME_LEN + 1]; - struct nw_property prop; - struct ipx_addr *n_addr = (struct ipx_addr *) ∝ -/* struct ncp_conn_loginfo ltmp;*/ - int connid; - - bzero(server, sizeof(server)); - bzero(nearest, sizeof(nearest)); - - strcpy(server, li->server); - ncp_str_upper(server); - - if ((error = sap_find_nearest(type, &li->ipxaddr, nearest)) != 0) { - return error; - } - /* if no server specified return info about nearest */ - if (!li->server[0]) { - strcpy(li->server, nearest); - return 0; - } -/* printf("%s\n",ipx_ntoa(li->ipxaddr.sipx_addr));*/ - if (strcmp(server, nearest) == 0) { - return 0; - } - /* We have to ask the nearest server for our wanted server */ - li->opt=0; - if ((error = ncp_connect(li, &connid)) != 0) { - return error; - } - if (ncp_read_property_value(connid, type, server, 1, "NET_ADDRESS", &prop) != 0) { - ncp_disconnect(connid); - return EHOSTUNREACH; - } - if ((error = ncp_disconnect(connid)) != 0) { - return error; - } - li->ipxaddr.sipx_family = AF_IPX; - li->ipxaddr.sipx_addr.x_net = n_addr->x_net; - li->ipxaddr.sipx_port = n_addr->x_port; - li->ipxaddr.sipx_addr.x_host = n_addr->x_host; - return 0; -} - -static int -ncp_find_server_in(struct ncp_conn_loginfo *li, int type, char *server_name) { - struct hostent* h; - int l; - - h = gethostbyname(server_name); - if (!h) { - fprintf(stderr, "Get host address `%s': ", server_name); - herror(NULL); - return 1; - } - if (h->h_addrtype != AF_INET) { - fprintf(stderr, "Get host address `%s': Not AF_INET\n", server_name); - return 1; - } - if (h->h_length != 4) { - fprintf(stderr, "Get host address `%s': Bad address length\n", server_name); - return 1; - } - l = sizeof(struct sockaddr_in); - bzero(&li->inaddr, l); - li->inaddr.sin_len = l; - li->inaddr.sin_family = h->h_addrtype; - memcpy(&li->inaddr.sin_addr.s_addr, h->h_addr, 4); - li->inaddr.sin_port = htons(524); /* ncp */ - return 0; -} - -int -ncp_find_server(struct ncp_conn_loginfo *li, int type, int af, char *name) { - int error = EHOSTUNREACH; - - switch(af) { - case AF_IPX: - error = ncp_find_server_ipx(li, type); - break; - case AF_INET: - if (name) - error = ncp_find_server_in(li, type, name); - break; - default: - error = EPROTONOSUPPORT; - } - return error; -} - -int -ncp_find_fileserver(struct ncp_conn_loginfo *li, int af, char *name) { - return ncp_find_server(li, NCP_BINDERY_FSERVER, af, name); -} diff --git a/lib/libncp/ncpl_nls.c b/lib/libncp/ncpl_nls.c deleted file mode 100644 index 14a26e5..0000000 --- a/lib/libncp/ncpl_nls.c +++ /dev/null @@ -1,423 +0,0 @@ -/* - * Copyright (c) 1999-2002, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -/* - * Languages support. Currently is very primitive. - */ -#include <sys/types.h> -#include <ctype.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <locale.h> - -#include <netncp/ncp_lib.h> -#include <netncp/ncp_cfg.h> -#include <netncp/ncp_nls.h> - -#ifndef NCP_NLS_DEFAULT -#define NCP_NLS_DEFAULT NCP_NLS_AS_IS -#endif - -/* - * TODO: Make all tables dynamically loadable. - */ -#ifdef NCP_NLS_KOI2CP866 -/* Russian tables from easy-cyrillic: - * Copyright (C) 1993-1994 by Andrey A. Chernov, Moscow, Russia - */ -static u_int8_t alt2koi8[] = { - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x00 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x10 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 */ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30 */ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x5f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40 */ - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50 */ - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 */ - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70 */ - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0xe1, 0xe2, 0xf7, 0xe7, 0xe4, 0xe5, 0xf6, 0xfa, - 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, - 0xf2, 0xf3, 0xf4, 0xf5, 0xe6, 0xe8, 0xe3, 0xfe, - 0xfb, 0xfd, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, - 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, - 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, - 0x90, 0x91, 0x92, 0x81, 0x87, 0xb2, 0xb4, 0xa7, - 0xa6, 0xb5, 0xa1, 0xa8, 0xae, 0xad, 0xac, 0x83, - 0x84, 0x89, 0x88, 0x86, 0x80, 0x8a, 0xaf, 0xb0, - 0xab, 0xa5, 0xbb, 0xb8, 0xb1, 0xa0, 0xbe, 0xb9, - 0xba, 0xb6, 0xb7, 0xaa, 0xa9, 0xa2, 0xa4, 0xbd, - 0xbc, 0x85, 0x82, 0x8d, 0x8c, 0x8e, 0x8f, 0x8b, - 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, - 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1, - 0xb3, 0xa3, 0x99, 0x98, 0x93, 0x9b, 0x9f, 0x97, - 0x9c, 0x95, 0x9e, 0x96, 0xbf, 0x9d, 0x94, 0x9a -}; - -static u_int8_t koi82alt[] = { - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x00 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x10 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 */ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30 */ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x5f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40 */ - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50 */ - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 */ - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70 */ - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0xc4, 0xb3, 0xda, 0xbf, 0xc0, 0xd9, 0xc3, 0xb4, /* 0x80 */ - 0xc2, 0xc1, 0xc5, 0xdf, 0xdc, 0xdb, 0xdd, 0xde, - 0xb0, 0xb1, 0xb2, 0xf4, 0xfe, 0xf9, 0xfb, 0xf7, - 0xf3, 0xf2, 0xff, 0xf5, 0xf8, 0xfd, 0xfa, 0xf6, - 0xcd, 0xba, 0xd5, 0xf1, 0xd6, 0xc9, 0xb8, 0xb7, - 0xbb, 0xd4, 0xd3, 0xc8, 0xbe, 0xbd, 0xbc, 0xc6, - 0xc7, 0xcc, 0xb5, 0xf0, 0xb6, 0xb9, 0xd1, 0xd2, - 0xcb, 0xcf, 0xd0, 0xca, 0xd8, 0xd7, 0xce, 0xfc, - 0xee, 0xa0, 0xa1, 0xe6, 0xa4, 0xa5, 0xe4, 0xa3, - 0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, - 0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0xa6, 0xa2, - 0xec, 0xeb, 0xa7, 0xe8, 0xed, 0xe9, 0xe7, 0xea, - 0x9e, 0x80, 0x81, 0x96, 0x84, 0x85, 0x94, 0x83, - 0x95, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, - 0x8f, 0x9f, 0x90, 0x91, 0x92, 0x93, 0x86, 0x82, /* 0xf0 */ - 0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a -}; - -#endif - -/* - * Characters mapping for codepages used in Sweden. - */ -static u_int8_t se_nw2unix[] = { - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x00 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x10 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 */ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30 */ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x5f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40 */ - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50 */ - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 */ - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70 */ - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0xe1, 0xe2, 0xf7, 0xe7, 0xE4, 0xc4, 0xE5, 0xfa, /* 0x80 */ - 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xC4, 0xC5, - 0xf2, 0xf3, 0xf4, 0xf5, 0xF6, 0xe8, 0xe3, 0xfe, /* 0x90 */ - 0xfb, 0xD6, 0xff, 0xf9, 0xf8, 0xfc, 0xe0, 0xf1, - 0xc1, 0xc2, 0xd7, 0xc7, 0xc4, 0xc5, 0xd6, 0xda, /* 0xA0 */ - 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, - 0x90, 0x91, 0x92, 0x81, 0x87, 0xb2, 0xb4, 0xa7, /* 0xB0 */ - 0xa6, 0xb5, 0xa1, 0xa8, 0xae, 0xad, 0xac, 0x83, - 0x84, 0x89, 0x88, 0x86, 0x80, 0x8a, 0xaf, 0xb0, /* 0xC0 */ - 0xab, 0xa5, 0xbb, 0xb8, 0xb1, 0xa0, 0xbe, 0xb9, - 0xba, 0xb6, 0xb7, 0xaa, 0xa9, 0xa2, 0xa4, 0xbd, /* 0xD0 */ - 0xbc, 0x85, 0x82, 0x8d, 0x8c, 0x8e, 0x8f, 0x8b, - 0xd2, 0xd3, 0xd4, 0xd5, 0xc6, 0xc8, 0xc3, 0xde, /* 0xE0 */ - 0xdb, 0xdd, 0xdf, 0xd9, 0xd8, 0xdc, 0xc0, 0xd1, - 0xb3, 0xa3, 0x99, 0x98, 0x93, 0x9b, 0x9f, 0x97, /* 0xF0 */ - 0x9c, 0x95, 0x9e, 0x96, 0xbf, 0x9d, 0x94, 0x9a -}; - -static u_int8_t se_unix2nw[] = { - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x00 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x10 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 */ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30 */ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x5f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40 */ - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50 */ - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 */ - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70 */ - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0xc4, 0xb3, 0xda, 0xbf, 0xc0, 0xd9, 0xc3, 0xb4, /* 0x80 */ - 0xc2, 0xc1, 0xc5, 0xdf, 0xdc, 0xdb, 0xdd, 0xde, - 0xb0, 0xb1, 0xb2, 0xf4, 0xfe, 0xf9, 0xfb, 0xf7, /* 0x90 */ - 0xf3, 0xf2, 0xff, 0xf5, 0xf8, 0xfd, 0xfa, 0xf6, - 0xcd, 0xba, 0xd5, 0xf1, 0xd6, 0xc9, 0xb8, 0xb7, /* 0xA0 */ - 0xbb, 0xd4, 0xd3, 0xc8, 0xbe, 0xbd, 0xbc, 0xc6, - 0xc7, 0xcc, 0xb5, 0xf0, 0xb6, 0xb9, 0xd1, 0xd2, /* 0xB0 */ - 0xcb, 0xcf, 0xd0, 0xca, 0xd8, 0xd7, 0xce, 0xfc, - 0xee, 0xa0, 0xa1, 0xe6, 0x8E, 0x8F, 0xe4, 0xa3, /* 0xC0 */ - 0xe5, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, - 0xaf, 0xef, 0xe0, 0xe1, 0xe2, 0xe3, 0x99, 0xa2, /* 0xD0 */ - 0xec, 0xeb, 0xa7, 0xe8, 0xed, 0xe9, 0xe7, 0xea, - 0x9e, 0x80, 0x81, 0x96, 0x84, 0x86, 0x94, 0x83, /* 0xE0 */ - 0x95, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, - 0x8f, 0x9f, 0x90, 0x91, 0x92, 0x93, 0x94, 0x82, /* 0xf0 */ - 0x9c, 0x9b, 0x87, 0x98, 0x9d, 0x99, 0x97, 0x9a -}; - -/* - * Characters mapping for codepages used in Germany. - */ -static u_int8_t de_nw2unix[] = { - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x00 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0xb6, 0xa7, 0x5f, 0x5f, /* 0x10 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 */ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30 */ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40 */ - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50 */ - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 */ - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70 */ - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7, /* 0x80 */ - 0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5, - 0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9, /* 0x90 */ - 0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x5f, 0x5f, - 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba, /* 0xA0 */ - 0xbf, 0x5f, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0xB0 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0xC0 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0xD0 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0xdf, 0x5f, 0x5f, 0x5f, 0x5f, 0xb5, 0x5f, /* 0xE0 */ - 0x5f, 0x5f, 0x5f, 0xf0, 0x5f, 0xf8, 0x5f, 0x5f, - 0x5f, 0xb1, 0x5f, 0x5f, 0x5f, 0x5f, 0xf7, 0x5f, /* 0xF0 */ - 0xb0, 0x5f, 0xb7, 0x5f, 0x5f, 0xb2, 0x5f, 0xa0 -}; - -static u_int8_t de_unix2nw[] = { - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x00 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x10 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, /* 0x20 */ - 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* 0x30 */ - 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* 0x40 */ - 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, /* 0x50 */ - 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 0x60 */ - 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, /* 0x70 */ - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x80 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, /* 0x90 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0xff, 0xad, 0x9b, 0x9c, 0x5f, 0x9d, 0x5f, 0x15, /* 0xA0 */ - 0x5f, 0x5f, 0xa6, 0xae, 0xaa, 0x5f, 0x5f, 0x5f, - 0xf8, 0xf1, 0xfd, 0x5f, 0x5f, 0xe6, 0x14, 0xfa, /* 0xB0 */ - 0x5f, 0x5f, 0xa7, 0xaf, 0xac, 0xab, 0x5f, 0xa8, - 0x5f, 0x5f, 0x5f, 0x5f, 0x8e, 0x8f, 0x92, 0x80, /* 0xC0 */ - 0x5f, 0x90, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, 0x5f, - 0x5f, 0xa5, 0x5f, 0x5f, 0x5f, 0x5f, 0x99, 0x5f, /* 0xD0 */ - 0x5f, 0x5f, 0x5f, 0x5f, 0x9a, 0x5f, 0x5f, 0xe1, - 0x85, 0xa0, 0x83, 0x5f, 0x84, 0x86, 0x91, 0x87, /* 0xE0 */ - 0x8a, 0x82, 0x88, 0x89, 0x8d, 0xa1, 0x8c, 0x8b, - 0xeb, 0xa4, 0x95, 0xa2, 0x93, 0x5f, 0x94, 0xf6, /* 0xF0 */ - 0xed, 0x97, 0xa3, 0x96, 0x81, 0x5f, 0x5f, 0x98 -}; - - -static u_int8_t def2lower[256]; -static u_int8_t def2upper[256]; - -/* - * List of available charsets - */ -struct ncp_nlsdesc { - int scheme; - char *name; - struct ncp_nlstables nls; -}; - -static struct ncp_nlsdesc ncp_nlslist[] = { - {NCP_NLS_AS_IS, NCP_NLS_AS_IS_NAME, - {def2lower, def2upper, NULL, NULL, 0} - }, -#ifdef NCP_NLS_KOI2CP866 - {NCP_NLS_KOI_866, NCP_NLS_KOI_866_NAME, - {def2lower, def2upper, alt2koi8, koi82alt, 0} - }, -#endif - {NCP_NLS_SE, NCP_NLS_SE_NAME, - {def2lower, def2upper, se_nw2unix, se_unix2nw, 0} - }, - {NCP_NLS_DE, NCP_NLS_DE_NAME, - {def2lower, def2upper, de_nw2unix, de_unix2nw, 0} - }, - {0} -}; - -struct ncp_nlstables ncp_nls; - -int -ncp_nls_setlocale(char *name) { - int i; - - ncp_nls.to_lower = def2lower; - ncp_nls.to_upper = def2upper; - if (setlocale(LC_CTYPE, name) == NULL) { - fprintf(stderr, "Can't set locale '%s'\n", name); - return EINVAL; - } - for (i = 0; i < 256; i++) { - ncp_nls.to_lower[i] = tolower(i); - ncp_nls.to_upper[i] = toupper(i); - } - return 0; -} - -int -ncp_nls_setrecode(int scheme) { - struct ncp_nlsdesc *nd; - - if (scheme == 0) { -#if NCP_NLS_DEFAULT - scheme = NCP_NLS_DEFAULT; -#else - scheme = NCP_NLS_AS_IS; -#endif - } - for (nd = ncp_nlslist; nd->name; nd++) { - if (nd->scheme != scheme) continue; - ncp_nls.u2n = nd->nls.u2n; - ncp_nls.n2u = nd->nls.n2u; - return ncp_nls_setlocale(""); - } - fprintf(stderr, "Character conversion scheme %d was not compiled in\n", scheme); - return EINVAL; -} - -int -ncp_nls_setrecodebyname(char *name) { - struct ncp_nlsdesc *nd; - - for (nd = ncp_nlslist; nd->name; nd++) { - if (strcmp(nd->name, name) != 0) continue; - ncp_nls.u2n = nd->nls.u2n; - ncp_nls.n2u = nd->nls.n2u; - return 0; - } - fprintf(stderr, "Character conversion scheme %s was not compiled in\n", name); - return EINVAL; -} - -char * -ncp_nls_str_n2u(char *dst, const char *src) { - char *p; - - if (ncp_nls.n2u == NULL) { - return strcpy(dst, src); - } - p = dst; - while (*src) - *p++ = ncp_nls.n2u[(u_char)*(src++)]; - *p = 0; - return dst; -} - -char * -ncp_nls_str_u2n(char *dst, const char *src) { - char *p; - - if (ncp_nls.u2n == NULL) { - return strcpy(dst, src); - } - p = dst; - while (*src) - *p++ = ncp_nls.u2n[(u_char)*(src++)]; - *p = 0; - return dst; -} - -char * -ncp_nls_mem_n2u(char *dst, const char *src, int size) { - char *p; - - if (size == 0) return NULL; - if (ncp_nls.n2u == NULL) { - return memcpy(dst, src, size); - } - for(p = dst; size; size--, p++) - *p = ncp_nls.n2u[(u_char)*(src++)]; - return dst; -} - -char * -ncp_nls_mem_u2n(char *dst, const char *src, int size) { - char *p; - - if (size == 0) return NULL; - if (ncp_nls.u2n == NULL) { - return strcpy(dst, src); - } - for(p = dst; size; size--, p++) - *p = ncp_nls.u2n[(u_char)*(src++)]; - return dst; -} - -char * -ncp_str_upper(char *s) { - char *p = s; - while (*s) { - *s = toupper(*s); - s++; - } - return p; -} diff --git a/lib/libncp/ncpl_queue.c b/lib/libncp/ncpl_queue.c deleted file mode 100644 index 0512ce9..0000000 --- a/lib/libncp/ncpl_queue.c +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * NetWare queue interface - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <netncp/ncp_lib.h> - -int -ncp_create_queue_job_and_file(NWCONN_HANDLE connid, u_int32_t queue_id, - struct queue_job *job) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 121); - ncp_add_dword_hl(conn, queue_id); - ncp_add_mem(conn, &(job->j), sizeof(job->j)); - - if ((error = ncp_request(connid, 23, conn)) != 0) - return error; - memcpy(&(job->j), ncp_reply_data(conn, 0), 78); - ConvertToNWfromDWORD(job->j.JobFileHandle, &job->file_handle); - return 0; -} - -int -ncp_close_file_and_start_job(NWCONN_HANDLE connid, u_int32_t queue_id, - struct queue_job *job) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 127); - ncp_add_dword_hl(conn, queue_id); - ncp_add_dword_lh(conn, job->j.JobNumber); - error = ncp_request(connid, 23, conn); - return error; -} - -int -ncp_attach_to_queue(NWCONN_HANDLE connid, u_int32_t queue_id) { - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 111); - ncp_add_dword_hl(conn, queue_id); - error = ncp_request(connid, 23, conn); - return error; -} - -int -ncp_detach_from_queue(NWCONN_HANDLE connid, u_int32_t queue_id) { - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 112); - ncp_add_dword_hl(conn, queue_id); - error= ncp_request(connid, 23, conn); - return error; -} - -int -ncp_service_queue_job(NWCONN_HANDLE connid, u_int32_t queue_id, - u_int16_t job_type, struct queue_job *job) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 124); - ncp_add_dword_hl(conn, queue_id); - ncp_add_word_hl(conn, job_type); - if ((error = ncp_request(connid, 23, conn)) != 0) { - return error; - } - memcpy(&(job->j), ncp_reply_data(conn, 0), 78); - ConvertToNWfromDWORD(job->j.JobFileHandle, &job->file_handle); - return error; -} - -int -ncp_finish_servicing_job(NWCONN_HANDLE connid, u_int32_t queue_id, - u_int32_t job_number, u_int32_t charge_info) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 131); - ncp_add_dword_hl(conn, queue_id); - ncp_add_dword_lh(conn, job_number); - ncp_add_dword_hl(conn, charge_info); - - error = ncp_request(connid, 23, conn); - return error; -} - -int -ncp_abort_servicing_job(NWCONN_HANDLE connid, u_int32_t queue_id, - u_int32_t job_number) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 132); - ncp_add_dword_hl(conn, queue_id); - ncp_add_dword_lh(conn, job_number); - error = ncp_request(connid, 23, conn); - return error; -} - -int -ncp_get_queue_length(NWCONN_HANDLE connid, u_int32_t queue_id, - u_int32_t *queue_length) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn, 125); - ncp_add_dword_hl(conn, queue_id); - - if ((error = ncp_request(connid, 23, conn)) != 0) - return error; - if (conn->rpsize < 12) { - ncp_printf("ncp_reply_size %d < 12\n", conn->rpsize); - return EINVAL; - } - if (ncp_reply_dword_hl(conn,0) != queue_id) { - printf("Ouch! Server didn't reply with same queue id in ncp_get_queue_length!\n"); - return EINVAL; - } - *queue_length = ncp_reply_dword_lh(conn,8); - return error; -} - -int -ncp_get_queue_job_ids(NWCONN_HANDLE connid, u_int32_t queue_id, - u_int32_t queue_section, u_int32_t *length1, u_int32_t *length2, - u_int32_t ids[]) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn,129); - ncp_add_dword_hl(conn, queue_id); - ncp_add_dword_lh(conn, queue_section); - - if ((error = ncp_request(connid, 23, conn)) != 0) - return error; - if (conn->rpsize < 8) { - ncp_printf("ncp_reply_size %d < 8\n", conn->rpsize); - return EINVAL; - } - *length2 = ncp_reply_dword_lh(conn,4); - if (conn->rpsize < 8 + 4*(*length2)) { - ncp_printf("ncp_reply_size %d < %d\n", conn->rpsize, 8+4*(*length2)); - return EINVAL; - } - if (ids) { - int count = min(*length1, *length2)*sizeof(u_int32_t); - int pos; - - for (pos=0; pos<count; pos+=sizeof(u_int32_t)) { - *ids++ = ncp_reply_dword_lh(conn, 8+pos); - } - } - *length1 = ncp_reply_dword_lh(conn,0); - return error; -} - -int -ncp_get_queue_job_info(NWCONN_HANDLE connid, u_int32_t queue_id, - u_int32_t job_id, struct nw_queue_job_entry *jobdata) -{ - int error; - DECLARE_RQ; - - ncp_init_request_s(conn,122); - ncp_add_dword_hl(conn, queue_id); - ncp_add_dword_lh(conn, job_id); - - if ((error = ncp_request(connid, 23, conn)) != 0) - return error; - - if (conn->rpsize < sizeof(struct nw_queue_job_entry)) { - ncp_printf("ncp_reply_size %d < %d\n", conn->rpsize,sizeof(struct nw_queue_job_entry)); - return EINVAL; - } - memcpy(jobdata,ncp_reply_data(conn,0), sizeof(struct nw_queue_job_entry)); - return error; -} diff --git a/lib/libncp/ncpl_rcfile.c b/lib/libncp/ncpl_rcfile.c deleted file mode 100644 index deb16c7..0000000 --- a/lib/libncp/ncpl_rcfile.c +++ /dev/null @@ -1,406 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <sys/queue.h> -#include <ctype.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <pwd.h> -#include <unistd.h> - -#include <netncp/ncp_lib.h> -#include <netncp/ncp_rcfile.h> -#include <netncp/ncp_cfg.h> - -#define NWFS_CFG_FILE NCP_PREFIX"/etc/nwfs.conf" - -struct rcfile *ncp_rc = NULL; - -SLIST_HEAD(rcfile_head, rcfile); -static struct rcfile_head pf_head = {NULL}; - -int rc_merge(char *filename,struct rcfile **rcfile); -static struct rcfile* rc_find(char *filename); -static struct rcsection *rc_findsect(struct rcfile *rcp, char *sectname); -static struct rcsection *rc_addsect(struct rcfile *rcp, char *sectname); -static int rc_sect_free(struct rcsection *rsp); -static struct rckey *rc_sect_findkey(struct rcsection *rsp, char *keyname); -static struct rckey *rc_sect_addkey(struct rcsection *rsp, char *name, char *value); -static void rc_key_free(struct rckey *p); -static void rc_parse(struct rcfile *rcp); - - -/* - * open rcfile and load its content, if already open - return previous handle - */ -int -rc_open(char *filename,char *mode,struct rcfile **rcfile) { - struct rcfile *rcp; - FILE *f; - - rcp = rc_find(filename); - if( rcp ) { - *rcfile = rcp; - return 0; - } - f = fopen (filename, mode); - if (f==NULL) - return errno; - rcp = malloc(sizeof(struct rcfile)); - if (rcp==NULL) { - fclose(f); - return ENOMEM; - } - bzero(rcp, sizeof(struct rcfile)); - rcp->rf_name = strdup (filename); - rcp->rf_f = f; - SLIST_INSERT_HEAD(&pf_head, rcp, rf_next); - rc_parse(rcp); - *rcfile = rcp; - return 0; -} - -int -rc_merge(char *filename,struct rcfile **rcfile) { - struct rcfile *rcp = *rcfile; - FILE *f, *t; - - if (rcp == NULL) { - return rc_open(filename,"r",rcfile); - } - f = fopen (filename, "r"); - if (f==NULL) - return errno; - t = rcp->rf_f; - rcp->rf_f = f; - rc_parse(rcp); - rcp->rf_f = t; - fclose(f); - return 0; -} - -int -rc_close(struct rcfile *rcp) { - struct rcsection *p,*n; - - fclose(rcp->rf_f); - for(p = SLIST_FIRST(&rcp->rf_sect);p;) { - n = p; - p = SLIST_NEXT(p,rs_next); - rc_sect_free(n); - } - free(rcp->rf_name); - SLIST_REMOVE(&pf_head, rcp, rcfile, rf_next); - free(rcp); - return 0; -} - -static struct rcfile* -rc_find(char *filename) { - struct rcfile *p; - - SLIST_FOREACH(p, &pf_head, rf_next) - if (strcmp (filename, p->rf_name)==0) - return p; - return 0; -} - -static struct rcsection * -rc_findsect(struct rcfile *rcp, char *sectname) { - struct rcsection *p; - - SLIST_FOREACH(p, &rcp->rf_sect, rs_next) - if (strcmp(p->rs_name, sectname)==0) - return p; - return NULL; -} - -static struct rcsection * -rc_addsect(struct rcfile *rcp, char *sectname) { - struct rcsection *p; - - p = rc_findsect(rcp, sectname); - if (p) return p; - p = malloc(sizeof(*p)); - if (!p) return NULL; - p->rs_name = strdup(sectname); - SLIST_INIT(&p->rs_keys); - SLIST_INSERT_HEAD(&rcp->rf_sect, p, rs_next); - return p; -} - -static int -rc_sect_free(struct rcsection *rsp) { - struct rckey *p,*n; - - for(p = SLIST_FIRST(&rsp->rs_keys);p;) { - n = p; - p = SLIST_NEXT(p,rk_next); - rc_key_free(n); - } - free(rsp->rs_name); - free(rsp); - return 0; -} - -static struct rckey * -rc_sect_findkey(struct rcsection *rsp, char *keyname) { - struct rckey *p; - - SLIST_FOREACH(p, &rsp->rs_keys, rk_next) - if (strcmp(p->rk_name, keyname)==0) - return p; - return NULL; -} - -static struct rckey * -rc_sect_addkey(struct rcsection *rsp, char *name, char *value) { - struct rckey *p; - - p = rc_sect_findkey(rsp, name); - if (p) { - free(p->rk_value); - } else { - p = malloc(sizeof(*p)); - if (!p) return NULL; - SLIST_INSERT_HEAD(&rsp->rs_keys, p, rk_next); - p->rk_name = strdup(name); - } - p->rk_value = value ? strdup(value) : strdup(""); - return p; -} - -void -rc_sect_delkey(struct rcsection *rsp, struct rckey *p) { - - SLIST_REMOVE(&rsp->rs_keys,p,rckey,rk_next); - rc_key_free(p); - return; -} - -static void -rc_key_free(struct rckey *p){ - free(p->rk_value); - free(p->rk_name); - free(p); -} - -enum { stNewLine, stHeader, stSkipToEOL, stGetKey, stGetValue}; - -static void -rc_parse(struct rcfile *rcp) { - FILE *f = rcp->rf_f; - int state = stNewLine, c; - struct rcsection *rsp = NULL; - struct rckey *rkp = NULL; - char buf[2048]; - char *next = buf, *last = &buf[sizeof(buf)-1]; - - while ((c = getc (f)) != EOF) { - if (c == '\r') - continue; - if (state == stNewLine) { - next = buf; - if (isspace(c)) - continue; /* skip leading junk */ - if (c == '[') { - state = stHeader; - rsp = NULL; - continue; - } - if (c == '#' || c == ';') { - state = stSkipToEOL; - } else { /* something meaningfull */ - state = stGetKey; - } - } - if (state == stSkipToEOL || next == last) {/* ignore long lines */ - if (c == '\n'){ - state = stNewLine; - next = buf; - } - continue; - } - if (state == stHeader) { - if (c == ']') { - *next = 0; - next = buf; - rsp = rc_addsect(rcp, buf); - state = stSkipToEOL; - } else - *next++ = c; - continue; - } - if (state == stGetKey) { - if (c == ' ' || c == '\t')/* side effect: 'key name='*/ - continue; /* become 'keyname=' */ - if (c == '\n') { /* silently ignore ... */ - state = stNewLine; - continue; - } - if (c != '=') { - *next++ = c; - continue; - } - *next = 0; - if (rsp == NULL) { - fprintf(stderr, "Key '%s' defined before section\n", buf); - state = stSkipToEOL; - continue; - } - rkp = rc_sect_addkey(rsp, buf, NULL); - next = buf; - state = stGetValue; - continue; - } - /* only stGetValue left */ - if (state != stGetValue) { - fprintf(stderr, "Well, I can't parse file '%s'\n",rcp->rf_name); - state = stSkipToEOL; - } - if (c != '\n') { - *next++ = c; - continue; - } - *next = 0; - rkp->rk_value = strdup(buf); - state = stNewLine; - rkp = NULL; - } /* while */ - if (c == EOF && state == stGetValue) { - *next = 0; - rkp->rk_value = strdup(buf); - } - return; -} - -int -rc_getstringptr(struct rcfile *rcp,char *section, char *key,char **dest) { - struct rcsection *rsp; - struct rckey *rkp; - - *dest = NULL; - rsp = rc_findsect(rcp, section); - if (!rsp) return ENOENT; - rkp = rc_sect_findkey(rsp,key); - if (!rkp) return ENOENT; - *dest = rkp->rk_value; - return 0; -} - -int -rc_getstring(struct rcfile *rcp,char *section, char *key,int maxlen,char *dest) { - char *value; - int error; - - error = rc_getstringptr(rcp, section, key, &value); - if (error) return error; - if (strlen(value) >= maxlen) { - fprintf(stderr, "line too long for key '%s' in section '%s', max = %d\n",key, section, maxlen); - return EINVAL; - } - strcpy(dest,value); - return 0; -} - -int -rc_getint(struct rcfile *rcp,char *section, char *key,int *value) { - struct rcsection *rsp; - struct rckey *rkp; - - rsp = rc_findsect(rcp, section); - if (!rsp) return ENOENT; - rkp = rc_sect_findkey(rsp,key); - if (!rkp) return ENOENT; - errno = 0; - *value = strtol(rkp->rk_value,NULL,0); - if (errno) { - fprintf(stderr, "invalid int value '%s' for key '%s' in section '%s'\n",rkp->rk_value,key,section); - return errno; - } - return 0; -} - -/* - * 1,yes,true - * 0,no,false - */ -int -rc_getbool(struct rcfile *rcp,char *section, char *key,int *value) { - struct rcsection *rsp; - struct rckey *rkp; - char *p; - - rsp = rc_findsect(rcp, section); - if (!rsp) return ENOENT; - rkp = rc_sect_findkey(rsp,key); - if (!rkp) return ENOENT; - p = rkp->rk_value; - while (*p && isspace(*p)) p++; - if (*p == '0' || strcasecmp(p,"no") == 0 || strcasecmp(p,"false") == 0) { - *value = 0; - return 0; - } - if (*p == '1' || strcasecmp(p,"yes") == 0 || strcasecmp(p,"true") == 0) { - *value = 1; - return 0; - } - fprintf(stderr, "invalid boolean value '%s' for key '%s' in section '%s' \n",p, key, section); - return EINVAL; -} - -/* - * first read ~/.nwfsrc, next try to merge NWFS_CFG_FILE - */ -int -ncp_open_rcfile(void) { - char *home, *fn; - int error; - - home = getenv("HOME"); - if (home) { - fn = malloc(strlen(home) + 20); - sprintf(fn, "%s/.nwfsrc", home); - error = rc_open(fn,"r",&ncp_rc); - free (fn); - } - error = rc_merge(NWFS_CFG_FILE, &ncp_rc); - if( ncp_rc == NULL ) { - printf("Warning: no cfg files found.\n"); - return 1; - } - return 0; -} - diff --git a/lib/libncp/ncpl_rpc.c b/lib/libncp/ncpl_rpc.c deleted file mode 100644 index 87c601a..0000000 --- a/lib/libncp/ncpl_rpc.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * NetWare RPCs - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <sys/time.h> -#include <arpa/inet.h> -#include <errno.h> -#include <stdio.h> -#include <string.h> -#include <netncp/ncp_lib.h> - -struct ncp_rpc_rq { - nuint16 len; /* HL */ - nuint8 subfn; - nuint32 reserved[4]; - nuint8 flags[4]; -} __attribute__ ((packed)); - -struct ncp_rpc_rp { - nuint32 rpccode; - nuint32 reserved[4]; - nuint32 rpcval; -} __attribute__ ((packed)); - -static NWCCODE -ncp_rpc(NWCONN_HANDLE cH, int rpcfn, - const nuint8* rpcarg, char* arg1, char *arg2, - nuint32* rpcval) { - NWCCODE error; - NW_FRAGMENT rq[4], rp; - struct ncp_rpc_rq rqh; - struct ncp_rpc_rp rph; - - rqh.subfn = rpcfn; - if (rpcarg) - bcopy(rpcarg, rqh.reserved, 4 * 4 + 4); - else - bzero(rqh.reserved, 4 * 4 + 4); - rq[0].fragAddress = (char*)&rqh; - rq[0].fragSize = sizeof(rqh); - rq[1].fragAddress = arg1; - rq[1].fragSize = strlen(arg1) + 1; - rq[2].fragAddress = arg2; - rq[2].fragSize = arg2 ? (strlen(arg2) + 1) : 0; - rqh.len = htons(rq[2].fragSize + rq[1].fragSize + sizeof(rqh) - 2); - rp.fragAddress = (char*)&rph; - rp.fragSize = sizeof(rph); - error = NWRequest(cH, 131, 3, rq, 1, &rp); - if (error) return error; - if (rp.fragSize < 4) return EBADRPC; - error = rph.rpccode; - if (error) return error; - if (rpcval) { - if (rp.fragSize < 24) - return EBADRPC; - *rpcval = rph.rpcval; - } - return 0; -} - -NWCCODE -NWSMLoadNLM(NWCONN_HANDLE cH, pnstr8 cmd) { - return ncp_rpc(cH, 1, NULL, cmd, NULL, NULL); -} - -NWCCODE -NWSMUnloadNLM(NWCONN_HANDLE cH, pnstr8 cmd) { - return ncp_rpc(cH, 2, NULL, cmd, NULL, NULL); -} - -NWCCODE -NWSMMountVolume(NWCONN_HANDLE cH, pnstr8 volName, nuint32* volnum) { - return ncp_rpc(cH, 3, NULL, volName, NULL, volnum); -} - -NWCCODE -NWSMDismountVolumeByName(NWCONN_HANDLE cH, pnstr8 vol) { - return ncp_rpc(cH, 4, NULL, vol, NULL, NULL); -} - -struct ncp_set_hdr { - nuint32 typeFlag; /* 0 - str, 1 - value */ - nuint32 value; - nuint32 pad[20 - 4 - 4]; -} __attribute__ ((packed)); - -NWCCODE -NWSMSetDynamicCmdIntValue(NWCONN_HANDLE cH, pnstr8 setCommandName, nuint32 cmdValue) { - struct ncp_set_hdr rq; - - memset(&rq, 0, sizeof(rq)); - rq.typeFlag = 1; - rq.value = cmdValue; - return ncp_rpc(cH, 6, (char*)&rq, setCommandName, NULL, NULL); -} - -NWCCODE -NWSMSetDynamicCmdStrValue(NWCONN_HANDLE cH, pnstr8 setCommandName, - pnstr8 cmdValue) { - return ncp_rpc(cH, 6, NULL, setCommandName, cmdValue, NULL); -} - -NWCCODE -NWSMExecuteNCFFile(NWCONN_HANDLE cH, pnstr8 NCFFileName) { - return ncp_rpc(cH, 7, NULL, NCFFileName, NULL, NULL); -} diff --git a/lib/libncp/ncpl_subr.c b/lib/libncp/ncpl_subr.c deleted file mode 100644 index 3c328ce..0000000 --- a/lib/libncp/ncpl_subr.c +++ /dev/null @@ -1,490 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/param.h> -#include <sys/types.h> -#include <sys/errno.h> -#include <sys/sysctl.h> -#include <sys/ioctl.h> -#include <unistd.h> -#include <ctype.h> -#include <fcntl.h> -#include <paths.h> -#include <string.h> -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> - -#include <netncp/ncp_lib.h> -#include <netncp/ncp_rcfile.h> -#include <netncp/ncp_nls.h> -/*#include <netncp/ncp_cfg.h>*/ -#include <netncp/ncpio.h> - -#define _PATH_NCP _PATH_DEV NCP_NAME - -void -ncp_add_word_lh(struct ncp_buf *conn, u_int16_t x) { - setwle(conn->packet, conn->rqsize, x); - conn->rqsize += 2; - return; -} - -void -ncp_add_dword_lh(struct ncp_buf *conn, u_int32_t x) { - setdle(conn->packet, conn->rqsize, x); - conn->rqsize += 4; - return; -} - -void -ncp_add_word_hl(struct ncp_buf *conn, u_int16_t x){ - setwbe(conn->packet, conn->rqsize, x); - conn->rqsize += 2; - return; -} - -void -ncp_add_dword_hl(struct ncp_buf *conn, u_int32_t x) { - setdbe(conn->packet, conn->rqsize, x); - conn->rqsize += 4; - return; -} - -void -ncp_add_mem(struct ncp_buf *conn, const void *source, int size) { - memcpy(conn->packet+conn->rqsize, source, size); - conn->rqsize += size; - return; -} - -void -ncp_add_mem_nls(struct ncp_buf *conn, const void *source, int size) { - ncp_nls_mem_u2n(conn->packet+conn->rqsize, source, size); - conn->rqsize += size; - return; -} - -void -ncp_add_pstring(struct ncp_buf *conn, const char *s) { - int len = strlen(s); - if (len > 255) { - ncp_printf("ncp_add_pstring: string too long: %s\n", s); - len = 255; - } - ncp_add_byte(conn, len); - ncp_add_mem(conn, s, len); - return; -} - -void -ncp_add_handle_path(struct ncp_buf *conn, nuint32 volNumber, nuint32 dirNumber, - int handleFlag, const char *path) -{ - ncp_add_byte(conn, volNumber); - ncp_add_dword_lh(conn, dirNumber); - ncp_add_byte(conn, handleFlag); - if (path) { - ncp_add_byte(conn, 1); /* 1 component */ - ncp_add_pstring(conn, path); - } else { - ncp_add_byte(conn, 0); - } -} - -void -ncp_init_request(struct ncp_buf *conn) { - conn->rqsize = 0; - conn->rpsize = 0; -} - -void -ncp_init_request_s(struct ncp_buf *conn, int subfn) { - ncp_init_request(conn); - ncp_add_word_lh(conn, 0); - ncp_add_byte(conn, subfn); -} - -u_int16_t -ncp_reply_word_hl(struct ncp_buf *conn, int offset) { - return getwbe(ncp_reply_data(conn, offset), 0); -} - -u_int16_t -ncp_reply_word_lh(struct ncp_buf *conn, int offset) { - return getwle(ncp_reply_data(conn, offset), 0); -} - -u_int32_t -ncp_reply_dword_hl(struct ncp_buf *conn, int offset) { - return getdbe(ncp_reply_data(conn, offset), 0); -} - -u_int32_t -ncp_reply_dword_lh(struct ncp_buf *conn, int offset) { - return getdle(ncp_reply_data(conn, offset), 0); -} - - -int -ncp_connect(struct ncp_conn_args *li, int *connHandle) { - struct ncpioc_connect args; - int fd, r; - if ((fd = open(_PATH_NCP, O_RDWR)) < 0) - return (errno); - args.ioc_li = li; - args.ioc_connhandle = connHandle; - errno = 0; - (void)ioctl(fd, NCPIOC_CONNECT, &args); - r = errno; - close(fd); - return (r); -} - -int -ncp_disconnect(int cH) { - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_CONNCLOSE); - return ncp_conn_request(cH, conn); -} - -int -ncp_request(int connHandle,int function, struct ncp_buf *ncpbuf){ - struct ncpioc_request args; - int fd, r; - if ((fd = open(_PATH_NCP, O_RDWR)) < 0) - return (errno); - args.ioc_connhandle = connHandle; - args.ioc_fn = function; - args.ioc_ncpbuf = ncpbuf; - errno = 0; - (void)ioctl(fd, NCPIOC_REQUEST, &args); - r = errno; - close(fd); - return (r); -} - -int -ncp_conn_request(int connHandle, struct ncp_buf *ncpbuf){ - return (ncp_request(connHandle, NCP_CONN, ncpbuf)); -} - -int -ncp_conn_scan(struct ncp_conn_loginfo *li, int *connid) { - struct ncpioc_connscan args; - int fd, r; - if ((fd = open(_PATH_NCP, O_RDWR)) < 0) - return (errno); - args.ioc_li = li; - args.ioc_connhandle = connid; - errno = 0; - (void)ioctl(fd, NCPIOC_CONNSCAN, &args); - r = errno; - close(fd); - return (r); -} - -NWCCODE -NWRequest(NWCONN_HANDLE cH, nuint16 fn, - nuint16 nrq, NW_FRAGMENT* rq, - nuint16 nrp, NW_FRAGMENT* rp) -{ - int error; - struct ncp_conn_frag nf; - DECLARE_RQ; - - ncp_init_request(conn); - ncp_add_byte(conn, NCP_CONN_FRAG); - nf.fn = fn; - nf.rqfcnt = nrq; - nf.rqf = rq; - nf.rpf = rp; - nf.rpfcnt = nrp; - ncp_add_mem(conn, &nf, sizeof(nf)); - error = ncp_conn_request(cH, conn); - return error; -} - - -int -ncp_initlib(void){ - int error; - int kv; - size_t kvlen = sizeof(kv); - static int ncp_initialized; - - if (ncp_initialized) - return 0; - error = sysctlbyname("net.ncp.version", &kv, &kvlen, NULL, 0); - if (error) { - if (errno == ENOENT) - fprintf(stderr, "Kernel module ncp is not loaded.\n"); - else - fprintf(stderr, "%s: kernel module is old, please recompile it.\n", __func__); - return error; - } - if (NCP_VERSION != kv) { - fprintf(stderr, "%s: kernel module version(%d) don't match library(%d).\n", __func__, kv, NCP_VERSION); - return EINVAL; - } - if ((error = ncp_nls_setrecode(0)) != 0) { - fprintf(stderr, "%s: can't initialise recode\n", __func__); - return error; - } - if ((error = ncp_nls_setlocale("")) != 0) { - fprintf(stderr, "%s: can't initialise locale\n", __func__); - return error; - } - ncp_initialized++; - return 0; -} - - -/* - */ -int ncp_opterr = 1, /* if error message should be printed */ - ncp_optind = 1, /* index into parent argv vector */ - ncp_optopt, /* character checked for validity */ - ncp_optreset; /* reset getopt */ -char *ncp_optarg; /* argument associated with option */ - -#define BADCH (int)'?' -#define BADARG (int)':' -#define EMSG "" - -int -ncp_getopt(nargc, nargv, ostr) - int nargc; - char * const *nargv; - const char *ostr; -{ - static char *place = EMSG; /* option letter processing */ - char *oli; /* option letter list index */ - int tmpind; - - if (ncp_optreset || !*place) { /* update scanning pointer */ - ncp_optreset = 0; - tmpind = ncp_optind; - while (1) { - if (tmpind >= nargc) { - place = EMSG; - return (-1); - } - if (*(place = nargv[tmpind]) != '-') { - tmpind++; - continue; /* lookup next option */ - } - if (place[1] && *++place == '-') { /* found "--" */ - ncp_optind = ++tmpind; - place = EMSG; - return (-1); - } - ncp_optind = tmpind; - break; - } - } /* option letter okay? */ - if ((ncp_optopt = (int)*place++) == (int)':' || - !(oli = strchr(ostr, ncp_optopt))) { - /* - * if the user didn't specify '-' as an option, - * assume it means -1. - */ - if (ncp_optopt == (int)'-') - return (-1); - if (!*place) - ++ncp_optind; - if (ncp_opterr && *ostr != ':') - (void)fprintf(stderr, - "%s: illegal option -- %c\n", _getprogname(), ncp_optopt); - return (BADCH); - } - if (*++oli != ':') { /* don't need argument */ - ncp_optarg = NULL; - if (!*place) - ++ncp_optind; - } - else { /* need an argument */ - if (*place) /* no white space */ - ncp_optarg = place; - else if (nargc <= ++ncp_optind) { /* no arg */ - place = EMSG; - if (*ostr == ':') - return (BADARG); - if (ncp_opterr) - (void)fprintf(stderr, - "%s: option requires an argument -- %c\n", - _getprogname(), ncp_optopt); - return (BADCH); - } - else /* white space */ - ncp_optarg = nargv[ncp_optind]; - place = EMSG; - ++ncp_optind; - } - return (ncp_optopt); /* dump back option letter */ -} -/* - * misc options parsing routines - */ -int -ncp_args_parserc(struct ncp_args *na, char *sect, ncp_setopt_t *set_callback) { - int len, error; - - for (; na->opt; na++) { - switch (na->at) { - case NCA_STR: - if (rc_getstringptr(ncp_rc,sect,na->name,&na->str) == 0) { - len = strlen(na->str); - if (len > na->ival) { - fprintf(stderr,"rc: Argument for option '%c' (%s) too long\n",na->opt,na->name); - return EINVAL; - } - set_callback(na); - } - break; - case NCA_BOOL: - error = rc_getbool(ncp_rc,sect,na->name,&na->ival); - if (error == ENOENT) break; - if (error) return EINVAL; - set_callback(na); - break; - case NCA_INT: - if (rc_getint(ncp_rc,sect,na->name,&na->ival) == 0) { - if (((na->flag & NAFL_HAVEMIN) && - (na->ival < na->min)) || - ((na->flag & NAFL_HAVEMAX) && - (na->ival > na->max))) { - fprintf(stderr,"rc: Argument for option '%c' (%s) should be in [%d-%d] range\n",na->opt,na->name,na->min,na->max); - return EINVAL; - } - set_callback(na); - }; - break; - default: - break; - } - } - return 0; -} - -int -ncp_args_parseopt(struct ncp_args *na, int opt, char *optarg, ncp_setopt_t *set_callback) { - int len; - - for (; na->opt; na++) { - if (na->opt != opt) continue; - switch (na->at) { - case NCA_STR: - na->str = optarg; - if (optarg) { - len = strlen(na->str); - if (len > na->ival) { - fprintf(stderr,"opt: Argument for option '%c' (%s) too long\n",na->opt,na->name); - return EINVAL; - } - set_callback(na); - } - break; - case NCA_BOOL: - na->ival = 0; - set_callback(na); - break; - case NCA_INT: - errno = 0; - na->ival = strtol(optarg, NULL, 0); - if (errno) { - fprintf(stderr,"opt: Invalid integer value for option '%c' (%s).\n",na->opt,na->name); - return EINVAL; - } - if (((na->flag & NAFL_HAVEMIN) && - (na->ival < na->min)) || - ((na->flag & NAFL_HAVEMAX) && - (na->ival > na->max))) { - fprintf(stderr,"opt: Argument for option '%c' (%s) should be in [%d-%d] range\n",na->opt,na->name,na->min,na->max); - return EINVAL; - } - set_callback(na); - break; - default: - break; - } - break; - } - return 0; -} - -/* - * Print a (descriptive) error message - * error values: - * 0 - no specific error code available; - * -999..-1 - NDS error - * 1..32767 - system error - * the rest - requester error; - */ -void -ncp_error(const char *fmt, int error, ...) { - va_list ap; - - fprintf(stderr, "%s: ", _getprogname()); - va_start(ap, error); - vfprintf(stderr, fmt, ap); - va_end(ap); - if (error == -1) - error = errno; - if (error > -1000 && error < 0) { - fprintf(stderr, ": dserr = %d\n", error); - } else if (error & 0x8000) { - fprintf(stderr, ": nwerr = %04x\n", error); - } else if (error) { - fprintf(stderr, ": syserr = %s\n", strerror(error)); - } else - fprintf(stderr, "\n"); -} - -char * -ncp_printb(char *dest, int flags, const struct ncp_bitname *bnp) { - int first = 1; - - strcpy(dest, "<"); - for(; bnp->bn_bit; bnp++) { - if (flags & bnp->bn_bit) { - strcat(dest, bnp->bn_name); - first = 0; - } - if (!first && (flags & bnp[1].bn_bit)) - strcat(dest, "|"); - } - strcat(dest, ">"); - return dest; -} diff --git a/lib/libncp/sap.c b/lib/libncp/sap.c deleted file mode 100644 index c7f8da1..0000000 --- a/lib/libncp/sap.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (c) 1999, Boris Popov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the author nor the names of any co-contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <stdlib.h> -#include <string.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/time.h> -#include <arpa/inet.h> -#include <netipx/ipx.h> -#include <errno.h> -#include <unistd.h> -#include "ipxsap.h" - -/* - * TODO: These should go to ipx headers - */ -#define ipx_set_net(x,y) ((x).x_net.s_net[0] = (y).x_net.s_net[0]); \ - ((x).x_net.s_net[1]=(y).x_net.s_net[1]) -#define ipx_set_nullnet(x) ((x).x_net.s_net[0]=0); ((x).x_net.s_net[1]=0) -#define ipx_set_nullhost(x) ((x).x_host.s_host[0] = 0); \ - ((x).x_host.s_host[1] = 0); ((x).x_host.s_host[2] = 0) -#define ipx_set_wildnet(x) ((x).x_net.s_net[0] = 0xFFFF); \ - ((x).x_net.s_net[1]=0xFFFF) -#define ipx_set_wildhost(x) ((x).x_host.s_host[0] = 0xFFFF); \ - ((x).x_host.s_host[1] = 0xFFFF); ((x).x_host.s_host[2] = 0xFFFF); - - -static struct sap_packet* sap_packet_alloc(int entries); -static int sap_size(int entries, u_short operation); -int (*sap_sendto_func)(void*,int,struct sockaddr_ipx*,int sock)=NULL; - -static int -sap_sendto(void* buffer, int size, struct sockaddr_ipx* daddr, int sock) -{ - if (sap_sendto_func) - return sap_sendto_func(buffer,size,daddr,sock); - return sendto(sock, (char*)buffer, size, 0, - (struct sockaddr*)daddr, sizeof(*daddr)); -} - -static struct sap_packet* -sap_packet_alloc(int entries) -{ - if (entries > IPX_SAP_MAX_ENTRIES) - return NULL; - return - (struct sap_packet*)malloc(sap_size(entries, IPX_SAP_GENERAL_RESPONSE)); -} - -static int -sap_size(int entries, u_short operation) -{ - if (entries <= 0) - return 0; - switch (operation) { - case IPX_SAP_GENERAL_QUERY: - return entries == 1 ? IPX_SAP_REQUEST_LEN : 0; - case IPX_SAP_GENERAL_RESPONSE: - if (entries > IPX_SAP_MAX_ENTRIES) - return 0; - return sizeof(struct sap_packet) + (entries - 1) * sizeof(struct sap_entry); - case IPX_SAP_NEAREST_QUERY: - return entries == 1 ? IPX_SAP_REQUEST_LEN : 0; - case IPX_SAP_NEAREST_RESPONSE: - return entries == 1 ? sizeof(struct sap_packet) : 0; - default: - return 0; - } -} - -void -sap_copyname(char *dest, const char *src) -{ - bzero(dest, IPX_SAP_SERVER_NAME_LEN); - strncpy(dest, src, IPX_SAP_SERVER_NAME_LEN - 1); -} - -int -sap_rq_init(struct sap_rq* rq, int sock) -{ - rq->buffer = sap_packet_alloc(IPX_SAP_MAX_ENTRIES); - if (rq->buffer == NULL) - return 0; - rq->entries = 0; - rq->buffer->operation = htons(IPX_SAP_GENERAL_QUERY); - rq->dest_addr.sipx_family = AF_IPX; - rq->dest_addr.sipx_len = sizeof(struct sockaddr_ipx); - rq->sock = sock; - return 1; -} - -int -sap_rq_flush(struct sap_rq* rq) -{ - int result; - - if (rq->entries == 0) - return 0; - result = sap_sendto(rq->buffer, - sap_size(rq->entries, ntohs(rq->buffer->operation)), - &rq->dest_addr, rq->sock); - rq->entries = 0; - return result; -} - -void -sap_rq_general_query(struct sap_rq* rq, u_short ser_type) -{ - struct sap_entry* sep; - - sap_rq_flush(rq); - rq->buffer->operation = htons(IPX_SAP_GENERAL_QUERY); - sep = rq->buffer->sap_entries + rq->entries++; - sep->server_type = htons(ser_type); -} - -void -sap_rq_gns_request(struct sap_rq* rq, u_short ser_type) -{ - struct sap_entry* sep; - - sap_rq_flush(rq); - rq->buffer->operation = htons(IPX_SAP_NEAREST_QUERY); - sep = rq->buffer->sap_entries + rq->entries++; - sep->server_type = htons(ser_type); -} - -void -sap_rq_general_response(struct sap_rq* rq,u_short type,char *name,struct sockaddr_ipx* addr, u_short hops,int down_allow) -{ - struct sap_entry* sep; - - if (hops >= IPX_SAP_SERVER_DOWN && !down_allow) return; - if (rq->entries >= IPX_SAP_MAX_ENTRIES) - sap_rq_flush(rq); - if (rq->buffer->operation != htons(IPX_SAP_GENERAL_RESPONSE)){ - sap_rq_flush(rq); - rq->buffer->operation = htons(IPX_SAP_GENERAL_RESPONSE); - } - sep = rq->buffer->sap_entries + rq->entries; - sep->server_type = htons(type); - sap_copyname(sep->server_name, name); - memcpy(&sep->ipx, &addr->sipx_addr, sizeof(struct ipx_addr)); - sep->hops = htons(hops); - rq->entries++; -} - -void -sap_rq_gns_response(struct sap_rq* rq,u_short type,char *name,struct sockaddr_ipx* addr,u_short hops) -{ - struct sap_entry* sep; - - if (hops >= IPX_SAP_SERVER_DOWN) return; - sap_rq_flush(rq); - rq->buffer->operation = htons(IPX_SAP_NEAREST_RESPONSE); - sep = rq->buffer->sap_entries + rq->entries; - sep->server_type = htons(type); - sap_copyname(sep->server_name, name); - memcpy(&sep->ipx, &addr->sipx_addr, sizeof(struct ipx_addr)); - sep->hops = htons(hops); - rq->entries++; -} - -void -sap_rq_set_destination(struct sap_rq* rq,struct ipx_addr *dest) -{ - sap_rq_flush(rq); - memcpy(&rq->dest_addr.sipx_addr,dest,sizeof(struct ipx_addr)); -} - -int -sap_getsock(int *rsock) { - struct sockaddr_ipx sap_addr; - int opt, sock, slen; - - sock = socket(AF_IPX, SOCK_DGRAM, 0); - if (sock < 0) - return (errno); - slen = sizeof(sap_addr); - bzero(&sap_addr, slen); - sap_addr.sipx_family = AF_IPX; - sap_addr.sipx_len = slen; - if (bind(sock, (struct sockaddr*)&sap_addr, slen) == -1) { - close(sock); - return(errno); - } - opt = 1; - if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt)) != 0){ - close(sock); - return(errno); - } - *rsock = sock; - return(0); -} - -static int -sap_recv(int sock,void *buf,int len,int flags, int timeout){ - fd_set rd, wr, ex; - struct timeval tv; - int result; - - FD_ZERO(&rd); - FD_ZERO(&wr); - FD_ZERO(&ex); - FD_SET(sock, &rd); - - tv.tv_sec = timeout; - tv.tv_usec = 0; - - if ((result = select(sock + 1, &rd, &wr, &ex, &tv)) == -1) { - return result; - } - if (FD_ISSET(sock, &rd)) { - result = recv(sock, buf, len, flags); - } else { - errno = ETIMEDOUT; - result = -1; - } - return result; -} - -int -sap_find_nearest(int server_type, struct sockaddr_ipx *daddr, char *server_name) -{ - struct ipx_addr addr; - char data[1024]; - int sock, error, packets, len; - struct sap_packet *reply = (struct sap_packet*)&data; - struct sap_rq sap_rq; - - error = sap_getsock(&sock); - if (error) - return error; - bzero(&addr, sizeof(addr)); - /* BAD: we should enum all ifs (and nets ?) */ - if (ipx_iffind(NULL, &addr) != 0) { - return (EPROTONOSUPPORT); - } - ipx_set_wildhost(addr); - addr.x_port = htons(IPXPORT_SAP); - - if (!sap_rq_init(&sap_rq, sock)) { - close(sock); - return(ENOMEM); - } - sap_rq_set_destination(&sap_rq, &addr); - sap_rq_gns_request(&sap_rq, server_type); - sap_rq_flush(&sap_rq); - packets = 5; - do { - len = sap_recv(sock, data, sizeof(data), 0, 1); - if (len >= 66 && - ntohs(reply->operation) == IPX_SAP_NEAREST_RESPONSE) - break; - if (len < 0) - packets--; - } while (packets > 0); - - if (packets == 0) { - close(sock); - return ENETDOWN; - } - - daddr->sipx_addr = reply->sap_entries[0].ipx; - daddr->sipx_family = AF_IPX; - daddr->sipx_len = sizeof(struct sockaddr_ipx); - sap_copyname(server_name, reply->sap_entries[0].server_name); - errno = 0; - close(sock); - return 0; -} diff --git a/lib/libnetgraph/msg.c b/lib/libnetgraph/msg.c index 534d1d1..c946459 100644 --- a/lib/libnetgraph/msg.c +++ b/lib/libnetgraph/msg.c @@ -234,7 +234,7 @@ NgDeliverMsg(int cs, const char *path, } /* Wait for reply if there should be one. */ - if (msg->header.cmd & NGM_HASREPLY) { + if (msg->header.cmd & NGM_HASREPLY && !(msg->header.flags & NGF_RESP)) { struct pollfd rfds; int n; diff --git a/lib/libpam/modules/pam_unix/pam_unix.c b/lib/libpam/modules/pam_unix/pam_unix.c index 5881ecf..9a213e2 100644 --- a/lib/libpam/modules/pam_unix/pam_unix.c +++ b/lib/libpam/modules/pam_unix/pam_unix.c @@ -460,14 +460,14 @@ to64(char *s, long v, int n) } /* Salt suitable for traditional DES and MD5 */ -void -makesalt(char salt[SALTSIZE]) +static void +makesalt(char salt[SALTSIZE + 1]) { int i; /* These are not really random numbers, they are just * numbers that change to thwart construction of a - * dictionary. This is exposed to the public. + * dictionary. */ for (i = 0; i < SALTSIZE; i += 4) to64(&salt[i], arc4random(), 4); diff --git a/lib/libpmc/Makefile b/lib/libpmc/Makefile index c15d38a..dde87bb 100644 --- a/lib/libpmc/Makefile +++ b/lib/libpmc/Makefile @@ -27,6 +27,8 @@ MAN+= pmc.soft.3 MAN+= pmc.atom.3 MAN+= pmc.core.3 MAN+= pmc.core2.3 +MAN+= pmc.haswell.3 +MAN+= pmc.haswelluc.3 MAN+= pmc.iaf.3 MAN+= pmc.ivybridge.3 MAN+= pmc.ivybridgexeon.3 diff --git a/lib/libpmc/libpmc.c b/lib/libpmc/libpmc.c index 1866e7f..74956a9 100644 --- a/lib/libpmc/libpmc.c +++ b/lib/libpmc/libpmc.c @@ -183,6 +183,11 @@ static const struct pmc_event_descr corei7_event_table[] = __PMC_EV_ALIAS_COREI7() }; +static const struct pmc_event_descr haswell_event_table[] = +{ + __PMC_EV_ALIAS_HASWELL() +}; + static const struct pmc_event_descr ivybridge_event_table[] = { __PMC_EV_ALIAS_IVYBRIDGE() @@ -213,6 +218,11 @@ static const struct pmc_event_descr corei7uc_event_table[] = __PMC_EV_ALIAS_COREI7UC() }; +static const struct pmc_event_descr haswelluc_event_table[] = +{ + __PMC_EV_ALIAS_HASWELLUC() +}; + static const struct pmc_event_descr sandybridgeuc_event_table[] = { __PMC_EV_ALIAS_SANDYBRIDGEUC() @@ -237,6 +247,7 @@ PMC_MDEP_TABLE(atom, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC); PMC_MDEP_TABLE(core, IAP, PMC_CLASS_SOFT, PMC_CLASS_TSC); PMC_MDEP_TABLE(core2, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC); PMC_MDEP_TABLE(corei7, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP); +PMC_MDEP_TABLE(haswell, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP); PMC_MDEP_TABLE(ivybridge, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC); PMC_MDEP_TABLE(ivybridge_xeon, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC); PMC_MDEP_TABLE(sandybridge, IAP, PMC_CLASS_SOFT, PMC_CLASS_IAF, PMC_CLASS_TSC, PMC_CLASS_UCF, PMC_CLASS_UCP); @@ -277,6 +288,7 @@ PMC_CLASS_TABLE_DESC(atom, IAP, atom, iap); PMC_CLASS_TABLE_DESC(core, IAP, core, iap); PMC_CLASS_TABLE_DESC(core2, IAP, core2, iap); PMC_CLASS_TABLE_DESC(corei7, IAP, corei7, iap); +PMC_CLASS_TABLE_DESC(haswell, IAP, haswell, iap); PMC_CLASS_TABLE_DESC(ivybridge, IAP, ivybridge, iap); PMC_CLASS_TABLE_DESC(ivybridge_xeon, IAP, ivybridge_xeon, iap); PMC_CLASS_TABLE_DESC(sandybridge, IAP, sandybridge, iap); @@ -284,6 +296,7 @@ PMC_CLASS_TABLE_DESC(sandybridge_xeon, IAP, sandybridge_xeon, iap); PMC_CLASS_TABLE_DESC(westmere, IAP, westmere, iap); PMC_CLASS_TABLE_DESC(ucf, UCF, ucf, ucf); PMC_CLASS_TABLE_DESC(corei7uc, UCP, corei7uc, ucp); +PMC_CLASS_TABLE_DESC(haswelluc, UCP, haswelluc, ucp); PMC_CLASS_TABLE_DESC(sandybridgeuc, UCP, sandybridgeuc, ucp); PMC_CLASS_TABLE_DESC(westmereuc, UCP, westmereuc, ucp); #endif @@ -582,6 +595,8 @@ static struct pmc_event_alias core2_aliases_without_iaf[] = { #define atom_aliases_without_iaf core2_aliases_without_iaf #define corei7_aliases core2_aliases #define corei7_aliases_without_iaf core2_aliases_without_iaf +#define haswell_aliases core2_aliases +#define haswell_aliases_without_iaf core2_aliases_without_iaf #define ivybridge_aliases core2_aliases #define ivybridge_aliases_without_iaf core2_aliases_without_iaf #define ivybridge_xeon_aliases core2_aliases @@ -740,6 +755,31 @@ static struct pmc_masks iap_rsp_mask_sb_sbx_ib[] = { NULLMASK }; +static struct pmc_masks iap_rsp_mask_haswell[] = { + PMCMASK(REQ_DMND_DATA_RD, (1ULL << 0)), + PMCMASK(REQ_DMND_RFO, (1ULL << 1)), + PMCMASK(REQ_DMND_IFETCH, (1ULL << 2)), + PMCMASK(REQ_PF_DATA_RD, (1ULL << 4)), + PMCMASK(REQ_PF_RFO, (1ULL << 5)), + PMCMASK(REQ_PF_IFETCH, (1ULL << 6)), + PMCMASK(REQ_OTHER, (1ULL << 15)), + PMCMASK(RES_ANY, (1ULL << 16)), + PMCMASK(RES_SUPPLIER_SUPP, (1ULL << 17)), + PMCMASK(RES_SUPPLIER_LLC_HITM, (1ULL << 18)), + PMCMASK(RES_SUPPLIER_LLC_HITE, (1ULL << 19)), + PMCMASK(RES_SUPPLIER_LLC_HITS, (1ULL << 20)), + PMCMASK(RES_SUPPLIER_LLC_HITF, (1ULL << 21)), + PMCMASK(RES_SUPPLIER_LOCAL, (1ULL << 22)), + PMCMASK(RES_SNOOP_SNP_NONE, (1ULL << 31)), + PMCMASK(RES_SNOOP_SNP_NO_NEEDED,(1ULL << 32)), + PMCMASK(RES_SNOOP_SNP_MISS, (1ULL << 33)), + PMCMASK(RES_SNOOP_HIT_NO_FWD, (1ULL << 34)), + PMCMASK(RES_SNOOP_HIT_FWD, (1ULL << 35)), + PMCMASK(RES_SNOOP_HITM, (1ULL << 36)), + PMCMASK(RES_NON_DRAM, (1ULL << 37)), + NULLMASK +}; + static int iap_allocate_pmc(enum pmc_event pe, char *ctrspec, struct pmc_op_pmcallocate *pmc_config) @@ -822,6 +862,11 @@ iap_allocate_pmc(enum pmc_event pe, char *ctrspec, n = pmc_parse_mask(iap_rsp_mask_sb_sbx_ib, p, &rsp); } else return (-1); + } else if (cpu_info.pm_cputype == PMC_CPU_INTEL_HASWELL) { + if (KWPREFIXMATCH(p, IAP_KW_RSP "=")) { + n = pmc_parse_mask(iap_rsp_mask_haswell, p, &rsp); + } else + return (-1); } else return (-1); @@ -2690,6 +2735,10 @@ pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames, ev = corei7_event_table; count = PMC_EVENT_TABLE_SIZE(corei7); break; + case PMC_CPU_INTEL_HASWELL: + ev = haswell_event_table; + count = PMC_EVENT_TABLE_SIZE(haswell); + break; case PMC_CPU_INTEL_IVYBRIDGE: ev = ivybridge_event_table; count = PMC_EVENT_TABLE_SIZE(ivybridge); @@ -2727,6 +2776,10 @@ pmc_event_names_of_class(enum pmc_class cl, const char ***eventnames, ev = corei7uc_event_table; count = PMC_EVENT_TABLE_SIZE(corei7uc); break; + case PMC_CPU_INTEL_HASWELL: + ev = haswelluc_event_table; + count = PMC_EVENT_TABLE_SIZE(haswelluc); + break; case PMC_CPU_INTEL_SANDYBRIDGE: ev = sandybridgeuc_event_table; count = PMC_EVENT_TABLE_SIZE(sandybridgeuc); @@ -2994,6 +3047,11 @@ pmc_init(void) pmc_class_table[n++] = &corei7uc_class_table_descr; PMC_MDEP_INIT_INTEL_V2(corei7); break; + case PMC_CPU_INTEL_HASWELL: + pmc_class_table[n++] = &ucf_class_table_descr; + pmc_class_table[n++] = &haswelluc_class_table_descr; + PMC_MDEP_INIT_INTEL_V2(haswell); + break; case PMC_CPU_INTEL_IVYBRIDGE: PMC_MDEP_INIT_INTEL_V2(ivybridge); break; @@ -3138,6 +3196,10 @@ _pmc_name_of_event(enum pmc_event pe, enum pmc_cputype cpu) ev = corei7_event_table; evfence = corei7_event_table + PMC_EVENT_TABLE_SIZE(corei7); break; + case PMC_CPU_INTEL_HASWELL: + ev = haswell_event_table; + evfence = haswell_event_table + PMC_EVENT_TABLE_SIZE(haswell); + break; case PMC_CPU_INTEL_IVYBRIDGE: ev = ivybridge_event_table; evfence = ivybridge_event_table + PMC_EVENT_TABLE_SIZE(ivybridge); diff --git a/lib/libpmc/pmc.haswell.3 b/lib/libpmc/pmc.haswell.3 new file mode 100644 index 0000000..dd0cbb8 --- /dev/null +++ b/lib/libpmc/pmc.haswell.3 @@ -0,0 +1,975 @@ +.\" Copyright (c) 2013 Hiren Panchasara <hiren.panchasara@gmail.com> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 22, 2013 +.Dt PMC.HASWELL 3 +.Os +.Sh NAME +.Nm pmc.haswell +.Nd measurement events for +.Tn Intel +.Tn Haswsell +family CPUs +.Sh LIBRARY +.Lb libpmc +.Sh SYNOPSIS +.In pmc.h +.Sh DESCRIPTION +.Tn Intel +.Tn "Haswell" +CPUs contain PMCs conforming to version 2 of the +.Tn Intel +performance measurement architecture. +These CPUs may contain up to two classes of PMCs: +.Bl -tag -width "Li PMC_CLASS_IAP" +.It Li PMC_CLASS_IAF +Fixed-function counters that count only one hardware event per counter. +.It Li PMC_CLASS_IAP +Programmable counters that may be configured to count one of a defined +set of hardware events. +.El +.Pp +The number of PMCs available in each class and their widths need to be +determined at run time by calling +.Xr pmc_cpuinfo 3 . +.Pp +Intel Haswell PMCs are documented in +.Rs +.%B "Intel(R) 64 and IA-32 Architectures Software Developer's Manual" +.%T "Combined Volumes: 1, 2A, 2B, 2C, 3A, 3B and 3C" +.%N "Order Number: 325462-045US" +.%D January 2013 +.%Q "Intel Corporation" +.Re +.Ss HASWELL FIXED FUNCTION PMCS +These PMCs and their supported events are documented in +.Xr pmc.iaf 3 . +.Ss HASWELL PROGRAMMABLE PMCS +The programmable PMCs support the following capabilities: +.Bl -column "PMC_CAP_INTERRUPT" "Support" +.It Em Capability Ta Em Support +.It PMC_CAP_CASCADE Ta \&No +.It PMC_CAP_EDGE Ta Yes +.It PMC_CAP_INTERRUPT Ta Yes +.It PMC_CAP_INVERT Ta Yes +.It PMC_CAP_READ Ta Yes +.It PMC_CAP_PRECISE Ta \&No +.It PMC_CAP_SYSTEM Ta Yes +.It PMC_CAP_TAGGING Ta \&No +.It PMC_CAP_THRESHOLD Ta Yes +.It PMC_CAP_USER Ta Yes +.It PMC_CAP_WRITE Ta Yes +.El +.Ss Event Qualifiers +Event specifiers for these PMCs support the following common +qualifiers: +.Bl -tag -width indent +.It Li rsp= Ns Ar value +Configure the Off-core Response bits. +.Bl -tag -width indent +.It Li DMND_DATA_RD +Counts the number of demand and DCU prefetch data reads of full +and partial cachelines as well as demand data page table entry +cacheline reads. Does not count L2 data read prefetches or +instruction fetches. +.It Li REQ_DMND_RFO +Counts the number of demand and DCU prefetch reads for ownership (RFO) +requests generated by a write to data cacheline. Does not count L2 RFO +prefetches. +.It Li REQ_DMND_IFETCH +Counts the number of demand and DCU prefetch instruction cacheline reads. +Does not count L2 code read prefetches. +.It Li REQ_WB +Counts the number of writeback (modified to exclusive) transactions. +.It Li REQ_PF_DATA_RD +Counts the number of data cacheline reads generated by L2 prefetchers. +.It Li REQ_PF_RFO +Counts the number of RFO requests generated by L2 prefetchers. +.It Li REQ_PF_IFETCH +Counts the number of code reads generated by L2 prefetchers. +.It Li REQ_PF_LLC_DATA_RD +L2 prefetcher to L3 for loads. +.It Li REQ_PF_LLC_RFO +RFO requests generated by L2 prefetcher +.It Li REQ_PF_LLC_IFETCH +L2 prefetcher to L3 for instruction fetches. +.It Li REQ_BUS_LOCKS +Bus lock and split lock requests. +.It Li REQ_STRM_ST +Streaming store requests. +.It Li REQ_OTHER +Any other request that crosses IDI, including I/O. +.It Li RES_ANY +Catch all value for any response types. +.It Li RES_SUPPLIER_NO_SUPP +No Supplier Information available. +.It Li RES_SUPPLIER_LLC_HITM +M-state initial lookup stat in L3. +.It Li RES_SUPPLIER_LLC_HITE +E-state. +.It Li RES_SUPPLIER_LLC_HITS +S-state. +.It Li RES_SUPPLIER_LLC_HITF +F-state. +.It Li RES_SUPPLIER_LOCAL +Local DRAM Controller. +.It Li RES_SNOOP_SNP_NONE +No details on snoop-related information. +.It Li RES_SNOOP_SNP_NO_NEEDED +No snoop was needed to satisfy the request. +.It Li RES_SNOOP_SNP_MISS +A snoop was needed and it missed all snooped caches: +-For LLC Hit, ReslHitl was returned by all cores +-For LLC Miss, Rspl was returned by all sockets and data was returned from +DRAM. +.It Li RES_SNOOP_HIT_NO_FWD +A snoop was needed and it hits in at least one snooped cache. Hit denotes a +cache-line was valid before snoop effect. This includes: +-Snoop Hit w/ Invalidation (LLC Hit, RFO) +-Snoop Hit, Left Shared (LLC Hit/Miss, IFetch/Data_RD) +-Snoop Hit w/ Invalidation and No Forward (LLC Miss, RFO Hit S) +In the LLC Miss case, data is returned from DRAM. +.It Li RES_SNOOP_HIT_FWD +A snoop was needed and data was forwarded from a remote socket. +This includes: +-Snoop Forward Clean, Left Shared (LLC Hit/Miss, IFetch/Data_RD/RFT). +.It Li RES_SNOOP_HITM +A snoop was needed and it HitM-ed in local or remote cache. HitM denotes a +cache-line was in modified state before effect as a results of snoop. This +includes: +-Snoop HitM w/ WB (LLC miss, IFetch/Data_RD) +-Snoop Forward Modified w/ Invalidation (LLC Hit/Miss, RFO) +-Snoop MtoS (LLC Hit, IFetch/Data_RD). +.It Li RES_NON_DRAM +Target was non-DRAM system address. This includes MMIO transactions. +.El +.It Li cmask= Ns Ar value +Configure the PMC to increment only if the number of configured +events measured in a cycle is greater than or equal to +.Ar value . +.It Li edge +Configure the PMC to count the number of de-asserted to asserted +transitions of the conditions expressed by the other qualifiers. +If specified, the counter will increment only once whenever a +condition becomes true, irrespective of the number of clocks during +which the condition remains true. +.It Li inv +Invert the sense of comparison when the +.Dq Li cmask +qualifier is present, making the counter increment when the number of +events per cycle is less than the value specified by the +.Dq Li cmask +qualifier. +.It Li os +Configure the PMC to count events happening at processor privilege +level 0. +.It Li usr +Configure the PMC to count events occurring at privilege levels 1, 2 +or 3. +.El +.Pp +If neither of the +.Dq Li os +or +.Dq Li usr +qualifiers are specified, the default is to enable both. +.Ss Event Specifiers (Programmable PMCs) +Haswell programmable PMCs support the following events: +.Bl -tag -width indent +.It Li LD_BLOCKS.STORE_FORWARD +.Pq Event 03H , Umask 02H +Loads blocked by overlapping with store buffer that +cannot be forwarded. +.It Li MISALIGN_MEM_REF.LOADS +.Pq Event 05H , Umask 01H +Speculative cache-line split load uops dispatched to +L1D. +.It Li MISALIGN_MEM_REF.STORES +.Pq Event 05H , Umask 02H +Speculative cache-line split Store-address uops +dispatched to L1D. +.It Li LD_BLOCKS_PARTIAL.ADDRESS_ALIAS +.Pq Event 07H , Umask 01H +False dependencies in MOB due to partial compare +on address. +.It Li DTLB_LOAD_MISSES.MISS_CAUSES_A_WALK +.Pq Event 08H , Umask 01H +Misses in all TLB levels that cause a page walk of any +page size. +.It Li DTLB_LOAD_MISSES.WALK_COMPLETED_4K +.Pq Event 08H , Umask 02H +Completed page walks due to demand load misses +that caused 4K page walks in any TLB levels. +.It Li DTLB_LOAD_MISSES.WALK_COMPLETED_2M_4K +.Pq Event 08H , Umask 02H +Completed page walks due to demand load misses +that caused 2M/4M page walks in any TLB levels. +.It Li DTLB_LOAD_MISSES.WALK_COMPLETED +.Pq Event 08H , Umask 0EH +Completed page walks in any TLB of any page size +due to demand load misses +.It Li DTLB_LOAD_MISSES.WALK_DURATION +.Pq Event 08H , Umask 10H +Cycle PMH is busy with a walk. +.It Li DTLB_LOAD_MISSES.STLB_HIT_4K +.Pq Event 08H , Umask 20H +Load misses that missed DTLB but hit STLB (4K). +.It Li DTLB_LOAD_MISSES.STLB_HIT_2M +.Pq Event 08H , Umask 40H +Load misses that missed DTLB but hit STLB (2M). +.It Li DTLB_LOAD_MISSES.STLB_HIT +.Pq Event 08H , Umask 60H +Number of cache load STLB hits. No page walk. +.It Li DTLB_LOAD_MISSES.PDE_CACHE_MISS +.Pq Event 08H , Umask 80H +DTLB demand load misses with low part of linear-to- +physical address translation missed +.It Li INT_MISC.RECOVERY_CYCLES +.Pq Event 0DH , Umask 03H +Cycles waiting to recover after Machine Clears +except JEClear. Set Cmask= 1. +.It Li UOPS_ISSUED.ANY +.Pq Event 0EH , Umask 01H +ncrements each cycle the # of Uops issued by the +RAT to RS. +Set Cmask = 1, Inv = 1, Any= 1to count stalled cycles +of this core. +.It Li UOPS_ISSUED.FLAGS_MERGE +.Pq Event 0EH , Umask 10H +Number of flags-merge uops allocated. Such uops +adds delay. +.It Li UOPS_ISSUED.SLOW_LEA +.Pq Event 0EH , Umask 20H +Number of slow LEA or similar uops allocated. Such +uop has 3 sources (e.g. 2 sources + immediate) +regardless if as a result of LEA instruction or not. +.It Li UOPS_ISSUED.SiNGLE_MUL +.Pq Event 0EH , Umask 40H +Number of multiply packed/scalar single precision +uops allocated. +.It Li L2_RQSTS.DEMAND_DATA_RD_MISS +.Pq Event 24H , Umask 21H +Demand Data Read requests that missed L2, no +rejects. +.It Li L2_RQSTS.DEMAND_DATA_RD_HIT +.Pq Event 24H , Umask 41H +Demand Data Read requests that hit L2 cache. +.It Li L2_RQSTS.ALL_DEMAND_DATA_RD +.Pq Event 24H , Umask E1H +Counts any demand and L1 HW prefetch data load +requests to L2. +.It Li L2_RQSTS.RFO_HIT +.Pq Event 24H , Umask 42H +Counts the number of store RFO requests that hit +the L2 cache. +.It Li L2_RQSTS.RFO_MISS +.Pq Event 24H , Umask 22H +Counts the number of store RFO requests that miss +the L2 cache. +.It Li L2_RQSTS.ALL_RFO +.Pq Event 24H , Umask E2H +Counts all L2 store RFO requests. +.It Li L2_RQSTS.CODE_RD_HIT +.Pq Event 24H , Umask 44H +Number of instruction fetches that hit the L2 cache. +.It Li L2_RQSTS.CODE_RD_MISS +.Pq Event 24H , Umask 24H +Number of instruction fetches that missed the L2 +cache. +.It Li L2_RQSTS.ALL_DEMAND_MISS +.Pq Event 24H , Umask 27H +Demand requests that miss L2 cache. +.It Li L2_RQSTS.ALL_DEMAND_REFERENCES +.Pq Event 24H , Umask E7H +Demand requests to L2 cache. +.It Li L2_RQSTS.ALL_CODE_RD +.Pq Event 24H , Umask E4H +Counts all L2 code requests. +.It Li L2_RQSTS.L2_PF_HIT +.Pq Event 24H , Umask 50H +Counts all L2 HW prefetcher requests that hit L2. +.It Li L2_RQSTS.L2_PF_MISS +.Pq Event 24H , Umask 30H +Counts all L2 HW prefetcher requests that missed +L2. +.It Li L2_RQSTS.ALL_PF +.Pq Event 24H , Umask F8H +Counts all L2 HW prefetcher requests. +.It Li L2_RQSTS.MISS +.Pq Event 24H , Umask 3FH +All requests that missed L2. +.It Li L2_RQSTS.REFERENCES +.Pq Event 24H , Umask FFH +All requests to L2 cache. +.It Li L2_DEMAND_RQSTS.WB_HIT +.Pq Event 27H , Umask 50H +Not rejected writebacks that hit L2 cache +.It Li LONGEST_LAT_CACHE.REFERENCE +.Pq Event 2EH , Umask 4FH +This event counts requests originating from the core +that reference a cache line in the last level cache. +.It Li LONGEST_LAT_CACHE.MISS +.Pq Event 2EH , Umask 41H +This event counts each cache miss condition for +references to the last level cache. +.It Li CPU_CLK_UNHALTED.THREAD_P +.Pq Event 3CH , Umask 00H +Counts the number of thread cycles while the thread +is not in a halt state. The thread enters the halt state +when it is running the HLT instruction. The core +frequency may change from time to time due to +power or thermal throttling. +.It Li CPU_CLK_THREAD_UNHALTED.REF_XCLK +.Pq Event 3CH , Umask 01H +Increments at the frequency of XCLK (100 MHz) +when not halted. +.It Li L1D_PEND_MISS.PENDING +.Pq Event 48H , Umask 01H +Increments the number of outstanding L1D misses +every cycle. Set Cmaks = 1 and Edge =1 to count +occurrences. +.It Li DTLB_STORE_MISSES.MISS_CAUSES_A_WALK +.Pq Event 49H , Umask 01H +Miss in all TLB levels causes an page walk of any +page size (4K/2M/4M/1G). +.It Li DTLB_STORE_MISSES.WALK_COMPLETED_4K +.Pq Event 49H , Umask 02H +Completed page walks due to store misses in one or +more TLB levels of 4K page structure. +.It Li DTLB_STORE_MISSES.WALK_COMPLETED_2M_4M +.Pq Event 49H , Umask 04H +Completed page walks due to store misses in one or +more TLB levels of 2M/4M page structure. +.It Li DTLB_STORE_MISSES.WALK_COMPLETED +.Pq Event 49H , Umask 0EH +Completed page walks due to store miss in any TLB +levels of any page size (4K/2M/4M/1G). +.It Li DTLB_STORE_MISSES.WALK_DURATION +.Pq Event 49H , Umask 10H +Cycles PMH is busy with this walk. +.It Li DTLB_STORE_MISSES.STLB_HIT_4K +.Pq Event 49H , Umask 20H +Store misses that missed DTLB but hit STLB (4K). +.It Li DTLB_STORE_MISSES.STLB_HIT_2M +.Pq Event 49H , Umask 40H +Store misses that missed DTLB but hit STLB (2M). +.It Li DTLB_STORE_MISSES.STLB_HIT +.Pq Event 49H , Umask 60H +Store operations that miss the first TLB level but hit +the second and do not cause page walks. +.It Li DTLB_STORE_MISSES.PDE_CACHE_MISS +.Pq Event 49H , Umask 80H +DTLB store misses with low part of linear-to-physical +address translation missed. +.It Li LOAD_HIT_PRE.SW_PF +.Pq Event 4CH , Umask 01H +Non-SW-prefetch load dispatches that hit fill buffer +allocated for S/W prefetch. +.It Li LOAD_HIT_PRE.HW_PF +.Pq Event 4CH , Umask 02H +Non-SW-prefetch load dispatches that hit fill buffer +allocated for H/W prefetch. +.It Li L1D.REPLACEMENT +.Pq Event 51H , Umask 01H +Counts the number of lines brought into the L1 data +cache. +.It Li MOVE_ELIMINATION.INT_NOT_ELIMINATED +.Pq Event 58H , Umask 04H +Number of integer Move Elimination candidate uops +that were not eliminated. +.It Li MOVE_ELIMINATION.SMID_NOT_ELIMINATED +.Pq Event 58H , Umask 08H +Number of SIMD Move Elimination candidate uops +that were not eliminated. +.It Li MOVE_ELIMINATION.INT_ELIMINATED +.Pq Event 58H , Umask 01H +Unhalted core cycles when the thread is in ring 0. +.It Li MOVE_ELIMINATION.SMID_ELIMINATED +.Pq Event 58H , Umask 02H +Number of SIMD Move Elimination candidate uops +that were eliminated. +.It Li CPL_CYCLES.RING0 +.Pq Event 5CH , Umask 02H +Unhalted core cycles when the thread is in ring 0. +.It Li CPL_CYCLES.RING123 +.Pq Event 5CH , Umask 01H +Unhalted core cycles when the thread is not in ring 0. +.It Li RS_EVENTS.EMPTY_CYCLES +.Pq Event 5EH , Umask 01H +Cycles the RS is empty for the thread. +.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_DATA_RD +.Pq Event 60H , Umask 01H +Offcore outstanding Demand Data Read transactions +in SQ to uncore. Set Cmask=1 to count cycles. +.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_CORE_RD +.Pq Event 60H , Umask 02H +Offcore outstanding Demand code Read transactions +in SQ to uncore. Set Cmask=1 to count cycles. +.It Li OFFCORE_REQUESTS_OUTSTANDING.DEMAND_RFO +.Pq Event 60H , Umask 04H +Offcore outstanding RFO store transactions in SQ to +uncore. Set Cmask=1 to count cycles. +.It Li OFFCORE_REQUESTS_OUTSTANDING.ALL_DATA_RD +.Pq Event 60H , Umask 08H +Offcore outstanding cacheable data read +transactions in SQ to uncore. Set Cmask=1 to count +cycles. +.It Li LOCK_CYCLES.SPLIT_LOCK_UC_LOCK_DURATION +.Pq Event 63H , Umask 01H +Cycles in which the L1D and L2 are locked, due to a +UC lock or split lock. +.It Li LOCK_CYCLES.CACHE_LOCK_DURATION +.Pq Event 63H , Umask 02H +Cycles in which the L1D is locked. +.It Li IDQ.EMPTY +.Pq Event 79H , Umask 02H +Counts cycles the IDQ is empty. +.It Li IDQ.MITE_UOPS +.Pq Event 79H , Umask 04H +Increment each cycle # of uops delivered to IDQ from +MITE path. +Set Cmask = 1 to count cycles. +.It Li IDQ.DSB_UOPS +.Pq Event 79H , Umask 08H +Increment each cycle. # of uops delivered to IDQ +from DSB path. +Set Cmask = 1 to count cycles. +.It Li IDQ.MS_DSB_UOPS +.Pq Event 79H , Umask 10H +Increment each cycle # of uops delivered to IDQ +when MS_busy by DSB. Set Cmask = 1 to count +cycles. Add Edge=1 to count # of delivery. +.It Li IDQ.MS_MITE_UOPS +.Pq Event 79H , Umask 20H +ncrement each cycle # of uops delivered to IDQ +when MS_busy by MITE. Set Cmask = 1 to count +cycles. +.It Li IDQ.MS_UOPS +.Pq Event 79H , Umask 30H +Increment each cycle # of uops delivered to IDQ from +MS by either DSB or MITE. Set Cmask = 1 to count +cycles. +.It Li IDQ.ALL_DSB_CYCLES_ANY_UOPS +.Pq Event 79H , Umask 18H +Counts cycles DSB is delivered at least one uops. Set +Cmask = 1. +.It Li IDQ.ALL_DSB_CYCLES_4_UOPS +.Pq Event 79H , Umask 18H +Counts cycles DSB is delivered four uops. Set Cmask +=4. +.It Li IDQ.ALL_MITE_CYCLES_ANY_UOPS +.Pq Event 79H , Umask 24H +Counts cycles MITE is delivered at least one uops. Set +Cmask = 1. +.It Li IDQ.ALL_MITE_CYCLES_4_UOPS +.Pq Event 79H , Umask 24H +Counts cycles MITE is delivered four uops. Set Cmask +=4. +.It Li IDQ.MITE_ALL_UOPS +.Pq Event 79H , Umask 3CH +# of uops delivered to IDQ from any path. +.It Li ICACHE.MISSES +.Pq Event 80H , Umask 02H +Number of Instruction Cache, Streaming Buffer and +Victim Cache Misses. Includes UC accesses. +.It Li ITLB_MISSES.MISS_CAUSES_A_WALK +.Pq Event 85H , Umask 01H +Misses in ITLB that causes a page walk of any page +size. +.It Li ITLB_MISSES.WALK_COMPLETED_4K +.Pq Event 85H , Umask 02H +Completed page walks due to misses in ITLB 4K page +entries. +.It Li TLB_MISSES.WALK_COMPLETED_2M_4M +.Pq Event 85H , Umask 04H +Completed page walks due to misses in ITLB 2M/4M +page entries. +.It Li ITLB_MISSES.WALK_COMPLETED +.Pq Event 85H , Umask 0EH +Completed page walks in ITLB of any page size. +.It Li ITLB_MISSES.WALK_DURATION +.Pq Event 85H , Umask 10H +Cycle PMH is busy with a walk. +.It Li ITLB_MISSES.STLB_HIT_4K +.Pq Event 85H , Umask 20H +ITLB misses that hit STLB (4K). +.It Li ITLB_MISSES.STLB_HIT_2M +.Pq Event 85H , Umask 40H +ITLB misses that hit STLB (2K). +.It Li ITLB_MISSES.STLB_HIT +.Pq Event 85H , Umask 60H +TLB misses that hit STLB. No page walk. +.It Li ILD_STALL.LCP +.Pq Event 87H , Umask 01H +Stalls caused by changing prefix length of the +instruction. +.It Li ILD_STALL.IQ_FULL +.Pq Event 87H , Umask 04H +Stall cycles due to IQ is full. +.It Li BR_INST_EXEC.COND +.Pq Event 88H , Umask 01H +Qualify conditional near branch instructions +executed, but not necessarily retired. +.It Li BR_INST_EXEC.DIRECT_JMP +.Pq Event 88H , Umask 02H +Qualify all unconditional near branch instructions +excluding calls and indirect branches. +.It Li BR_INST_EXEC.INDIRECT_JMP_NON_CALL_RET +.Pq Event 88H , Umask 04H +Qualify executed indirect near branch instructions +that are not calls nor returns. +.It Li BR_INST_EXEC.RETURN_NEAR +.Pq Event 88H , Umask 08H +Qualify indirect near branches that have a return +mnemonic. +.It Li BR_INST_EXEC.DIRECT_NEAR_CALL +.Pq Event 88H , Umask 10H +Qualify unconditional near call branch instructions, +excluding non call branch, executed. +.It Li BR_INST_EXEC.INDIRECT_NEAR_CALL +.Pq Event 88H , Umask 20H +Qualify indirect near calls, including both register and +memory indirect, executed. +.It Li BR_INST_EXEC.NONTAKEN +.Pq Event 88H , Umask 40H +Qualify non-taken near branches executed. +.It Li BR_INST_EXEC.TAKEN +.Pq Event 88H , Umask 80H +Qualify taken near branches executed. Must combine +with 01H,02H, 04H, 08H, 10H, 20H. +.It Li BR_INST_EXEC.ALL_BRANCHES +.Pq Event 88H , Umask FFH +Counts all near executed branches (not necessarily +retired). +.It Li BR_MISP_EXEC.COND +.Pq Event 89H , Umask 01H +Qualify conditional near branch instructions +mispredicted. +.It Li BR_MISP_EXEC.INDIRECT_JMP_NON_CALL_RET +.Pq Event 89H , Umask 04H +Qualify mispredicted indirect near branch +instructions that are not calls nor returns. +.It Li BR_MISP_EXEC.RETURN_NEAR +.Pq Event 89H , Umask 08H +Qualify mispredicted indirect near branches that +have a return mnemonic. +.It Li BR_MISP_EXEC.DIRECT_NEAR_CALL +.Pq Event 89H , Umask 10H +Qualify mispredicted unconditional near call branch +instructions, excluding non call branch, executed. +.It Li BR_MISP_EXEC.INDIRECT_NEAR_CALL +.Pq Event 89H , Umask 20H +Qualify mispredicted indirect near calls, including +both register and memory indirect, executed. +.It Li BR_MISP_EXEC.NONTAKEN +.Pq Event 89H , Umask 40H +Qualify mispredicted non-taken near branches +executed. +.It Li BR_MISP_EXEC.TAKEN +.Pq Event 89H , Umask 80H +Qualify mispredicted taken near branches executed. +Must combine with 01H,02H, 04H, 08H, 10H, 20H. +.It Li BR_MISP_EXEC.ALL_BRANCHES +.Pq Event 89H , Umask FFH +Counts all near executed branches (not necessarily +retired). +.It Li IDQ_UOPS_NOT_DELIVERED.CORE +.Pq Event 9CH , Umask 01H +Count number of non-delivered uops to RAT per +thread. +.It Li UOPS_EXECUTED_PORT.PORT_0 +.Pq Event A1H , Umask 01H +Cycles which a Uop is dispatched on port 0 in this +thread. +.It Li UOPS_EXECUTED_PORT.PORT_1 +.Pq Event A1H , Umask 02H +Cycles which a Uop is dispatched on port 1 in this +thread. +.It Li UOPS_EXECUTED_PORT.PORT_2 +.Pq Event A1H , Umask 04H +Cycles which a Uop is dispatched on port 2 in this +thread. +.It Li UOPS_EXECUTED_PORT.PORT_3 +.Pq Event A1H , Umask 08H +Cycles which a Uop is dispatched on port 3 in this +thread. +.It Li UOPS_EXECUTED_PORT.PORT_4 +.Pq Event A1H , Umask 10H +Cycles which a Uop is dispatched on port 4 in this +thread. +.It Li UOPS_EXECUTED_PORT.PORT_5 +.Pq Event A1H , Umask 20H +Cycles which a Uop is dispatched on port 5 in this +thread. +.It Li UOPS_EXECUTED_PORT.PORT_6 +.Pq Event A1H , Umask 40H +Cycles which a Uop is dispatched on port 6 in this +thread. +.It Li UOPS_EXECUTED_PORT.PORT_7 +.Pq Event A1H , Umask 80H +Cycles which a Uop is dispatched on port 7 in this +thread. +.It Li RESOURCE_STALLS.ANY +.Pq Event A2H , Umask 01H +Cycles Allocation is stalled due to Resource Related +reason. +.It Li RESOURCE_STALLS.RS +.Pq Event A2H , Umask 04H +Cycles stalled due to no eligible RS entry available. +.It Li RESOURCE_STALLS.SB +.Pq Event A2H , Umask 08H +Cycles stalled due to no store buffers available (not +including draining form sync). +.It Li RESOURCE_STALLS.ROB +.Pq Event A2H , Umask 10H +Cycles stalled due to re-order buffer full. +.It Li CYCLE_ACTIVITY.CYCLES_L2_PENDING +.Pq Event A3H , Umask 01H +Cycles with pending L2 miss loads. Set Cmask=2 to +count cycle. +.It Li CYCLE_ACTIVITY.CYCLES_LDM_PENDING +.Pq Event A3H , Umask 02H +Cycles with pending memory loads. Set Cmask=2 to +count cycle. +.It Li CYCLE_ACTIVITY.STALLS_L2_PENDING +.Pq Event A3H , Umask 05H +Number of loads missed L2. +.It Li CYCLE_ACTIVITY.CYCLES_L1D_PENDING +.Pq Event A3H , Umask 08H +Cycles with pending L1 cache miss loads. Set +Cmask=8 to count cycle. +.It Li ITLB.ITLB_FLUSH +.Pq Event AEH , Umask 01H +Counts the number of ITLB flushes, includes +4k/2M/4M pages. +.It Li OFFCORE_REQUESTS.DEMAND_DATA_RD +.Pq Event B0H , Umask 01H +Demand data read requests sent to uncore. +.It Li OFFCORE_REQUESTS.DEMAND_CODE_RD +.Pq Event B0H , Umask 02H +Demand code read requests sent to uncore. +.It Li OFFCORE_REQUESTS.DEMAND_RFO +.Pq Event B0H , Umask 04H +Demand RFO read requests sent to uncore, including +regular RFOs, locks, ItoM. +.It Li OFFCORE_REQUESTS.ALL_DATA_RD +.Pq Event B0H , Umask 08H +Data read requests sent to uncore (demand and +prefetch). +.It Li UOPS_EXECUTED.CORE +.Pq Event B1H , Umask 02H +Counts total number of uops to be executed per-core +each cycle. +.It Li OFF_CORE_RESPONSE_0 +.Pq Event B7H , Umask 01H +Requires MSR 01A6H +.It Li OFF_CORE_RESPONSE_1 +.Pq Event BBH , Umask 01H +Requires MSR 01A7H +.It Li PAGE_WALKER_LOADS.DTLB_L1 +.Pq Event BCH , Umask 11H +Number of DTLB page walker loads that hit in the +L1+FB. +.It Li PAGE_WALKER_LOADS.ITLB_L1 +.Pq Event BCH , Umask 21H +Number of ITLB page walker loads that hit in the +L1+FB. +.It Li PAGE_WALKER_LOADS.DTLB_L2 +.Pq Event BCH , Umask 12H +Number of DTLB page walker loads that hit in the L2. +.It Li PAGE_WALKER_LOADS.ITLB_L2 +.Pq Event BCH , Umask 22H +Number of ITLB page walker loads that hit in the L2. +.It Li PAGE_WALKER_LOADS.DTLB_L3 +.Pq Event BCH , Umask 14H +Number of DTLB page walker loads that hit in the L3. +.It Li PAGE_WALKER_LOADS.ITLB_L3 +.Pq Event BCH , Umask 24H +Number of ITLB page walker loads that hit in the L3. +.It Li PAGE_WALKER_LOADS.DTLB_MEMORY +.Pq Event BCH , Umask 18H +Number of DTLB page walker loads from memory. +.It Li PAGE_WALKER_LOADS.ITLB_MEMORY +.Pq Event BCH , Umask 28H +Number of ITLB page walker loads from memory. +.It Li TLB_FLUSH.DTLB_THREAD +.Pq Event BDH , Umask 01H +DTLB flush attempts of the thread-specific entries. +.It Li TLB_FLUSH.STLB_ANY +.Pq Event BDH , Umask 20H +Count number of STLB flush attempts. +.It Li INST_RETIRED.ANY_P +.Pq Event C0H , Umask 00H +Number of instructions at retirement. +.It Li INST_RETIRED.ALL +.Pq Event C0H , Umask 01H +Precise instruction retired event with HW to reduce +effect of PEBS shadow in IP distribution. +.It Li OTHER_ASSISTS.AVX_TO_SSE +.Pq Event C1H , Umask 08H +Number of transitions from AVX-256 to legacy SSE +when penalty applicable. +.It Li OTHER_ASSISTS.SSE_TO_AVX +.Pq Event C1H , Umask 10H +Number of transitions from SSE to AVX-256 when +penalty applicable. +.It Li OTHER_ASSISTS.ANY_WB_ASSIST +.Pq Event C1H , Umask 40H +Number of microcode assists invoked by HW upon +uop writeback. +.It Li UOPS_RETIRED.ALL +.Pq Event C2H , Umask 01H +Counts the number of micro-ops retired, Use +cmask=1 and invert to count active cycles or stalled +cycles. +.It Li UOPS_RETIRED.RETIRE_SLOTS +.Pq Event C2H , Umask 02H +Counts the number of retirement slots used each +cycle. +.It Li MACHINE_CLEARS.MEMORY_ORDERING +.Pq Event C3H , Umask 02H +Counts the number of machine clears due to memory +order conflicts. +.It Li MACHINE_CLEARS.SMC +.Pq Event C3H , Umask 04H +Number of self-modifying-code machine clears +detected. +.It Li MACHINE_CLEARS.MASKMOV +.Pq Event C3H , Umask 20H +Counts the number of executed AVX masked load +operations that refer to an illegal address range with +the mask bits set to 0. +.It Li BR_INST_RETIRED.ALL_BRANCHES +.Pq Event C4H , Umask 00H +Branch instructions at retirement. +.It Li BR_INST_RETIRED.CONDITIONAL +.Pq Event C4H , Umask 01H +Counts the number of conditional branch instructions Supports PEBS +retired. +.It Li BR_INST_RETIRED.NEAR_CALL +.Pq Event C4H , Umask 02H +Direct and indirect near call instructions retired. +.It Li BR_INST_RETIRED.ALL_BRANCHES +.Pq Event C4H , Umask 04H +Counts the number of branch instructions retired. +.It Li BR_INST_RETIRED.NEAR_RETURN +.Pq Event C4H , Umask 08H +Counts the number of near return instructions +retired. +.It Li BR_INST_RETIRED.NOT_TAKEN +.Pq Event C4H , Umask 10H +Counts the number of not taken branch instructions +retired. + It Li BR_INST_RETIRED.NEAR_TAKEN +.Pq Event C4H , Umask 20H +Number of near taken branches retired. +.It Li BR_INST_RETIRED.FAR_BRANCH +.Pq Event C4H , Umask 40H +Number of far branches retired. +.It Li BR_MISP_RETIRED.ALL_BRANCHES +.Pq Event C5H , Umask 00H +Mispredicted branch instructions at retirement +.It Li BR_MISP_RETIRED.CONDITIONAL +.Pq Event C5H , Umask 01H +Mispredicted conditional branch instructions retired. +.It Li BR_MISP_RETIRED.CONDITIONAL +.Pq Event C5H , Umask 04H +Mispredicted macro branch instructions retired. +.It Li FP_ASSIST.X87_OUTPUT +.Pq Event CAH , Umask 02H +Number of X87 FP assists due to Output values. +.It Li FP_ASSIST.X87_INPUT +.Pq Event CAH , Umask 04H +Number of X87 FP assists due to input values. +.It Li FP_ASSIST.SIMD_OUTPUT +.Pq Event CAH , Umask 08H +Number of SIMD FP assists due to Output values. +.It Li FP_ASSIST.SIMD_INPUT +.Pq Event CAH , Umask 10H +Number of SIMD FP assists due to input values. +.It Li FP_ASSIST.ANY +.Pq Event CAH , Umask 1EH +Cycles with any input/output SSE* or FP assists. +.It Li ROB_MISC_EVENTS.LBR_INSERTS +.Pq Event CCH , Umask 20H +Count cases of saving new LBR records by hardware. +.It Li MEM_TRANS_RETIRED.LOAD_LATENCY +.Pq Event CDH , Umask 01H +Randomly sampled loads whose latency is above a +user defined threshold. A small fraction of the overall +loads are sampled due to randomization. +.It Li MEM_UOP_RETIRED.LOADS +.Pq Event D0H , Umask 01H +Qualify retired memory uops that are loads. Combine Supports PEBS and +with umask 10H, 20H, 40H, 80H. +.It Li MEM_UOP_RETIRED.STORES +.Pq Event D0H , Umask 02H +Qualify retired memory uops that are stores. +Combine with umask 10H, 20H, 40H, 80H. +.It Li MEM_UOP_RETIRED.STLB_MISS +.Pq Event D0H , Umask 10H +Qualify retired memory uops with STLB miss. Must +combine with umask 01H, 02H, to produce counts. +.It Li MEM_UOP_RETIRED.LOCK +.Pq Event D0H , Umask 20H +Qualify retired memory uops with lock. Must combine Supports PEBS and +with umask 01H, 02H, to produce counts. +.It Li MEM_UOP_RETIRED.SPLIT +.Pq Event D0H , Umask 40H +Qualify retired memory uops with line split. Must +combine with umask 01H, 02H, to produce counts. +.It Li MEM_UOP_RETIRED.ALL +.Pq Event D0H , Umask 80H +Qualify any retired memory uops. Must combine with Supports PEBS and +umask 01H, 02H, to produce counts. +.It Li MEM_LOAD_UOPS_RETIRED.L1_HIT +.Pq Event D1H , Umask 01H +Retired load uops with L1 cache hits as data sources. +.It Li MEM_LOAD_UOPS_RETIRED.L2_HIT +.Pq Event D1H , Umask 02H +Retired load uops with L2 cache hits as data sources. +.It Li MEM_LOAD_UOPS_RETIRED.LLC_HIT +.Pq Event D1H , Umask 04H +Retired load uops with LLC cache hits as data +sources. +.It Li MEM_LOAD_UOPS_RETIRED.L2_MISS +.Pq Event D1H , Umask 10H +Retired load uops missed L2. Unknown data source +excluded. +.It Li MEM_LOAD_UOPS_RETIRED.HIT_LFB +.Pq Event D1H , Umask 40H +Retired load uops which data sources were load uops +missed L1 but hit FB due to preceding miss to the +same cache line with data not ready. +.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_MISS +.Pq Event D2H , Umask 01H +Retired load uops which data sources were LLC hit +and cross-core snoop missed in on-pkg core cache. +.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_HIT +.Pq Event D2H , Umask 02H +Retired load uops which data sources were LLC and +cross-core snoop hits in on-pkg core cache. +.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_HITM +.Pq Event D2H , Umask 04H +Retired load uops which data sources were HitM +responses from shared LLC. +.It Li MEM_LOAD_UOPS_LLC_HIT_RETIRED.XSNP_NONE +.Pq Event D2H , Umask 08H +Retired load uops which data sources were hits in +LLC without snoops required. +.It Li MEM_LOAD_UOPS_LLC_MISS_RETIRED.LOCAL_DRAM +.Pq Event D3H , Umask 01H +Retired load uops which data sources missed LLC but +serviced from local dram. +.It Li BACLEARS.ANY +.Pq Event E6H , Umask 1FH +Number of front end re-steers due to BPU +misprediction. +.It Li L2_TRANS.DEMAND_DATA_RD +.Pq Event F0H , Umask 01H +Demand Data Read requests that access L2 cache. +.It Li L2_TRANS.RFO +.Pq Event F0H , Umask 02H +RFO requests that access L2 cache. +.It Li L2_TRANS.CODE_RD +.Pq Event F0H , Umask 04H +L2 cache accesses when fetching instructions. +.It Li L2_TRANS.ALL_PF +.Pq Event F0H , Umask 08H +Any MLC or LLC HW prefetch accessing L2, including +rejects. +.It Li L2_TRANS.L1D_WB +.Pq Event F0H , Umask 10H +L1D writebacks that access L2 cache. +.It Li L2_TRANS.L2_FILL +.Pq Event F0H , Umask 20H +L2 fill requests that access L2 cache. +.It Li L2_TRANS.L2_WB +.Pq Event F0H , Umask 40H +L2 writebacks that access L2 cache. +.It Li L2_TRANS.ALL_REQUESTS +.Pq Event F0H , Umask 80H +Transactions accessing L2 pipe. +.It Li L2_LINES_IN.I +.Pq Event F1H , Umask 01H +L2 cache lines in I state filling L2. +.It Li L2_LINES_IN.S +.Pq Event F1H , Umask 02H +L2 cache lines in S state filling L2. +.It Li L2_LINES_IN.E +.Pq Event F1H , Umask 04H +L2 cache lines in E state filling L2. +.It Li L2_LINES_IN.ALL +.Pq Event F1H , Umask 07H +L2 cache lines filling L2. +.It Li L2_LINES_OUT.DEMAND_CLEAN +.Pq Event F2H , Umask 05H +Clean L2 cache lines evicted by demand. +.It Li L2_LINES_OUT.DEMAND_DIRTY +.Pq Event F2H , Umask 06H +Dirty L2 cache lines evicted by demand. +.El +.Sh SEE ALSO +.Xr pmc 3 , +.Xr pmc.atom 3 , +.Xr pmc.core 3 , +.Xr pmc.iaf 3 , +.Xr pmc.ucf 3 , +.Xr pmc.k7 3 , +.Xr pmc.k8 3 , +.Xr pmc.p4 3 , +.Xr pmc.p5 3 , +.Xr pmc.p6 3 , +.Xr pmc.corei7 3 , +.Xr pmc.corei7uc 3 , +.Xr pmc.haswelluc 3 , +.Xr pmc.ivybridge 3 , +.Xr pmc.ivybridgexeon 3 , +.Xr pmc.sandybridge 3 , +.Xr pmc.sandybridgeuc 3 , +.Xr pmc.sandybridgexeon 3 , +.Xr pmc.westmere 3 , +.Xr pmc.westmereuc 3 , +.Xr pmc.soft 3 , +.Xr pmc.tsc 3 , +.Xr pmc_cpuinfo 3 , +.Xr pmclog 3 , +.Xr hwpmc 4 +.Sh HISTORY +The +.Nm pmc +library first appeared in +.Fx 6.0 . +.Sh AUTHORS +The +.Lb libpmc +library was written by +.An "Joseph Koshy" +.Aq jkoshy@FreeBSD.org . +The support for the Haswell +microarchitecture was written by +.An "Hiren Panchasara" +.Aq hiren.panchasara@gmail.com . diff --git a/lib/libpmc/pmc.haswelluc.3 b/lib/libpmc/pmc.haswelluc.3 new file mode 100644 index 0000000..dba9d47 --- /dev/null +++ b/lib/libpmc/pmc.haswelluc.3 @@ -0,0 +1,237 @@ +.\" Copyright (c) 2013 Hiren Panchasara <hiren.panchasara@gmail.com> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 22, 2013 +.Dt PMC.HASWELLUC 3 +.Os +.Sh NAME +.Nm pmc.haswelluc +.Nd uncore measurement events for +.Tn Intel +.Tn Haswell +family CPUs +.Sh LIBRARY +.Lb libpmc +.Sh SYNOPSIS +.In pmc.h +.Sh DESCRIPTION +.Tn Intel +.Tn "Haswell" +CPUs contain PMCs conforming to version 3 of the +.Tn Intel +performance measurement architecture. +These CPUs contain two classes of PMCs: +.Bl -tag -width "Li PMC_CLASS_UCP" +.It Li PMC_CLASS_UCF +Fixed-function counters that count only one hardware event per counter. +.It Li PMC_CLASS_UCP +Programmable counters that may be configured to count one of a defined +set of hardware events. +.El +.Pp +The number of PMCs available in each class and their widths need to be +determined at run time by calling +.Xr pmc_cpuinfo 3 . +.Pp +Intel Haswell PMCs are documented in +.Rs +.%B "Intel(R) 64 and IA-32 Architectures Software Developers Manual" +.%T "Combined Volumes: 1, 2A, 2B, 2C, 3A, 3B and 3C" +.%N "Order Number: 325462-045US" +.%D January 2013 +.%Q "Intel Corporation" +.Re +.Ss HASWELL UNCORE FIXED FUNCTION PMCS +These PMCs and their supported events are documented in +.Xr pmc.ucf 3 . +Not all CPUs in this family implement fixed-function counters. +.Ss HASWELL UNCORE PROGRAMMABLE PMCS +The programmable PMCs support the following capabilities: +.Bl -column "PMC_CAP_INTERRUPT" "Support" +.It Em Capability Ta Em Support +.It PMC_CAP_CASCADE Ta \&No +.It PMC_CAP_EDGE Ta Yes +.It PMC_CAP_INTERRUPT Ta \&No +.It PMC_CAP_INVERT Ta Yes +.It PMC_CAP_READ Ta Yes +.It PMC_CAP_PRECISE Ta \&No +.It PMC_CAP_SYSTEM Ta \&No +.It PMC_CAP_TAGGING Ta \&No +.It PMC_CAP_THRESHOLD Ta Yes +.It PMC_CAP_USER Ta \&No +.It PMC_CAP_WRITE Ta Yes +.El +.Ss Event Qualifiers +Event specifiers for these PMCs support the following common +qualifiers: +.Bl -tag -width indent +.It Li cmask= Ns Ar value +Configure the PMC to increment only if the number of configured +events measured in a cycle is greater than or equal to +.Ar value . +.It Li edge +Configure the PMC to count the number of de-asserted to asserted +transitions of the conditions expressed by the other qualifiers. +If specified, the counter will increment only once whenever a +condition becomes true, irrespective of the number of clocks during +which the condition remains true. +.It Li inv +Invert the sense of comparison when the +.Dq Li cmask +qualifier is present, making the counter increment when the number of +events per cycle is less than the value specified by the +.Dq Li cmask +qualifier. +.El +.Ss Event Specifiers (Programmable PMCs) +Haswell programmable PMCs support the following events: +.Bl -tag -width indent +.It Li UNC_CBO_XSNP_RESPONSE.MISS +.Pq Event 22H , Umask 01H +A snoop misses in some processor core. +.It Li UNC_CBO_XSNP_RESPONSE.INVAL +.Pq Event 22H , Umask 02H +A snoop invalidates a non-modified line in some +processor core. +.It Li UNC_CBO_XSNP_RESPONSE.HIT +.Pq Event 22H , Umask 04H +A snoop hits a non-modified line in some processor +core. +.It Li UNC_CBO_XSNP_RESPONSE.HITM +.Pq Event 22H , Umask 08H +A snoop hits a modified line in some processor core. +.It Li UNC_CBO_XSNP_RESPONSE.INVAL_M +.Pq Event 22H , Umask 10H +A snoop invalidates a modified line in some processor +core. +.It Li UNC_CBO_XSNP_RESPONSE.EXTERNAL_FILTER +.Pq Event 22H , Umask 20H +Filter on cross-core snoops initiated by this Cbox due +to external snoop request. +.It Li UNC_CBO_XSNP_RESPONSE.XCORE_FILTER +.Pq Event 22H , Umask 40H +Filter on cross-core snoops initiated by this Cbox due +to processor core memory request. +.It Li UNC_CBO_XSNP_RESPONSE.EVICTION_FILTER +.Pq Event 22H , Umask 80H +Filter on cross-core snoops initiated by this Cbox due +to LLC eviction. +.It Li UNC_CBO_CACHE_LOOKUP.M +.Pq Event 34H , Umask 01H +LLC lookup request that access cache and found line in +M-state. +.It Li UNC_CBO_CACHE_LOOKUP.ES +.Pq Event 34H , Umask 06H +LLC lookup request that access cache and found line in +E or S state. +.It Li UNC_CBO_CACHE_LOOKUP.I +.Pq Event 34H , Umask 08H +LLC lookup request that access cache and found line in +I-state. +.It Li UNC_CBO_CACHE_LOOKUP.READ_FILTER +.Pq Event 34H , Umask 10H +Filter on processor core initiated cacheable read +requests. Must combine with at least one of 01H, 02H, +04H, 08H. +.It Li UNC_CBO_CACHE_LOOKUP.WRITE_FILTER +.Pq Event 34H , Umask 20H +Filter on processor core initiated cacheable write +requests. Must combine with at least one of 01H, 02H, +04H, 08H. +.It Li UNC_CBO_CACHE_LOOKUP.EXTSNP_FILTER +.Pq Event 34H , Umask 40H +Filter on external snoop requests. Must combine with +at least one of 01H, 02H, 04H, 08H. +.It Li UNC_CBO_CACHE_LOOKUP.ANY_REQUEST_FILTER +.Pq Event 34H , Umask 80H +Filter on any IRQ or IPQ initiated requests including +uncacheable, non-coherent requests. Must combine +with at least one of 01H, 02H, 04H, 08H. +.It Li UNC_ARB_TRK_OCCUPANCY.ALL +.Pq Event 80H , Umask 01H +Counts cycles weighted by the number of requests +waiting for data returning from the memory controller. +Accounts for coherent and non-coherent requests +initiated by IA cores, processor graphic units, or LLC. +.It Li UNC_ARB_TRK_REQUEST.ALL +.Pq Event 81H , Umask 01H +Counts the number of coherent and in-coherent +requests initiated by IA cores, processor graphic units, +or LLC. +.It Li UNC_ARB_TRK_REQUEST.WRITES +.Pq Event 81H , Umask 20H +Counts the number of allocated write entries, include +full, partial, and LLC evictions. +.It Li UNC_ARB_TRK_REQUEST.EVICTIONS +.Pq Event 81H , Umask 80H +Counts the number of LLC evictions allocated. +.It Li UNC_ARB_COH , Umask TRK_OCCUPANCY.ALL +.Pq Event 83H , Umask 01H +Cycles weighted by number of requests pending in +Coherency Tracker. +.It Li UNC_ARB_COH , Umask TRK_REQUEST.ALL +.Pq Event 84H , Umask 01H +Number of requests allocated in Coherency Tracker. +.El +.Sh SEE ALSO +.Xr pmc 3 , +.Xr pmc.atom 3 , +.Xr pmc.core 3 , +.Xr pmc.corei7 3 , +.Xr pmc.corei7uc 3 , +.Xr pmc.haswell 3 , +.Xr pmc.iaf 3 , +.Xr pmc.k7 3 , +.Xr pmc.k8 3 , +.Xr pmc.p4 3 , +.Xr pmc.p5 3 , +.Xr pmc.p6 3 , +.Xr pmc.sandybridge 3 , +.Xr pmc.sandybridgeuc 3 , +.Xr pmc.sandybridgexeon 3 , +.Xr pmc.soft 3 , +.Xr pmc.tsc 3 , +.Xr pmc.ucf 3 , +.Xr pmc.westmere 3 , +.Xr pmc.westmereuc 3 , +.Xr pmc_cpuinfo 3 , +.Xr pmclog 3 , +.Xr hwpmc 4 +.Sh HISTORY +The +.Nm pmc +library first appeared in +.Fx 6.0 . +.Sh AUTHORS +The +.Lb libpmc +library was written by +.An "Joseph Koshy" +.Aq jkoshy@FreeBSD.org . +The support for the Haswell +microarchitecture was added by +.An "Hiren Panchasara" +.Aq hiren.panchasara@gmail.com . diff --git a/lib/libpmc/pmc.sandybridgexeon.3 b/lib/libpmc/pmc.sandybridgexeon.3 index 0ddaeda..8d69abd 100644 --- a/lib/libpmc/pmc.sandybridgexeon.3 +++ b/lib/libpmc/pmc.sandybridgexeon.3 @@ -219,7 +219,7 @@ L1D. .It Li MISALIGN_MEM_REF.STORES .Pq Event 05H , Umask 02H Speculative cache-line split Store- address uops -dispatchedto L1D. +dispatched to L1D. .It Li LD_BLOCKS_PARTIAL.ADDRESS_ALIAS .Pq Event 07H , Umask 01H False dependencies in MOB due to partial compare on diff --git a/lib/libpmc/pmc.soft.3 b/lib/libpmc/pmc.soft.3 index a8674ba..a6919ae 100644 --- a/lib/libpmc/pmc.soft.3 +++ b/lib/libpmc/pmc.soft.3 @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 28, 2012 +.Dd February 26, 2013 .Dt PMC.SOFT 3 .Os .Sh NAME @@ -61,6 +61,8 @@ The event specifiers supported by software are: Hard clock ticks. .It Li CLOCK.STAT Stat clock ticks. +.It Li CLOCK.PROF +Profiling clock ticks. .It Li LOCK.FAILED Lock acquisition failed. .It Li PAGE_FAULT.ALL diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c index 9d9c111..f23ec96 100644 --- a/lib/libprocstat/libprocstat.c +++ b/lib/libprocstat/libprocstat.c @@ -600,7 +600,6 @@ kinfo_fflags2fst(int kfflags) } kfflags2fst[] = { { KF_FLAG_APPEND, PS_FST_FFLAG_APPEND }, { KF_FLAG_ASYNC, PS_FST_FFLAG_ASYNC }, - { KF_FLAG_CAPABILITY, PS_FST_FFLAG_CAPABILITY }, { KF_FLAG_CREAT, PS_FST_FFLAG_CREAT }, { KF_FLAG_DIRECT, PS_FST_FFLAG_DIRECT }, { KF_FLAG_EXCL, PS_FST_FFLAG_EXCL }, diff --git a/lib/libprocstat/libprocstat.h b/lib/libprocstat/libprocstat.h index 662ea37..1c55aa7 100644 --- a/lib/libprocstat/libprocstat.h +++ b/lib/libprocstat/libprocstat.h @@ -88,7 +88,6 @@ #define PS_FST_FFLAG_DIRECT 0x1000 #define PS_FST_FFLAG_EXEC 0x2000 #define PS_FST_FFLAG_HASLOCK 0x4000 -#define PS_FST_FFLAG_CAPABILITY 0x8000 struct procstat; struct filestat { diff --git a/lib/libsbuf/Symbol.map b/lib/libsbuf/Symbol.map index 75af558..cf2508f 100644 --- a/lib/libsbuf/Symbol.map +++ b/lib/libsbuf/Symbol.map @@ -22,3 +22,8 @@ FBSD_1.2 { sbuf_done; sbuf_delete; }; + +FBSD_1.3 { + sbuf_start_section; + sbuf_end_section; +}; diff --git a/lib/libsbuf/Version.def b/lib/libsbuf/Version.def index ab673d9..fb0b3f6 100644 --- a/lib/libsbuf/Version.def +++ b/lib/libsbuf/Version.def @@ -2,3 +2,6 @@ FBSD_1.2 { }; + +FBSD_1.3 { +} FBSD_1.2; diff --git a/lib/libsm/Makefile b/lib/libsm/Makefile index f2f19fb..ce590d7 100644 --- a/lib/libsm/Makefile +++ b/lib/libsm/Makefile @@ -18,11 +18,6 @@ CFLAGS+=${SENDMAIL_CFLAGS} WARNS?= 2 -# Unfortunately, clang gives warnings about sendmail code that cannot -# be turned off yet. Since this is contrib code, and we don't really -# care about the warnings, just make them non-fatal for now. -NO_WERROR.clang= - LIB= sm SRCS+= sm_os.h diff --git a/lib/libstand/Makefile b/lib/libstand/Makefile index 807136d..2886e92 100644 --- a/lib/libstand/Makefile +++ b/lib/libstand/Makefile @@ -39,7 +39,7 @@ CFLAGS+= -msoft-float -D_STANDALONE # standalone components and stuff we have modified locally SRCS+= gzguts.h zutil.h __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \ - globals.c pager.c printf.c strdup.c strerror.c strtol.c random.c \ + globals.c pager.c printf.c strdup.c strerror.c strtol.c strtoul.c random.c \ sbrk.c twiddle.c zalloc.c zalloc_malloc.c # private (pruned) versions of libc string functions @@ -67,6 +67,9 @@ SRCS+= divsi3.S .else # Compiler support functions .PATH: ${.CURDIR}/../../contrib/compiler-rt/lib/ +# __clzsi2 and ctzsi2 for various builtin functions +SRCS+= clzsi2.c ctzsi2.c +# Divide and modulus functions called by the compiler SRCS+= divmoddi4.c divmodsi4.c divdi3.c divsi3.c moddi3.c modsi3.c SRCS+= udivmoddi4.c udivmodsi4.c udivdi3.c udivsi3.c umoddi3.c umodsi3.c diff --git a/lib/libstand/nandfs.c b/lib/libstand/nandfs.c index d5fcb9d..713dc12 100644 --- a/lib/libstand/nandfs.c +++ b/lib/libstand/nandfs.c @@ -95,8 +95,7 @@ static off_t nandfs_seek(struct open_file *, off_t, int); static int nandfs_stat(struct open_file *, struct stat *); static int nandfs_readdir(struct open_file *, struct dirent *); -static int nandfs_buf_read(struct nandfs *, char **, size_t *); -static struct nandfs_node *nandfs_lookup_inode(struct nandfs *, nandfs_daddr_t); +static int nandfs_buf_read(struct nandfs *, void **, size_t *); static struct nandfs_node *nandfs_lookup_path(struct nandfs *, const char *); static int nandfs_read_inode(struct nandfs *, struct nandfs_node *, nandfs_lbn_t, u_int, void *, int); @@ -125,6 +124,27 @@ struct fs_ops nandfs_fsops = { #define NINDIR(fs) ((fs)->nf_blocksize / sizeof(nandfs_daddr_t)) +/* from NetBSD's src/sys/net/if_ethersubr.c */ +static uint32_t +nandfs_crc32(uint32_t crc, const uint8_t *buf, size_t len) +{ + static const uint32_t crctab[] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, + 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, + 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c + }; + size_t i; + + crc = crc ^ ~0U; + for (i = 0; i < len; i++) { + crc ^= buf[i]; + crc = (crc >> 4) ^ crctab[crc & 0xf]; + crc = (crc >> 4) ^ crctab[crc & 0xf]; + } + return (crc ^ ~0U); +} + static int nandfs_check_fsdata_crc(struct nandfs_fsdata *fsdata) { @@ -138,7 +158,7 @@ nandfs_check_fsdata_crc(struct nandfs_fsdata *fsdata) /* Calculate */ fsdata->f_sum = (0); - comp_crc = crc32(0, (uint8_t *)fsdata, fsdata->f_bytes); + comp_crc = nandfs_crc32(0, (uint8_t *)fsdata, fsdata->f_bytes); /* Restore */ fsdata->f_sum = fsdata_crc; @@ -162,7 +182,7 @@ nandfs_check_superblock_crc(struct nandfs_fsdata *fsdata, /* Calculate */ super->s_sum = (0); - comp_crc = crc32(0, (uint8_t *)super, fsdata->f_sbbytes); + comp_crc = nandfs_crc32(0, (uint8_t *)super, fsdata->f_sbbytes); /* Restore */ super->s_sum = super_crc; @@ -397,7 +417,7 @@ nandfs_open(const char *path, struct open_file *f) return (0); } -static int +static void nandfs_free_node(struct nandfs_node *node) { struct bmap_buf *bmap, *tmp; @@ -424,6 +444,7 @@ nandfs_close(struct open_file *f) nandfs_free_node(fs->nf_opened_node); free(fs->nf_sb); free(fs); + return (0); } static int @@ -431,7 +452,7 @@ nandfs_read(struct open_file *f, void *addr, size_t size, size_t *resid) { struct nandfs *fs = (struct nandfs *)f->f_fsdata; size_t csize, buf_size; - uint8_t *buf; + void *buf; int error = 0; NANDFS_DEBUG("nandfs_read(file=%p, addr=%p, size=%d)\n", f, addr, size); @@ -440,7 +461,7 @@ nandfs_read(struct open_file *f, void *addr, size_t size, size_t *resid) if (fs->nf_offset >= fs->nf_opened_node->inode->i_size) break; - error = nandfs_buf_read(fs, (void *)&buf, &buf_size); + error = nandfs_buf_read(fs, &buf, &buf_size); if (error) break; @@ -517,7 +538,7 @@ nandfs_readdir(struct open_file *f, struct dirent *d) { struct nandfs *fs = f->f_fsdata; struct nandfs_dir_entry *dirent; - uint8_t *buf; + void *buf; size_t buf_size; NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p)\n", f, d); @@ -528,7 +549,7 @@ nandfs_readdir(struct open_file *f, struct dirent *d) return (ENOENT); } - if (nandfs_buf_read(fs, (void *)&buf, &buf_size)) { + if (nandfs_buf_read(fs, &buf, &buf_size)) { NANDFS_DEBUG("nandfs_readdir(file=%p, dirent=%p)" "buf_read failed\n", f, d); return (EIO); @@ -546,7 +567,7 @@ nandfs_readdir(struct open_file *f, struct dirent *d) } static int -nandfs_buf_read(struct nandfs *fs, char **buf_p, size_t *size_p) +nandfs_buf_read(struct nandfs *fs, void **buf_p, size_t *size_p) { nandfs_daddr_t blknr, blkoff; @@ -612,8 +633,8 @@ nandfs_lookup_path(struct nandfs *fs, const char *path) struct nandfs_node *node; struct nandfs_dir_entry *dirent; char *namebuf; - uint64_t i, j, done, counter, pinode, inode; - int nlinks = 0, len, link_len, nameidx; + uint64_t i, done, pinode, inode; + int nlinks = 0, counter, len, link_len, nameidx; uint8_t *buffer, *orig; char *strp, *lpath; @@ -650,7 +671,8 @@ nandfs_lookup_path(struct nandfs *fs, const char *path) buffer = orig; done = counter = 0; while (1) { - dirent = (struct nandfs_dir_entry *)buffer; + dirent = + (struct nandfs_dir_entry *)(void *)buffer; NANDFS_DEBUG("%s: dirent.name = %s\n", __func__, dirent->name); NANDFS_DEBUG("%s: dirent.rec_len = %d\n", @@ -746,9 +768,9 @@ static int nandfs_read_inode(struct nandfs *fs, struct nandfs_node *node, nandfs_daddr_t blknr, u_int nblks, void *buf, int raw) { - int i; uint64_t *pblks; uint64_t *vblks; + u_int i; int error; pblks = malloc(nblks * sizeof(uint64_t)); @@ -777,7 +799,7 @@ nandfs_read_inode(struct nandfs *fs, struct nandfs_node *node, return (EIO); } - buf += fs->nf_blocksize; + buf = (void *)((uintptr_t)buf + fs->nf_blocksize); } free(pblks); @@ -859,8 +881,7 @@ nandfs_bmap_lookup(struct nandfs *fs, struct nandfs_node *node, { struct nandfs_inode *ino; nandfs_daddr_t ind_block_num; - uint64_t *map, *indir; - uint64_t idx0, idx1, vblk, tmp; + uint64_t *map; int idx; int level; @@ -1006,7 +1027,7 @@ ioread(struct open_file *f, off_t pos, void *buf, u_int length) err = (f->f_dev->dv_strategy)(f->f_devdata, F_READ, pos, nsec * bsize, buffer, NULL); - memcpy(buf, buffer + off, length); + memcpy(buf, (void *)((uintptr_t)buffer + off), length); free(buffer); return (err); diff --git a/lib/libstand/stand.h b/lib/libstand/stand.h index 10bb829..2a1e9a9 100644 --- a/lib/libstand/stand.h +++ b/lib/libstand/stand.h @@ -261,6 +261,7 @@ extern u_long random(void); /* imports from stdlib, locally modified */ extern long strtol(const char *, char **, int); +extern unsigned long strtoul(const char *, char **, int); extern char *optarg; /* getopt(3) external variables */ extern int optind, opterr, optopt, optreset; extern int getopt(int, char * const [], const char *); diff --git a/lib/libstand/strtoul.c b/lib/libstand/strtoul.c new file mode 100644 index 0000000..5735d20 --- /dev/null +++ b/lib/libstand/strtoul.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * Copyright (c) 2011 The FreeBSD Foundation + * All rights reserved. + * Portions of this software were developed by David Chisnall + * under sponsorship from the FreeBSD Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include "stand.h" +#include <limits.h> + +/* + * Convert a string to an unsigned long integer. + * + * Assumes that the upper and lower case + * alphabets and digits are each contiguous. + */ +unsigned long +strtoul(const char * __restrict nptr, char ** __restrict endptr, int base) +{ + const char *s; + unsigned long acc; + char c; + unsigned long cutoff; + int neg, any, cutlim; + + /* + * See strtol for comments as to the logic used. + */ + s = nptr; + do { + c = *s++; + } while (isspace((unsigned char)c)); + if (c == '-') { + neg = 1; + c = *s++; + } else { + neg = 0; + if (c == '+') + c = *s++; + } + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X') && + ((s[1] >= '0' && s[1] <= '9') || + (s[1] >= 'A' && s[1] <= 'F') || + (s[1] >= 'a' && s[1] <= 'f'))) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + acc = any = 0; + if (base < 2 || base > 36) + goto noconv; + + cutoff = ULONG_MAX / base; + cutlim = ULONG_MAX % base; + for ( ; ; c = *s++) { + if (c >= '0' && c <= '9') + c -= '0'; + else if (c >= 'A' && c <= 'Z') + c -= 'A' - 10; + else if (c >= 'a' && c <= 'z') + c -= 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = ULONG_MAX; + errno = ERANGE; + } else if (!any) { +noconv: + errno = EINVAL; + } else if (neg) + acc = -acc; + if (endptr != NULL) + *endptr = (char *)(any ? s - 1 : nptr); + return (acc); +} diff --git a/lib/libthr/thread/thr_sig.c b/lib/libthr/thread/thr_sig.c index d2be994..a99395f 100644 --- a/lib/libthr/thread/thr_sig.c +++ b/lib/libthr/thread/thr_sig.c @@ -737,13 +737,4 @@ _setcontext(const ucontext_t *ucp) return __sys_setcontext(&uc); } -__weak_reference(_swapcontext, swapcontext); -int -_swapcontext(ucontext_t *oucp, const ucontext_t *ucp) -{ - ucontext_t uc; - - (void) memcpy(&uc, ucp, sizeof(uc)); - remove_thr_signals(&uc.uc_sigmask); - return __sys_swapcontext(oucp, &uc); -} +__weak_reference(__sys_swapcontext, swapcontext); diff --git a/lib/libusb/Makefile b/lib/libusb/Makefile index d45dd56..66dd795 100644 --- a/lib/libusb/Makefile +++ b/lib/libusb/Makefile @@ -37,6 +37,19 @@ SRCS+= libusb10_io.c CFLAGS+= -DCOMPAT_32BIT .endif +# +# Cross platform support +# +# Examples: +# make LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h +# make COMPAT_32BIT=YES LIBUSB_GLOBAL_INCLUDE_FILE=libusb_global_linux.h +# +.if defined(LIBUSB_GLOBAL_INCLUDE_FILE) +CFLAGS+= -DLIBUSB_GLOBAL_INCLUDE_FILE=\"${LIBUSB_GLOBAL_INCLUDE_FILE}\" +CFLAGS+= -DUSB_GLOBAL_INCLUDE_FILE=\"${LIBUSB_GLOBAL_INCLUDE_FILE}\" +CFLAGS+= -I ../../sys +.endif + .include <bsd.lib.mk> # LibUSB v1.0 @@ -190,6 +203,7 @@ MLINKS += libusb20.3 libusb20_dev_reset.3 MLINKS += libusb20.3 libusb20_dev_check_connected.3 MLINKS += libusb20.3 libusb20_dev_set_power_mode.3 MLINKS += libusb20.3 libusb20_dev_get_power_mode.3 +MLINKS += libusb20.3 libusb20_dev_get_power_usage.3 MLINKS += libusb20.3 libusb20_dev_set_alt_index.3 MLINKS += libusb20.3 libusb20_dev_get_device_desc.3 MLINKS += libusb20.3 libusb20_dev_alloc_config.3 diff --git a/lib/libusb/libusb.h b/lib/libusb/libusb.h index 1675f46..225b539 100644 --- a/lib/libusb/libusb.h +++ b/lib/libusb/libusb.h @@ -27,8 +27,11 @@ #ifndef __LIBUSB_H__ #define __LIBUSB_H__ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include <stdint.h> #include <sys/time.h> #include <sys/types.h> +#endif #ifdef __cplusplus extern "C" { diff --git a/lib/libusb/libusb01.c b/lib/libusb/libusb01.c index 17edb0e..30a1430 100644 --- a/lib/libusb/libusb01.c +++ b/lib/libusb/libusb01.c @@ -28,11 +28,16 @@ * This file contains the emulation layer for LibUSB v0.1 from sourceforge. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <errno.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <time.h> +#include <sys/queue.h> +#endif #include "libusb20.h" #include "libusb20_desc.h" diff --git a/lib/libusb/libusb10.c b/lib/libusb/libusb10.c index 256d67e..0212296 100644 --- a/lib/libusb/libusb10.c +++ b/lib/libusb/libusb10.c @@ -25,17 +25,23 @@ * SUCH DAMAGE. */ -#include <sys/fcntl.h> -#include <sys/ioctl.h> -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <assert.h> #include <errno.h> #include <poll.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <unistd.h> +#include <time.h> +#include <sys/fcntl.h> +#include <sys/ioctl.h> +#include <sys/queue.h> +#include <sys/endian.h> +#endif #define libusb_device_handle libusb20_device @@ -1331,7 +1337,7 @@ failure: /* make sure our event loop spins the done handler */ dummy = 0; - write(dev->ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); + err = write(dev->ctx->ctrl_pipe[1], &dummy, sizeof(dummy)); } /* The following function must be called unlocked */ diff --git a/lib/libusb/libusb10.h b/lib/libusb/libusb10.h index d2a2bd7..f1e5460 100644 --- a/lib/libusb/libusb10.h +++ b/lib/libusb/libusb10.h @@ -27,7 +27,9 @@ #ifndef __LIBUSB10_H__ #define __LIBUSB10_H__ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include <sys/queue.h> +#endif #define GET_CONTEXT(ctx) (((ctx) == NULL) ? usbi_default_context : (ctx)) #define UNEXPORTED __attribute__((__visibility__("hidden"))) diff --git a/lib/libusb/libusb10_desc.c b/lib/libusb/libusb10_desc.c index 11e201f..d2f3f53 100644 --- a/lib/libusb/libusb10_desc.c +++ b/lib/libusb/libusb10_desc.c @@ -24,10 +24,15 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <time.h> +#include <sys/queue.h> +#endif #define libusb_device_handle libusb20_device diff --git a/lib/libusb/libusb10_io.c b/lib/libusb/libusb10_io.c index 302fdb8..489ceb7 100644 --- a/lib/libusb/libusb10_io.c +++ b/lib/libusb/libusb10_io.c @@ -24,15 +24,20 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <errno.h> #include <poll.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #include <unistd.h> +#include <sys/queue.h> +#include <sys/endian.h> +#endif #define libusb_device_handle libusb20_device diff --git a/lib/libusb/libusb20.3 b/lib/libusb/libusb20.3 index af80c6c..8d286f1 100644 --- a/lib/libusb/libusb20.3 +++ b/lib/libusb/libusb20.3 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd August 13, 2012 +.Dd February 14, 2013 .Dt LIBUSB20 3 .Os .Sh NAME @@ -149,6 +149,8 @@ USB access library (libusb -lusb) .Fn libusb20_dev_set_power_mode "struct libusb20_device *pdev" "uint8_t power_mode" .Ft uint8_t .Fn libusb20_dev_get_power_mode "struct libusb20_device *pdev" +.Ft uint16_t +.Fn libusb20_dev_get_power_usage "struct libusb20_device *pdev" .Ft int .Fn libusb20_dev_set_alt_index "struct libusb20_device *pdev" "uint8_t iface_index" "uint8_t alt_index" .Ft struct LIBUSB20_DEVICE_DESC_DECODED * @@ -740,6 +742,12 @@ USB device. . .Pp . +.Fn libusb20_dev_get_power_usage +returns the reported power usage in milliamps for the given USB device. +A power usage of zero typically means that the device is self powered. +. +.Pp +. .Fn libusb20_dev_set_alt_index will try to set the given alternate index for the given USB interface index. diff --git a/lib/libusb/libusb20.c b/lib/libusb/libusb20.c index aa45991..644eda4 100644 --- a/lib/libusb/libusb20.c +++ b/lib/libusb/libusb20.c @@ -24,13 +24,17 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <ctype.h> #include <poll.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> +#include <sys/queue.h> +#endif #include "libusb20.h" #include "libusb20_desc.h" @@ -71,6 +75,7 @@ dummy_callback(struct libusb20_transfer *xfer) #define dummy_check_connected (void *)dummy_int #define dummy_set_power_mode (void *)dummy_int #define dummy_get_power_mode (void *)dummy_int +#define dummy_get_power_usage (void *)dummy_int #define dummy_kernel_driver_active (void *)dummy_int #define dummy_detach_kernel_driver (void *)dummy_int #define dummy_do_request_sync (void *)dummy_int @@ -717,6 +722,18 @@ libusb20_dev_get_power_mode(struct libusb20_device *pdev) return (power_mode); } +uint16_t +libusb20_dev_get_power_usage(struct libusb20_device *pdev) +{ + int error; + uint16_t power_usage; + + error = pdev->methods->get_power_usage(pdev, &power_usage); + if (error) + power_usage = 0; + return (power_usage); +} + int libusb20_dev_set_alt_index(struct libusb20_device *pdev, uint8_t ifaceIndex, uint8_t altIndex) { diff --git a/lib/libusb/libusb20.h b/lib/libusb/libusb20.h index 87e0572..4a57b49 100644 --- a/lib/libusb/libusb20.h +++ b/lib/libusb/libusb20.h @@ -29,13 +29,9 @@ #ifndef _LIBUSB20_H_ #define _LIBUSB20_H_ -#include <sys/endian.h> -#include <sys/time.h> -#include <sys/types.h> - +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE #include <stdint.h> -#include <string.h> -#include <time.h> +#endif #ifdef __cplusplus extern "C" { @@ -255,6 +251,7 @@ int libusb20_dev_reset(struct libusb20_device *pdev); int libusb20_dev_check_connected(struct libusb20_device *pdev); int libusb20_dev_set_power_mode(struct libusb20_device *pdev, uint8_t power_mode); uint8_t libusb20_dev_get_power_mode(struct libusb20_device *pdev); +uint16_t libusb20_dev_get_power_usage(struct libusb20_device *pdev); int libusb20_dev_set_alt_index(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index); int libusb20_dev_get_info(struct libusb20_device *pdev, struct usb_device_info *pinfo); int libusb20_dev_get_iface_desc(struct libusb20_device *pdev, uint8_t iface_index, char *buf, uint8_t len); diff --git a/lib/libusb/libusb20_desc.c b/lib/libusb/libusb20_desc.c index e2fa5b5..22077b6 100644 --- a/lib/libusb/libusb20_desc.c +++ b/lib/libusb/libusb20_desc.c @@ -24,11 +24,15 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <time.h> +#include <sys/queue.h> +#endif #include "libusb20.h" #include "libusb20_desc.h" diff --git a/lib/libusb/libusb20_desc.h b/lib/libusb/libusb20_desc.h index a069ee9..48e2715 100644 --- a/lib/libusb/libusb20_desc.h +++ b/lib/libusb/libusb20_desc.h @@ -45,6 +45,10 @@ #ifndef _LIBUSB20_DESC_H_ #define _LIBUSB20_DESC_H_ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include <stdint.h> +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/libusb/libusb20_int.h b/lib/libusb/libusb20_int.h index 0251c5f..6705c63 100644 --- a/lib/libusb/libusb20_int.h +++ b/lib/libusb/libusb20_int.h @@ -105,6 +105,7 @@ typedef int (libusb20_process_t)(struct libusb20_device *pdev); typedef int (libusb20_reset_device_t)(struct libusb20_device *pdev); typedef int (libusb20_set_power_mode_t)(struct libusb20_device *pdev, uint8_t power_mode); typedef int (libusb20_get_power_mode_t)(struct libusb20_device *pdev, uint8_t *power_mode); +typedef int (libusb20_get_power_usage_t)(struct libusb20_device *pdev, uint16_t *power_usage); typedef int (libusb20_set_alt_index_t)(struct libusb20_device *pdev, uint8_t iface_index, uint8_t alt_index); typedef int (libusb20_set_config_index_t)(struct libusb20_device *pdev, uint8_t index); typedef int (libusb20_check_connected_t)(struct libusb20_device *pdev); @@ -127,6 +128,7 @@ typedef void (libusb20_tr_cancel_async_t)(struct libusb20_transfer *xfer); m(n, check_connected) \ m(n, set_power_mode) \ m(n, get_power_mode) \ + m(n, get_power_usage) \ m(n, set_alt_index) \ m(n, set_config_index) \ m(n, tr_cancel_async) \ diff --git a/lib/libusb/libusb20_ugen20.c b/lib/libusb/libusb20_ugen20.c index 2c67778..0846eb4 100644 --- a/lib/libusb/libusb20_ugen20.c +++ b/lib/libusb/libusb20_ugen20.c @@ -24,24 +24,28 @@ * SUCH DAMAGE. */ -#include <sys/queue.h> -#include <sys/types.h> - +#ifdef LIBUSB_GLOBAL_INCLUDE_FILE +#include LIBUSB_GLOBAL_INCLUDE_FILE +#else #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> - -#include "libusb20.h" -#include "libusb20_desc.h" -#include "libusb20_int.h" +#include <time.h> +#include <sys/queue.h> +#include <sys/types.h> +#endif #include <dev/usb/usb.h> #include <dev/usb/usbdi.h> #include <dev/usb/usb_ioctl.h> +#include "libusb20.h" +#include "libusb20_desc.h" +#include "libusb20_int.h" + static libusb20_init_backend_t ugen20_init_backend; static libusb20_open_device_t ugen20_open_device; static libusb20_close_device_t ugen20_close_device; @@ -69,6 +73,7 @@ static libusb20_reset_device_t ugen20_reset_device; static libusb20_check_connected_t ugen20_check_connected; static libusb20_set_power_mode_t ugen20_set_power_mode; static libusb20_get_power_mode_t ugen20_get_power_mode; +static libusb20_get_power_usage_t ugen20_get_power_usage; static libusb20_kernel_driver_active_t ugen20_kernel_driver_active; static libusb20_detach_kernel_driver_t ugen20_detach_kernel_driver; static libusb20_do_request_sync_t ugen20_do_request_sync; @@ -639,6 +644,18 @@ ugen20_get_power_mode(struct libusb20_device *pdev, uint8_t *power_mode) } static int +ugen20_get_power_usage(struct libusb20_device *pdev, uint16_t *power_usage) +{ + int temp; + + if (ioctl(pdev->file_ctrl, USB_GET_POWER_USAGE, &temp)) { + return (LIBUSB20_ERROR_OTHER); + } + *power_usage = temp; + return (0); /* success */ +} + +static int ugen20_kernel_driver_active(struct libusb20_device *pdev, uint8_t iface_index) { diff --git a/lib/libprocstat/nwfs.c b/lib/libusb/libusb_global_linux.h index 006f9aa..cbdd2c6 100644 --- a/lib/libprocstat/nwfs.c +++ b/lib/libusb/libusb_global_linux.h @@ -1,6 +1,6 @@ +/* $FreeBSD$ */ /*- - * Copyright (c) 2005-2009 Stanislav Sedov <stas@FreeBSD.org> - * All rights reserved. + * Copyright (c) 2013 Hans Petter Selasky. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,54 +23,47 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); -#include <sys/param.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/vnode.h> -#define _KERNEL -#include <sys/mount.h> -#undef _KERNEL +#ifndef _LIBUSB_GLOBAL_LINUX_H_ +#define _LIBUSB_GLOBAL_LINUX_H_ -#include <netinet/in.h> +#define _XOPEN_SOURCE +#define _BSD_SOURCE +#define _POSIX_SOURCE +#define _POSIX_C_SOURCE 200809 -#include <assert.h> -#include <err.h> -#include <kvm.h> +#include <ctype.h> +#include <errno.h> +#include <stdio.h> #include <stdlib.h> +#include <stdint.h> +#include <time.h> +#include <unistd.h> +#include <alloca.h> +#include <string.h> +#include <fcntl.h> +#include <limits.h> +#include <pthread.h> +#include <sys/queue.h> +#include <sys/ioctl.h> +#include <sys/poll.h> +#include <sys/time.h> +#include <dev/usb/usb_endian.h> +#include <dev/usb/usb_freebsd.h> -#include <fs/nwfs/nwfs.h> -#include <fs/nwfs/nwfs_node.h> +#ifndef __aligned +#define __aligned(x) __attribute__((__aligned__(x))) +#endif -#include "libprocstat.h" -#include "common_kvm.h" +#ifndef __packed +#define __packed __attribute__((__packed__)) +#endif -int -nwfs_filestat(kvm_t *kd, struct vnode *vp, struct vnstat *vn) -{ - struct mount mnt; - struct nwnode node; - int error; +#ifndef strlcpy +#define strlcpy(d,s,len) do { \ + strncpy(d,s,len); \ + ((char *)d)[(len) - 1] = 0; \ +} while (0) +#endif - assert(kd); - assert(vn); - error = kvm_read_all(kd, (unsigned long)VTONW(vp), &node, sizeof(node)); - if (error != 0) { - warnx("can't read nwfs fnode at %p", (void *)VTONW(vp)); - return (1); - } - error = kvm_read_all(kd, (unsigned long)getvnodemount(vp), &mnt, - sizeof(mnt)); - if (error != 0) { - warnx("can't read mount at %p for vnode %p", - (void *)getvnodemount(vp), vp); - return (1); - } - vn->vn_fileid = node.n_fid.f_id; - if (vn->vn_fileid == 0) - vn->vn_fileid = NWFS_ROOT_INO; - vn->vn_fsid = mnt.mnt_stat.f_fsid.val[0]; - return (0); -} +#endif /* _LIBUSB_GLOBAL_LINUX_H_ */ diff --git a/lib/libusb/usb.h b/lib/libusb/usb.h index dc3959e..d7bbaa5 100644 --- a/lib/libusb/usb.h +++ b/lib/libusb/usb.h @@ -27,10 +27,11 @@ #ifndef _LIBUSB20_COMPAT_01_H_ #define _LIBUSB20_COMPAT_01_H_ +#ifndef LIBUSB_GLOBAL_INCLUDE_FILE +#include <stdint.h> #include <sys/param.h> #include <sys/endian.h> - -#include <stdint.h> +#endif /* USB interface class codes */ diff --git a/lib/libutil/gr_util.c b/lib/libutil/gr_util.c index 3f7e199..6f74507 100644 --- a/lib/libutil/gr_util.c +++ b/lib/libutil/gr_util.c @@ -49,6 +49,8 @@ static char group_dir[PATH_MAX]; static char group_file[PATH_MAX]; static char tempname[PATH_MAX]; static int initialized; +static size_t grmemlen(const struct group *, const char *, int *); +static struct group *grcopy(const struct group *gr, char *mem, const char *, int ndx); /* * Initialize statics @@ -359,26 +361,30 @@ gr_equal(const struct group *gr1, const struct group *gr2) if (gr1->gr_gid != gr2->gr_gid) return (false); - /* Check all members in both groups. */ - if (gr1->gr_mem == NULL || gr2->gr_mem == NULL) { - if (gr1->gr_mem != gr2->gr_mem) - return (false); - } else { - for (gr1_ndx = 0; gr1->gr_mem[gr1_ndx] != NULL; gr1_ndx++) { - for (gr2_ndx = 0;; gr2_ndx++) { - if (gr2->gr_mem[gr2_ndx] == NULL) - return (false); - if (strcmp(gr1->gr_mem[gr1_ndx], - gr2->gr_mem[gr2_ndx]) == 0) { - break; - } - } + /* Check all members in both groups. + * getgrnam can return gr_mem with a pointer to NULL. + * gr_dup and gr_add strip out this superfluous NULL, setting + * gr_mem to NULL for no members. + */ + if (gr1->gr_mem != NULL && gr2->gr_mem != NULL) { + int i; + + for (i = 0; gr1->gr_mem[i] != NULL; i++) { + if (strcmp(gr1->gr_mem[i], gr2->gr_mem[i]) != 0) + return (false); } - - /* Check that group2 does not have more members than group1. */ - if (gr2->gr_mem[gr1_ndx] != NULL) - return (false); } + /* Count number of members in both structs */ + gr2_ndx = 0; + if (gr2->gr_mem != NULL) + for(; gr2->gr_mem[gr2_ndx] != NULL; gr2_ndx++) + /* empty */; + gr1_ndx = 0; + if (gr1->gr_mem != NULL) + for(; gr1->gr_mem[gr1_ndx] != NULL; gr1_ndx++) + /* empty */; + if (gr1_ndx != gr2_ndx) + return (false); return (true); } @@ -429,90 +435,129 @@ gr_make(const struct group *gr) struct group * gr_dup(const struct group *gr) { - struct group *newgr; - char *dst; + return (gr_add(gr, NULL)); +} +/* + * Add a new member name to a struct group. + */ +struct group * +gr_add(const struct group *gr, const char *newmember) +{ + char *mem; size_t len; - int ndx; int num_mem; - /* Calculate size of the group. */ - len = sizeof(*newgr); - if (gr->gr_name != NULL) - len += strlen(gr->gr_name) + 1; - if (gr->gr_passwd != NULL) - len += strlen(gr->gr_passwd) + 1; - if (gr->gr_mem != NULL) { - for (num_mem = 0; gr->gr_mem[num_mem] != NULL; num_mem++) - len += strlen(gr->gr_mem[num_mem]) + 1; - len += (num_mem + 1) * sizeof(*gr->gr_mem); - } else - num_mem = -1; + num_mem = 0; + len = grmemlen(gr, newmember, &num_mem); /* Create new group and copy old group into it. */ - if ((newgr = malloc(len)) == NULL) + if ((mem = malloc(len)) == NULL) return (NULL); - /* point new gr_mem to end of struct + 1 */ - if (gr->gr_mem != NULL) - newgr->gr_mem = (char **)(newgr + 1); - else + return (grcopy(gr, mem, newmember, num_mem)); +} + +/* It is safer to walk the pointers given at gr_mem since there is no + * guarantee the gr_mem + strings are contiguous in the given struct group + * but compactify the new group into the following form. + * + * The new struct is laid out like this in memory. The example given is + * for a group with two members only. + * + * { + * (char *name) + * (char *passwd) + * (int gid) + * (gr_mem * newgrp + sizeof(struct group) + sizeof(**)) points to gr_mem area + * gr_mem area + * (member1 *) + * (member2 *) + * (NULL) + * (name string) + * (passwd string) + * (member1 string) + * (member2 string) + * } + */ +/* + * Copy the contents of a group plus given name to a preallocated group struct + */ +static struct group * +grcopy(const struct group *gr, char *dst, const char *name, int ndx) +{ + int i; + struct group *newgr; + + newgr = (struct group *)(void *)dst; /* avoid alignment warning */ + dst += sizeof(*newgr); + if (ndx != 0) { + newgr->gr_mem = (char **)(void *)(dst); /* avoid alignment warning */ + dst += (ndx + 1) * sizeof(*newgr->gr_mem); + } else newgr->gr_mem = NULL; - /* point dst after the end of all the gr_mem pointers in newgr */ - dst = (char *)&newgr->gr_mem[num_mem + 1]; if (gr->gr_name != NULL) { newgr->gr_name = dst; dst = stpcpy(dst, gr->gr_name) + 1; - } else { + } else newgr->gr_name = NULL; - } if (gr->gr_passwd != NULL) { newgr->gr_passwd = dst; dst = stpcpy(dst, gr->gr_passwd) + 1; - } else { + } else newgr->gr_passwd = NULL; - } newgr->gr_gid = gr->gr_gid; + i = 0; + /* Original group struct might have a NULL gr_mem */ if (gr->gr_mem != NULL) { - for (ndx = 0; ndx < num_mem; ndx++) { - newgr->gr_mem[ndx] = dst; - dst = stpcpy(dst, gr->gr_mem[ndx]) + 1; + for (; gr->gr_mem[i] != NULL; i++) { + newgr->gr_mem[i] = dst; + dst = stpcpy(dst, gr->gr_mem[i]) + 1; } - newgr->gr_mem[ndx] = NULL; } + /* If name is not NULL, newgr->gr_mem is known to be not NULL */ + if (name != NULL) { + newgr->gr_mem[i++] = dst; + dst = stpcpy(dst, name) + 1; + } + /* if newgr->gr_mem is not NULL add NULL marker */ + if (newgr->gr_mem != NULL) + newgr->gr_mem[i] = NULL; + return (newgr); } /* - * Add a new member name to a struct group. + * Calculate length of a struct group + given name */ -struct group * -gr_add(struct group *gr, char *newmember) +static size_t +grmemlen(const struct group *gr, const char *name, int *num_mem) { - size_t mlen; - int num_mem=0; - char **members; - struct group *newgr; - - if (newmember == NULL) - return(gr_dup(gr)); + size_t len; + int i; + if (gr == NULL) + return (0); + /* Calculate size of the group. */ + len = sizeof(*gr); + if (gr->gr_name != NULL) + len += strlen(gr->gr_name) + 1; + if (gr->gr_passwd != NULL) + len += strlen(gr->gr_passwd) + 1; + i = 0; if (gr->gr_mem != NULL) { - for (num_mem = 0; gr->gr_mem[num_mem] != NULL; num_mem++) { - if (strcmp(gr->gr_mem[num_mem], newmember) == 0) { - errno = EEXIST; - return (NULL); - } + for (; gr->gr_mem[i] != NULL; i++) { + len += strlen(gr->gr_mem[i]) + 1; + len += sizeof(*gr->gr_mem); } } - /* Allocate enough for current pointers + 1 more and NULL marker */ - mlen = (num_mem + 2) * sizeof(*gr->gr_mem); - if ((members = malloc(mlen)) == NULL) - return (NULL); - memcpy(members, gr->gr_mem, num_mem * sizeof(*gr->gr_mem)); - members[num_mem++] = newmember; - members[num_mem] = NULL; - gr->gr_mem = members; - newgr = gr_dup(gr); - free(members); - return (newgr); + if (name != NULL) { + i++; + len += strlen(name) + 1; + len += sizeof(*gr->gr_mem); + } + /* Allow for NULL pointer */ + if (i != 0) + len += sizeof(*gr->gr_mem); + *num_mem = i; + return(len); } /* diff --git a/lib/libutil/kinfo_getproc.3 b/lib/libutil/kinfo_getproc.3 index 68b8819..804cb6c 100644 --- a/lib/libutil/kinfo_getproc.3 +++ b/lib/libutil/kinfo_getproc.3 @@ -25,7 +25,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 25, 2012 +.Dd March 1, 2013 .Dt KINFO_GETPROC 3 .Os .Sh NAME @@ -37,7 +37,7 @@ .In sys/types.h .In libutil.h .Ft struct kinfo_proc * -.Fn kinfo_getproc "pid_t pid" "int *cntp" +.Fn kinfo_getproc "pid_t pid" .Sh DESCRIPTION This function is used for obtaining process information from the kernel. .Pp diff --git a/lib/libutil/libutil.h b/lib/libutil/libutil.h index b1b2405..b8b9836 100644 --- a/lib/libutil/libutil.h +++ b/lib/libutil/libutil.h @@ -167,7 +167,7 @@ int gr_copy(int __ffd, int _tfd, const struct group *_gr, struct group * gr_dup(const struct group *_gr); struct group * - gr_add(struct group *_gr, char *_newmember); + gr_add(const struct group *_gr, const char *_newmember); int gr_equal(const struct group *_gr1, const struct group *_gr2); void gr_fini(void); int gr_init(const char *_dir, const char *_master); diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index bca0315..7949e9e 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -126,20 +126,25 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr) fd = flopen(pfh->pf_path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode); if (fd == -1) { - if (errno == EWOULDBLOCK && pidptr != NULL) { - count = 20; - rqtp.tv_sec = 0; - rqtp.tv_nsec = 5000000; - for (;;) { - errno = pidfile_read(pfh->pf_path, pidptr); - if (errno != EAGAIN || --count == 0) - break; - nanosleep(&rqtp, 0); - } - if (errno == EAGAIN) - *pidptr = -1; - if (errno == 0 || errno == EAGAIN) + if (errno == EWOULDBLOCK) { + if (pidptr == NULL) { errno = EEXIST; + } else { + count = 20; + rqtp.tv_sec = 0; + rqtp.tv_nsec = 5000000; + for (;;) { + errno = pidfile_read(pfh->pf_path, + pidptr); + if (errno != EAGAIN || --count == 0) + break; + nanosleep(&rqtp, 0); + } + if (errno == EAGAIN) + *pidptr = -1; + if (errno == 0 || errno == EAGAIN) + errno = EEXIST; + } } free(pfh); return (NULL); diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c index cfb42d0..6982ba3 100644 --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -48,8 +48,16 @@ __FBSDID("$FreeBSD$"); #include "vmmapi.h" +#define GB (1024 * 1024 * 1024UL) + struct vmctx { int fd; + uint32_t lowmem_limit; + enum vm_mmap_style vms; + size_t lowmem; + char *lowmem_addr; + size_t highmem; + char *highmem_addr; char *name; }; @@ -90,6 +98,7 @@ vm_open(const char *name) assert(vm != NULL); vm->fd = -1; + vm->lowmem_limit = 3 * GB; vm->name = (char *)(vm + 1); strcpy(vm->name, name); @@ -151,8 +160,22 @@ vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len) return (error); } -int -vm_setup_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **mapaddr) +uint32_t +vm_get_lowmem_limit(struct vmctx *ctx) +{ + + return (ctx->lowmem_limit); +} + +void +vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit) +{ + + ctx->lowmem_limit = limit; +} + +static int +setup_memory_segment(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **addr) { int error; struct vm_memory_segment seg; @@ -165,20 +188,69 @@ vm_setup_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len, char **mapaddr) seg.gpa = gpa; seg.len = len; error = ioctl(ctx->fd, VM_MAP_MEMORY, &seg); - if (error == 0 && mapaddr != NULL) { - *mapaddr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, + if (error == 0 && addr != NULL) { + *addr = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, ctx->fd, gpa); } return (error); } -char * -vm_map_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len) +int +vm_setup_memory(struct vmctx *ctx, size_t memsize, enum vm_mmap_style vms) +{ + char **addr; + int error; + + /* XXX VM_MMAP_SPARSE not implemented yet */ + assert(vms == VM_MMAP_NONE || vms == VM_MMAP_ALL); + ctx->vms = vms; + + /* + * If 'memsize' cannot fit entirely in the 'lowmem' segment then + * create another 'highmem' segment above 4GB for the remainder. + */ + if (memsize > ctx->lowmem_limit) { + ctx->lowmem = ctx->lowmem_limit; + ctx->highmem = memsize - ctx->lowmem; + } else { + ctx->lowmem = memsize; + ctx->highmem = 0; + } + + if (ctx->lowmem > 0) { + addr = (vms == VM_MMAP_ALL) ? &ctx->lowmem_addr : NULL; + error = setup_memory_segment(ctx, 0, ctx->lowmem, addr); + if (error) + return (error); + } + + if (ctx->highmem > 0) { + addr = (vms == VM_MMAP_ALL) ? &ctx->highmem_addr : NULL; + error = setup_memory_segment(ctx, 4*GB, ctx->highmem, addr); + if (error) + return (error); + } + + return (0); +} + +void * +vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len) { - /* Map 'len' bytes of memory at guest physical address 'gpa' */ - return ((char *)mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, - ctx->fd, gpa)); + /* XXX VM_MMAP_SPARSE not implemented yet */ + assert(ctx->vms == VM_MMAP_ALL); + + if (gaddr < ctx->lowmem && gaddr + len <= ctx->lowmem) + return ((void *)(ctx->lowmem_addr + gaddr)); + + if (gaddr >= 4*GB) { + gaddr -= 4*GB; + if (gaddr < ctx->highmem && gaddr + len <= ctx->highmem) + return ((void *)(ctx->highmem_addr + gaddr)); + } + + return (NULL); } int @@ -250,34 +322,6 @@ vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *ret_val) } int -vm_get_pinning(struct vmctx *ctx, int vcpu, int *host_cpuid) -{ - int error; - struct vm_pin vmpin; - - bzero(&vmpin, sizeof(vmpin)); - vmpin.vm_cpuid = vcpu; - - error = ioctl(ctx->fd, VM_GET_PINNING, &vmpin); - *host_cpuid = vmpin.host_cpuid; - return (error); -} - -int -vm_set_pinning(struct vmctx *ctx, int vcpu, int host_cpuid) -{ - int error; - struct vm_pin vmpin; - - bzero(&vmpin, sizeof(vmpin)); - vmpin.vm_cpuid = vcpu; - vmpin.host_cpuid = host_cpuid; - - error = ioctl(ctx->fd, VM_SET_PINNING, &vmpin); - return (error); -} - -int vm_run(struct vmctx *ctx, int vcpu, uint64_t rip, struct vm_exit *vmexit) { int error; diff --git a/lib/libvmmapi/vmmapi.h b/lib/libvmmapi/vmmapi.h index de04252..f066c50 100644 --- a/lib/libvmmapi/vmmapi.h +++ b/lib/libvmmapi/vmmapi.h @@ -32,32 +32,32 @@ struct vmctx; enum x2apic_state; +/* + * Different styles of mapping the memory assigned to a VM into the address + * space of the controlling process. + */ +enum vm_mmap_style { + VM_MMAP_NONE, /* no mapping */ + VM_MMAP_ALL, /* fully and statically mapped */ + VM_MMAP_SPARSE, /* mappings created on-demand */ +}; + int vm_create(const char *name); struct vmctx *vm_open(const char *name); void vm_destroy(struct vmctx *ctx); size_t vmm_get_mem_total(void); size_t vmm_get_mem_free(void); int vm_get_memory_seg(struct vmctx *ctx, vm_paddr_t gpa, size_t *ret_len); -/* - * Create a memory segment of 'len' bytes in the guest physical address space - * at offset 'gpa'. - * - * If 'mapaddr' is not NULL then this region is mmap'ed into the address - * space of the calling process. If there is an mmap error then *mapaddr - * will be set to MAP_FAILED. - */ - -int vm_setup_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len, - char **mapaddr); -char * vm_map_memory(struct vmctx *ctx, vm_paddr_t gpa, size_t len); +int vm_setup_memory(struct vmctx *ctx, size_t len, enum vm_mmap_style s); +void *vm_map_gpa(struct vmctx *ctx, vm_paddr_t gaddr, size_t len); +uint32_t vm_get_lowmem_limit(struct vmctx *ctx); +void vm_set_lowmem_limit(struct vmctx *ctx, uint32_t limit); int vm_set_desc(struct vmctx *ctx, int vcpu, int reg, uint64_t base, uint32_t limit, uint32_t access); int vm_get_desc(struct vmctx *ctx, int vcpu, int reg, uint64_t *base, uint32_t *limit, uint32_t *access); int vm_set_register(struct vmctx *ctx, int vcpu, int reg, uint64_t val); int vm_get_register(struct vmctx *ctx, int vcpu, int reg, uint64_t *retval); -int vm_get_pinning(struct vmctx *ctx, int vcpu, int *host_cpuid); -int vm_set_pinning(struct vmctx *ctx, int vcpu, int host_cpuid); int vm_run(struct vmctx *ctx, int vcpu, uint64_t rip, struct vm_exit *ret_vmexit); int vm_apicid2vcpu(struct vmctx *ctx, int apicid); diff --git a/lib/libyaml/Makefile b/lib/libyaml/Makefile new file mode 100644 index 0000000..5ecec78 --- /dev/null +++ b/lib/libyaml/Makefile @@ -0,0 +1,24 @@ +# $FreeBSD$ + +LIBYAML= ${.CURDIR}/../../contrib/libyaml + +LIB= bsdyml +SHLIB_MAJOR= 0 +INCS= bsdyml.h +SRCS= api.c dumper.c emitter.c loader.c \ + parser.c reader.c scanner.c writer.c +MAN= libbsdyml.3 + +.PATH: ${LIBYAML}/src ${LIBYAML}/include +CLEANFILES= bsdyml.h + +WARNS?= 1 +CFLAGS+= -I${LIBYAML}/include \ + -I${LIBYAML} \ + -I${.CURDIR} \ + -DHAVE_CONFIG_H + +bsdyml.h: yaml.h + cp -f ${.ALLSRC} ${.TARGET} + +.include <bsd.lib.mk> diff --git a/lib/libyaml/config.h b/lib/libyaml/config.h new file mode 100644 index 0000000..7032919 --- /dev/null +++ b/lib/libyaml/config.h @@ -0,0 +1,83 @@ +/* $FreeBSD$ */ + +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "yaml" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "http://pyyaml.org/newticket?component=libyaml" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "yaml" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "yaml 0.1.4" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "yaml" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "0.1.4" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "0.1.4" + +/* Define the major version number. */ +#define YAML_VERSION_MAJOR 0 + +/* Define the minor version number. */ +#define YAML_VERSION_MINOR 1 + +/* Define the patch version number. */ +#define YAML_VERSION_PATCH 4 + +/* Define the version string. */ +#define YAML_VERSION_STRING "0.1.4" + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `unsigned int' if <sys/types.h> does not define. */ +/* #undef size_t */ diff --git a/lib/libyaml/libbsdyml.3 b/lib/libyaml/libbsdyml.3 new file mode 100644 index 0000000..927c47c --- /dev/null +++ b/lib/libyaml/libbsdyml.3 @@ -0,0 +1,61 @@ +.\" Copyright (c) 2013 Baptiste Daroussin <bapt@FreeBSD.org> +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd March 05, 2013 +.Dt LIBBSDYML 3 +.Os +.Sh NAME +.Nm libbsdyml +.Nd LibYAML library for parsing and emitting YAML +.Sh SYNOPSIS +.In bsdyml.h +.Sh DESCRIPTION +The +.Nm +library is a verbatim copy of the LibYAML version 0.1.4 +.Pp +The +.Nm +library is intended to be used within the +.Fx +base system only. +Use of the +.Nm +library for other purposes is not supported and discouraged. +.Pp +To avoid version and autoconfiguration issues, the library has been +renamed to +.Nm +rather than retain the original LibYAML library and include file names +to prevent confusion and autoconfiguration issues for 3rd party +software. +.Sh SEE ALSO +For full documentation, please see the LibYAML webpage at +.Pa http://pyyaml.org/wiki/LibYAML . +.Sh AUTHORS +.An -nosplit +The original LibYAML was written by +.An Kirill Simonov Aq xi@resolvent.net . |