From afa5f1bdb11b69ffd6c9171fdade7bf337fa8c06 Mon Sep 17 00:00:00 2001 From: Apple Date: Sat, 12 Nov 2011 00:30:33 +0000 Subject: [PATCH] libutil-30.tar.gz --- ExtentManager.cpp | 150 +++++++- Makefile | 123 ------ _secure_path.3 | 75 ---- _secure_path.c | 73 ---- getmntopts.3 | 143 +++++-- libutil.exports | 10 +- libutil.h | 79 +--- libutil.plist | 6 +- libutil.xcodeproj/project.pbxproj | 355 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + property.3 | 99 ----- property.c | 257 ------------- realhostname.c | 2 + trimdomain.c | 6 +- uucplock.3 | 183 --------- uucplock.c | 229 ----------- wipefs.3 | 46 ++- wipefs.cpp | 19 +- wipefs.h | 1 + 19 files changed, 680 insertions(+), 1183 deletions(-) delete mode 100644 Makefile delete mode 100644 _secure_path.3 delete mode 100644 _secure_path.c create mode 100644 libutil.xcodeproj/project.pbxproj create mode 100644 libutil.xcodeproj/project.xcworkspace/contents.xcworkspacedata delete mode 100644 property.3 delete mode 100644 property.c delete mode 100644 uucplock.3 delete mode 100644 uucplock.c diff --git a/ExtentManager.cpp b/ExtentManager.cpp index 74d54c6..905b432 100644 --- a/ExtentManager.cpp +++ b/ExtentManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Apple Inc. All rights reserved. + * Copyright (c) 2008-2009,2011 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -121,27 +121,49 @@ ExtentManager::RemoveBlockRangeExtent(off_t blockAddr, off_t numBlocks) } if (BeforeExtent(ext, *curIt)) // we are done break; - // overlapped extents + + // + // If we get here, the input extent and *curIt have at least one block in common. + // That is, they overlap in some way. Thus *curIt needs to change, be removed, + // or be split into two non-contiguous extents. + // + if (curIt->blockAddr >= ext.blockAddr && curIt->blockAddr + curIt->numBlocks <= ext.blockAddr + ext.numBlocks) { - // *curIt is totally within ext, remove curIt + // + // The input extent totally contains *curIt, so remove *curIt. + // curIt = extentList.erase(curIt); } else if (curIt->blockAddr < ext.blockAddr && curIt->blockAddr + curIt->numBlocks > ext.blockAddr + ext.numBlocks) { - // ext is totally within *curIt, split ext into two + // + // The input extent does not include the start of *curIt, nor the end of *curIt, + // so split *curIt into two extents. + // newExt.blockAddr = ext.blockAddr + ext.numBlocks; newExt.numBlocks = curIt->blockAddr + curIt->numBlocks - newExt.blockAddr; curIt->numBlocks = ext.blockAddr - curIt->blockAddr; curIt++; extentList.insert(curIt, newExt); // throws bad_alloc when out of memory curIt++; - } else { // remove part of ext - if (curIt->blockAddr >= ext.blockAddr) { // remove the former part of *curIt - assert(curIt->blockAddr + curIt->numBlocks > newExt.blockAddr); + } else { + // + // The input extent contains either the start or the end of *curIt, but not both. + // The remove will leave either the end or the start of *curIt (respectively) and + // not change the number of extents in the list. + // + if (curIt->blockAddr >= ext.blockAddr) { + // + // Remove the start of *curIt by updating both its starting block and size. + // + assert(curIt->blockAddr + curIt->numBlocks > ext.blockAddr + ext.numBlocks); newExt.blockAddr = ext.blockAddr + ext.numBlocks; newExt.numBlocks = curIt->blockAddr + curIt->numBlocks - newExt.blockAddr; *curIt = newExt; - } else { // remove the latter part of *curIt + } else { + // + // Remove the end of *curIt by updating its size. + // curIt->numBlocks = ext.blockAddr - curIt->blockAddr; } curIt++; @@ -169,3 +191,115 @@ ExtentManager::DebugPrint() } printf("\n"); } + + +#if UNIT_TEST + +/* +clang++ -arch i386 -arch x86_64 -DUNIT_TEST ExtentManager.cpp -o ExtentManager && ./ExtentManager +*/ + +#include +#include + +const char *DebugDescription(class ExtentManager *extMan) +{ + char *result = strdup(""); + char *temp; + + ListExtIt it; + + for (it = extMan->extentList.begin(); it != extMan->extentList.end(); it++) { + temp = result; + asprintf(&result, "%s[%lld, %lld] ", temp, it->blockAddr, it->numBlocks); + free(temp); + } + + return result; +} + +int SimpleTestCase(off_t addAddr, off_t addBlocks, off_t removeAddr, off_t removeBlocks, const char *expectedResult) +{ + class ExtentManager extMan; + const char *actualResult; + int result = 0; + + extMan.Init(512, 512, 512*999); + extMan.AddBlockRangeExtent(addAddr, addBlocks); + extMan.RemoveBlockRangeExtent(removeAddr, removeBlocks); + actualResult = DebugDescription(&extMan); + if (strcmp(actualResult, expectedResult)) + { + fprintf(stderr, + "SimpleTestCase(%lld, %lld, %lld, %lld) failed.\n" + " Expected result: %s\n" + " Actual result: %s\n", + addAddr, addBlocks, removeAddr, removeBlocks, + expectedResult, actualResult); + result = 1; + } + free((void *)actualResult); + + return result; +} + +int main(void) +{ + int failed = 0; + class ExtentManager *extMan; + + // Create an extent, and remove one contained inside, + // leaving the start and end of the original extent. + // Create: [xxxxxxxxxx] + // Remove: [......] + failed |= SimpleTestCase(10, 10, 12, 6, "[0, 0] [10, 2] [18, 2] [999, 0] "); + + // Create an extent, and remove the whole extent. + // Create: [xxxxxxxxxx] + // Remove: [..........] + failed |= SimpleTestCase(10, 10, 10, 10, "[0, 0] [999, 0] "); + + // Create an extent, and remove the first part of the extent. + // Create: [xxxxxxxxxx] + // Remove: [......] + failed |= SimpleTestCase(10, 10, 10, 6, "[0, 0] [16, 4] [999, 0] "); + + // Create an extent, and remove the last part of the extent. + // Create: [xxxxxxxxxx] + // Remove: [......] + failed |= SimpleTestCase(10, 10, 14, 6, "[0, 0] [10, 4] [999, 0] "); + + // Create an extent and remove before the start, through the middle. + // Create: [xxxxxxxxxx] + // Remove: [..........] + failed |= SimpleTestCase(10, 10, 6, 10, "[0, 0] [16, 4] [999, 0] "); + + // Create an extent and remove from middle to past the end. + // Create: [xxxxxxxxxx] + // Remove: [..........] + failed |= SimpleTestCase(10, 10, 14, 10, "[0, 0] [10, 4] [999, 0] "); + + // Create an extent and remove from before through past end. + // Create: [xxxxxxxxxx] + // Remove: [..............] + failed |= SimpleTestCase(10, 10, 6, 18, "[0, 0] [999, 0] "); + + // Create an extent and remove purely before the extent. + // Create: [xxxxxxxxxx] + // Remove: [...] + failed |= SimpleTestCase(10, 10, 2, 5, "[0, 0] [10, 10] [999, 0] "); + + // Create an extent and remove purely after the extent. + // Create: [xxxxxxxxxx] + // Remove: [...] + failed |= SimpleTestCase(10, 10, 22, 5, "[0, 0] [10, 10] [999, 0] "); + + if (failed) + printf("FAIL!\n"); + else + printf("Success.\n"); + + return failed; +} + +#endif /* UNIT_TEST */ diff --git a/Makefile b/Makefile deleted file mode 100644 index 99b4304..0000000 --- a/Makefile +++ /dev/null @@ -1,123 +0,0 @@ -SHELL := /bin/sh - -VERSION = 1.0 -CC = xcrun cc -CPP = xcrun c++ -CPPFLAGS = -I$(SRCROOT) - -ifneq ($(SDKROOT),) -CFLAGS_SDK = -isysroot $(SDKROOT) -LDFLAGS_SDK = -Wl,-syslibroot,$(SDKROOT) -endif - -CFLAGS = -Os -g3 -no-cpp-precomp -Wall $(RC_CFLAGS) $(CFLAGS_SDK) -LDFLAGS = $(RC_CFLAGS) -install_name /usr/lib/libutil.dylib -compatibility_version $(VERSION) \ - -current_version $(VERSION) -lstdc++ -exported_symbols_list libutil.exports $(LDFLAGS_SDK) -INSTALL = install -c -LN = ln -MKDIR = mkdir -p -STRIP = strip -DSYMUTIL = dsymutil -AR = ar -RANLIB = ranlib - -SRCROOT = . -OBJROOT = $(SRCROOT) -SYMROOT = $(OBJROOT) -DSTROOT = - -LIB := libutil1.0.dylib -SRCS := _secure_path.c getmntopts.c humanize_number.c \ - pidfile.c property.c realhostname.c trimdomain.c uucplock.c \ - ExtentManager.cpp wipefs.cpp reexec_to_match_kernel.c -HDRS := libutil.h mntopts.h wipefs.h -MAN3 := _secure_path.3 getmntopts.3 humanize_number.3 pidfile.3 \ - property.3 realhostname.3 realhostname_sa.3 trimdomain.3 \ - uucplock.3 wipefs.3 reexec_to_match_kernel.3 - -ifeq ($(RC_ProjectName),libutil_Sim) - INSTALL_PREFIX = $(SDKROOT) -else - INSTALL_PREFIX = -endif - - -.SUFFIXES : -.SUFFIXES : .c .cpp .h .o - -.PHONY : -.PHONY : all installsrc installhdrs install clean installlib installman - -all : $(SYMROOT)/$(LIB) - -# -# xbs targets. -# -installsrc : - @if test ! -d $(SRCROOT); then \ - echo "$(INSTALL) -d $(SRCROOT)"; \ - $(INSTALL) -d $(SRCROOT); \ - fi - tar cf - . | (cd $(SRCROOT); tar xpf -) - @for i in `find $(SRCROOT) | grep "/\.svn$$"`; do \ - if test -d $$i ; then \ - echo "rm -rf $$i"; \ - rm -rf $$i; \ - fi; \ - done - -installhdrs : - $(INSTALL) -d $(DSTROOT)$(INSTALL_PREFIX)/usr/local/include - $(INSTALL) -m 0644 $(HDRS) $(DSTROOT)$(INSTALL_PREFIX)/usr/local/include - - -ifeq ($(RC_ProjectName),libutil_Sim) -install : installhdrs installlib strip install-plist -else -install : installhdrs installlib strip installman install-plist -endif - -clean : - rm -f $(patsubst %.cpp,$(OBJROOT)/%.o,$(patsubst %.c,$(OBJROOT)/%.o,$(SRCS))) - rm -f $(SYMROOT)/*~ - rm -f $(SRCROOT)/.\#* - rm -f $(SYMROOT)/$(LIB) - -strip: - $(STRIP) -x -S $(DSTROOT)$(INSTALL_PREFIX)/usr/lib/$(LIB) - -# -# Internal targets and rules. -# -installlib : $(SYMROOT)/$(LIB) - $(DSYMUTIL) $(SYMROOT)/$(LIB) -o $(SYMROOT)/$(LIB).dSYM - $(INSTALL) -d $(DSTROOT)$(INSTALL_PREFIX)/usr/lib - $(INSTALL) -m 0755 $< $(DSTROOT)$(INSTALL_PREFIX)/usr/lib - $(LN) -fs libutil1.0.dylib $(DSTROOT)$(INSTALL_PREFIX)/usr/lib/libutil.dylib - -installman : - $(INSTALL) -d $(DSTROOT)/usr/local/share/man/man3 - @for i in $(MAN3); do\ - echo "$(INSTALL) -m 0444 $(SRCROOT)/$$i $(DSTROOT)/usr/local/share/man/man3/"; \ - $(INSTALL) -m 0444 $(SRCROOT)/$$i $(DSTROOT)/usr/local/share/man/man3; \ - done - -$(OBJROOT)/%.o : $(SRCROOT)/%.c \ - $(patsubst %.h,$(SRCROOT)/%.h,$(HDRS)) - $(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - -$(OBJROOT)/%.o : $(SRCROOT)/%.cpp \ - $(patsubst %.h,$(SRCROOT)/%.h,$(HDRS)) - $(CPP) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - -$(SYMROOT)/$(LIB) : $(patsubst %.cpp,$(OBJROOT)/%.o,$(patsubst %.c,$(OBJROOT)/%.o,$(SRCS))) - $(CC) -dynamiclib $(LDFLAGS) -o $@ $(patsubst %.cpp,$(OBJROOT)/%.o,$(patsubst %.c,$(OBJROOT)/%.o,$(SRCS))) - -OSV = $(DSTROOT)$(INSTALL_PREFIX)/usr/local/OpenSourceVersions -OSL = $(DSTROOT)$(INSTALL_PREFIX)/usr/local/OpenSourceLicenses - -install-plist: - $(MKDIR) $(OSV) - $(INSTALL) -m 644 $(SRCROOT)/libutil.plist $(OSV)/ - $(MKDIR) $(OSL) - $(INSTALL) -m 644 $(SRCROOT)/libutil.txt $(OSL)/ diff --git a/_secure_path.3 b/_secure_path.3 deleted file mode 100644 index 7efb511..0000000 --- a/_secure_path.3 +++ /dev/null @@ -1,75 +0,0 @@ -.\" Copyright (c) 1997 David Nugent -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, is permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice immediately at the beginning of the file, without modification, -.\" 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. This work was done expressly for inclusion into FreeBSD. Other use -.\" is permitted provided this notation is included. -.\" 4. Absolutely no warranty of function or purpose is made by the author -.\" David Nugent. -.\" 5. Modifications may be freely made to this file providing the above -.\" conditions are met. -.\" -.\" $FreeBSD: src/lib/libutil/_secure_path.3,v 1.13 2005/01/20 09:17:07 ru Exp $ -.\" -.Dd May 2, 1997 -.Os -.Dt _SECURE_PATH 3 -.Sh NAME -.Nm _secure_path -.Nd determine if a file appears to be secure -.Sh LIBRARY -.Lb libutil -.Sh SYNOPSIS -.In sys/types.h -.In libutil.h -.Ft int -.Fn _secure_path "const char *path" "uid_t uid" "gid_t gid" -.Sh DESCRIPTION -This function does some basic security checking on a given path. -It is intended to be used by processes running with root privileges -in order to decide whether or not to trust the contents of a given -file. -It uses a method often used to detect system compromise. -.Pp -A file is considered -.Sq secure -if it meets the following conditions: -.Bl -enum -.It -The file exists, and is a regular file (not a symlink, device -special or named pipe, etc.), -.It -Is not world writable. -.It -Is owned by the given uid or uid 0, if uid is not -1, -.It -Is not group writable or it has group ownership by the given -gid, if gid is not -1. -.El -.Sh RETURN VALUES -This function returns zero if the file exists and may be -considered secure, -2 if the file does not exist, and --1 otherwise to indicate a security failure. -The -.Xr syslog 3 -function is used to log any failure of this function, including the -reason, at LOG_ERR priority. -.Sh SEE ALSO -.Xr lstat 2 , -.Xr syslog 3 -.Sh HISTORY -Code from which this function was derived was contributed to the -.Fx -project by Berkeley Software Design, Inc. -.Sh BUGS -The checks carried out are rudimentary and no attempt is made -to eliminate race conditions between use of this function and -access to the file referenced. diff --git a/_secure_path.c b/_secure_path.c deleted file mode 100644 index 69b0c64..0000000 --- a/_secure_path.c +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * Based on code copyright (c) 1995,1997 by - * Berkeley Software Design, Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, is permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice immediately at the beginning of the file, without modification, - * 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. This work was done expressly for inclusion into FreeBSD. Other use - * is permitted provided this notation is included. - * 4. Absolutely no warranty of function or purpose is made by the authors. - * 5. Modifications may be freely made to this file providing the above - * conditions are met. - */ - -#include - -#include -#include - -#include -#include -#include -#include - -/* - * Check for common security problems on a given path - * It must be: - * 1. A regular file, and exists - * 2. Owned and writable only by root (or given owner) - * 3. Group ownership is given group or is non-group writable - * - * Returns: -2 if file does not exist, - * -1 if security test failure - * 0 otherwise - */ - -int -_secure_path(const char *path, uid_t uid, gid_t gid) -{ - int r = -1; - struct stat sb; - const char *msg = NULL; - - if (lstat(path, &sb) < 0) { - if (errno == ENOENT) /* special case */ - r = -2; /* if it is just missing, skip the log entry */ - else - msg = "%s: cannot stat %s: %m"; - } - else if (!S_ISREG(sb.st_mode)) - msg = "%s: %s is not a regular file"; - else if (sb.st_mode & S_IWOTH) - msg = "%s: %s is world writable"; - else if ((int)uid != -1 && sb.st_uid != uid && sb.st_uid != 0) { - if (uid == 0) - msg = "%s: %s is not owned by root"; - else - msg = "%s: %s is not owned by uid %d"; - } else if ((int)gid != -1 && sb.st_gid != gid && (sb.st_mode & S_IWGRP)) - msg = "%s: %s is group writeable by non-authorised groups"; - else - r = 0; - if (msg != NULL) - syslog(LOG_ERR, msg, "_secure_path", path, uid); - return r; -} diff --git a/getmntopts.3 b/getmntopts.3 index dde6fe4..c421b5e 100644 --- a/getmntopts.3 +++ b/getmntopts.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: getmntopts.3,v 1.7 2004/02/24 15:12:51 wiz Exp $ +.\" $NetBSD: getmntopts.3,v 1.12 2010/08/24 12:05:01 christos Exp $ .\" .\" Copyright (c) 1994 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getmntopts.3 8.3 (Berkeley) 3/30/95 .\" -.Dd April 11, 2003 +.Dd May 4, 2010 .Dt GETMNTOPTS 3 .Os .Sh NAME @@ -51,7 +51,7 @@ The .Fn getmntopts function takes a comma separated option list and a list -of valid option names, and computes the bitmask +of valid option names, and computes the bitmasks corresponding to the requested set of options. .Pp The string @@ -76,9 +76,9 @@ has the following format: .Bd -literal struct mntopt { const char *m_option; /* option name */ - int m_inverse; /* is this a negative option, e.g., "dev" */ + int m_inverse; /* negative option, e.g., "dev" */ int m_flag; /* bit to set, e.g., MNT_RDONLY */ - int m_altloc; /* non-zero to use altflagp rather than flagp */ + int m_altloc; /* use altflagp rather than flagp */ }; .Ed .Pp @@ -127,7 +127,26 @@ entry. To simplify the program interface and ensure consistency across all programs, a general purpose macro, .Dv MOPT_STDOPTS , -is defined which contains an entry for all the generic VFS options. +is defined which contains an entry for all the generic VFS options: +.Bd -literal -offset indent +MOPT_USERQUOTA, +MOPT_GROUPQUOTA, +MOPT_FSTAB_COMPAT, +MOPT_NODEV, +MOPT_NOEXEC, +MOPT_NOSUID, +MOPT_RDONLY, +MOPT_UNION, +MOPT_BROWSE, +MOPT_AUTOMOUNTED, +MOPT_DEFWRITE, +MOPT_NOATIME, +MOPT_PERMISSIONS, +MOPT_IGNORE_OWNERSHIP, +MOPT_QUARANTINE, +MOPT_CPROTECT +.Ed +.Pp In addition, the macros .Dv MOPT_FORCE and @@ -141,22 +160,82 @@ Finally, the table must be terminated by an entry with a .Dv NULL first element. .Pp +.Fn getmntopts +returns a +.Li "mntoptparse_t" +handle that can be used in subsequent +.Fn getmntoptstr +and +.Fn getmntoptnum +calls to fetch a value for an option and that must be freed with a call +to +.Fn freemntopts . +If an error occurred, then if the external integer value +.Va getmnt_silent +is zero then +.Fn getmntopts +prints an error message and exits; +if +.Va getmnt_silent +is non-zero then +.Fn getmntopts +returns +.Dv NULL . +.Pp The .Fn getmntoptstr function returns the string value of the named option, if such a value -was set it the option string. +was set in the option string. +If the value was not set, then if the external integer value +.Va getmnt_silent +is zero then +.Fn getmntoptstr +prints an error message and exits; +if +.Va getmnt_silent +is non-zero then +.Fn getmntoptstr +returns +.Dv NULL . .Pp The .Fn getmntoptnum -returns the long value of the named option, if such a value was set it the +returns the long value of the named option, if such a value was set in the option string. -It prints an error message and exits if the value was not -set, or could not be converted from a string to a long. +If the value was not set, or could not be converted from a string to a +long, then if the external integer value +.Va getmnt_silent +is zero then +.Fn getmntoptnum +prints an error message and exits; +if +.Va getmnt_silent +is non-zero then +.Fn getmntoptnum +returns \-1. .Pp The .Fn freemntopts frees the storage used by .Fn getmntopts . +.Sh RETURN VALUES +.Fn getmntopts +returns +.Dv NULL +if an error occurred. +Note that some bits may already have been set in +.Va flagp +and +.Va altflagp +even if +.Dv NULL +is returned. +.Fn getmntoptstr +returns +.Dv NULL +if an error occurred. +.Fn getmntoptnum +returns \-1 if an error occurred. .Sh EXAMPLES Most commands will use the standard option set. Local filesystems which support the @@ -165,7 +244,7 @@ flag, would also have an .Dv MOPT_UPDATE entry. This can be declared and used as follows: -.Bd -literal +.Bd -literal -offset indent #include \*[Lt]mntopts.h\*[Gt] static const struct mntopt mopts[] = { @@ -174,37 +253,33 @@ static const struct mntopt mopts[] = { { NULL } }; -... +\&... + long val; -mntflags = mntaltflags = 0; mntoptparse_t mp; -... -if ((mp = getmntopts(options, mopts, \*[Am]mntflags, \*[Am]mntaltflags)) == NULL) - err(1, NULL); -... +mntflags = mntaltflags = 0; + +\&... + +mp = getmntopts(options, mopts, \*[Am]mntflags, \*[Am]mntaltflags); + +if (mp == NULL) + err(EXIT_FAILURE, "getmntopts"); + +\&... + val = getmntoptnum(mp, "rsize"); freemntopts(mp); .Ed -.Sh RETURN VALUE -.Fn getmntopts -returns -.Dv NULL -if an error occurred. -.Fn getmntoptstr -returns -.Dv NULL -if the option does not have an argument, or the option string. -.Fn getmntoptnum -returns \-1 if an error occurred and -.Va getmnt_silent -is set. .Sh DIAGNOSTICS If the external integer variable .Va getmnt_silent -is non-zero then the -.Fn getmntopts -function displays an error message and exits if an -unrecognized option is encountered. +is zero then the +.Fn getmntopts , +.Fn getmntoptstr , +and +.Fn getmntoptnum +functions display an error message and exit if an error occurred. By default .Va getmnt_silent is zero. diff --git a/libutil.exports b/libutil.exports index 36dc4a4..5ca39d9 100644 --- a/libutil.exports +++ b/libutil.exports @@ -1,4 +1,3 @@ -__secure_path _freemntopts _getmnt_silent _getmntoptnum @@ -9,19 +8,12 @@ _pidfile_close _pidfile_open _pidfile_remove _pidfile_write -_properties_free -_properties_read -_property_find _realhostname _realhostname_sa _reexec_to_match_kernel _reexec_to_match_lp64ness -_trimdomain -_uu_lock -_uu_lock_txfr -_uu_lockerr -_uu_unlock _wipefs_alloc _wipefs_except_blocks _wipefs_free +_wipefs_include_blocks _wipefs_wipe diff --git a/libutil.h b/libutil.h index 0a5949a..16a935f 100644 --- a/libutil.h +++ b/libutil.h @@ -42,16 +42,6 @@ #include #include -#define PROPERTY_MAX_NAME 64 -#define PROPERTY_MAX_VALUE 512 - -/* for properties.c */ -typedef struct _property { - struct _property *next; - char *name; - char *value; -} *properties; - #ifdef _SYS_PARAM_H_ /* for pidfile.c */ struct pidfh { @@ -62,61 +52,17 @@ struct pidfh { }; #endif -/* Avoid pulling in all the include files for no need */ -struct termios; -struct winsize; -struct utmp; struct in_addr; +struct sockaddr; __BEGIN_DECLS -void clean_environment(const char * const *_white, - const char * const *_more_white); -int extattr_namespace_to_string(int _attrnamespace, char **_string); -int extattr_string_to_namespace(const char *_string, int *_attrnamespace); -void login(struct utmp *_ut); -int login_tty(int _fd); -int logout(const char *_line); -void logwtmp(const char *_line, const char *_name, const char *_host); -void trimdomain(char *_fullhost, int _hostsize); -int openpty(int *_amaster, int *_aslave, char *_name, - struct termios *_termp, struct winsize *_winp); -int forkpty(int *_amaster, char *_name, - struct termios *_termp, struct winsize *_winp); int humanize_number(char *_buf, size_t _len, int64_t _number, const char *_suffix, int _scale, int _flags); -const char *uu_lockerr(int _uu_lockresult); -int uu_lock(const char *_ttyname); -int uu_unlock(const char *_ttyname); -int uu_lock_txfr(const char *_ttyname, pid_t _pid); -int _secure_path(const char *_path, uid_t _uid, gid_t _gid); -properties properties_read(int fd); -void properties_free(properties list); -char *property_find(properties list, const char *name); -char *auth_getval(const char *name); + int realhostname(char *host, size_t hsize, const struct in_addr *ip); -struct sockaddr; int realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen); -#ifdef _STDIO_H_ /* avoid adding new includes */ -char *fparseln(FILE *, size_t *, size_t *, const char[3], int); -#endif - -#ifdef _PWD_H_ -int pw_copy(int _ffd, int _tfd, const struct passwd *_pw, struct passwd *_old_pw); -struct passwd *pw_dup(const struct passwd *_pw); -int pw_edit(int _notsetuid); -int pw_equal(const struct passwd *_pw1, const struct passwd *_pw2); -void pw_fini(void); -int pw_init(const char *_dir, const char *_master); -char *pw_make(const struct passwd *_pw); -int pw_mkdb(const char *_user); -int pw_lock(void); -struct passwd *pw_scan(const char *_line, int _flags); -const char *pw_tempname(void); -int pw_tmp(int _mfd); -#endif - #ifdef _SYS_PARAM_H_ struct pidfh *pidfile_open(const char *path, mode_t mode, pid_t *pidptr); int pidfile_write(struct pidfh *pfh); @@ -129,33 +75,12 @@ int reexec_to_match_lp64ness(bool isLP64); __END_DECLS -#define UU_LOCK_INUSE (1) -#define UU_LOCK_OK (0) -#define UU_LOCK_OPEN_ERR (-1) -#define UU_LOCK_READ_ERR (-2) -#define UU_LOCK_CREAT_ERR (-3) -#define UU_LOCK_WRITE_ERR (-4) -#define UU_LOCK_LINK_ERR (-5) -#define UU_LOCK_TRY_ERR (-6) -#define UU_LOCK_OWNER_ERR (-7) - /* return values from realhostname() */ #define HOSTNAME_FOUND (0) #define HOSTNAME_INCORRECTNAME (1) #define HOSTNAME_INVALIDADDR (2) #define HOSTNAME_INVALIDNAME (3) -/* fparseln(3) */ -#define FPARSELN_UNESCESC 0x01 -#define FPARSELN_UNESCCONT 0x02 -#define FPARSELN_UNESCCOMM 0x04 -#define FPARSELN_UNESCREST 0x08 -#define FPARSELN_UNESCALL 0x0f - -/* pw_scan() */ -#define PWSCAN_MASTER 0x01 -#define PWSCAN_WARN 0x02 - /* humanize_number(3) */ #define HN_DECIMAL 0x01 #define HN_NOSPACE 0x02 diff --git a/libutil.plist b/libutil.plist index 43785e7..8633e1c 100644 --- a/libutil.plist +++ b/libutil.plist @@ -3,7 +3,7 @@ - OpenSourceCVS + OpenSourceSCM cvs -d freebsdanoncvs@anoncvs.FreeBSD.org:/home/ncvs co libutil OpenSourceImportDate 2006-05-20 @@ -15,8 +15,6 @@ libutil OpenSourceVersion 2005-02-13 - OpenSourceWebsiteURL - http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libutil/ OpenSourceImportDate @@ -29,7 +27,7 @@ libutil OpenSourceVersion 1.3 - OpenSourceWebsiteURL + OpenSourceURL http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/lib/libutil/getmntopts.c?rev=1.3 diff --git a/libutil.xcodeproj/project.pbxproj b/libutil.xcodeproj/project.pbxproj new file mode 100644 index 0000000..cec162a --- /dev/null +++ b/libutil.xcodeproj/project.pbxproj @@ -0,0 +1,355 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + BA79F9CB13BB7207006A292D /* ExtentManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9A313BB70FF006A292D /* ExtentManager.cpp */; }; + BA79F9CC13BB7207006A292D /* getmntopts.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9A613BB70FF006A292D /* getmntopts.c */; }; + BA79F9CD13BB7207006A292D /* humanize_number.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9A813BB70FF006A292D /* humanize_number.c */; }; + BA79F9CE13BB7207006A292D /* pidfile.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9B013BB70FF006A292D /* pidfile.c */; }; + BA79F9D013BB7207006A292D /* realhostname.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9B513BB70FF006A292D /* realhostname.c */; }; + BA79F9D113BB7207006A292D /* reexec_to_match_kernel.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9B713BB70FF006A292D /* reexec_to_match_kernel.c */; }; + BA79F9D213BB7207006A292D /* trimdomain.c in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9B913BB70FF006A292D /* trimdomain.c */; }; + BA79F9D413BB7207006A292D /* wipefs.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BA79F9BD13BB70FF006A292D /* wipefs.cpp */; }; + BA79F9D513BB7235006A292D /* libutil.h in Headers */ = {isa = PBXBuildFile; fileRef = BA79F9AA13BB70FF006A292D /* libutil.h */; settings = {ATTRIBUTES = (Private, ); }; }; + BA79F9D613BB7235006A292D /* mntopts.h in Headers */ = {isa = PBXBuildFile; fileRef = BA79F9AE13BB70FF006A292D /* mntopts.h */; settings = {ATTRIBUTES = (Private, ); }; }; + BA79F9D713BB7235006A292D /* wipefs.h in Headers */ = {isa = PBXBuildFile; fileRef = BA79F9BE13BB70FF006A292D /* wipefs.h */; settings = {ATTRIBUTES = (Private, ); }; }; + BA79F9D813BB7243006A292D /* ExtentManager.h in Headers */ = {isa = PBXBuildFile; fileRef = BA79F9A413BB70FF006A292D /* ExtentManager.h */; }; + BA79F9DD13BB76B0006A292D /* getmntopts.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9A513BB70FF006A292D /* getmntopts.3 */; }; + BA79F9DE13BB76B0006A292D /* humanize_number.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9A713BB70FF006A292D /* humanize_number.3 */; }; + BA79F9DF13BB76B0006A292D /* pidfile.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9AF13BB70FF006A292D /* pidfile.3 */; }; + BA79F9E113BB76B0006A292D /* realhostname_sa.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9B313BB70FF006A292D /* realhostname_sa.3 */; }; + BA79F9E213BB76B0006A292D /* realhostname.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9B413BB70FF006A292D /* realhostname.3 */; }; + BA79F9E313BB76B0006A292D /* reexec_to_match_kernel.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9B613BB70FF006A292D /* reexec_to_match_kernel.3 */; }; + BA79F9E413BB76B0006A292D /* trimdomain.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9B813BB70FF006A292D /* trimdomain.3 */; }; + BA79F9E613BB76B0006A292D /* wipefs.3 in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9BC13BB70FF006A292D /* wipefs.3 */; }; + BA79F9E913BB77FA006A292D /* libutil.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9AB13BB70FF006A292D /* libutil.plist */; }; + BA79F9EA13BB77FF006A292D /* libutil.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = BA79F9AC13BB70FF006A292D /* libutil.txt */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + BA79F9DB13BB7698006A292D /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 8; + dstPath = "$(INSTALL_PREFIX)/usr/local/share/man/man3"; + dstSubfolderSpec = 0; + files = ( + BA79F9DD13BB76B0006A292D /* getmntopts.3 in CopyFiles */, + BA79F9DE13BB76B0006A292D /* humanize_number.3 in CopyFiles */, + BA79F9DF13BB76B0006A292D /* pidfile.3 in CopyFiles */, + BA79F9E113BB76B0006A292D /* realhostname_sa.3 in CopyFiles */, + BA79F9E213BB76B0006A292D /* realhostname.3 in CopyFiles */, + BA79F9E313BB76B0006A292D /* reexec_to_match_kernel.3 in CopyFiles */, + BA79F9E413BB76B0006A292D /* trimdomain.3 in CopyFiles */, + BA79F9E613BB76B0006A292D /* wipefs.3 in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 1; + }; + BA79F9E713BB77BB006A292D /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 8; + dstPath = "$(INSTALL_PREFIX)/usr/local/OpenSourceVersions"; + dstSubfolderSpec = 0; + files = ( + BA79F9E913BB77FA006A292D /* libutil.plist in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 1; + }; + BA79F9E813BB77D6006A292D /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 8; + dstPath = "$(INSTALL_PREFIX)/usr/local/OpenSourceLicenses"; + dstSubfolderSpec = 0; + files = ( + BA79F9EA13BB77FF006A292D /* libutil.txt in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + BA79F9A313BB70FF006A292D /* ExtentManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ExtentManager.cpp; sourceTree = ""; }; + BA79F9A413BB70FF006A292D /* ExtentManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExtentManager.h; sourceTree = ""; }; + BA79F9A513BB70FF006A292D /* getmntopts.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = getmntopts.3; sourceTree = ""; }; + BA79F9A613BB70FF006A292D /* getmntopts.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = getmntopts.c; sourceTree = ""; }; + BA79F9A713BB70FF006A292D /* humanize_number.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = humanize_number.3; sourceTree = ""; }; + BA79F9A813BB70FF006A292D /* humanize_number.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = humanize_number.c; sourceTree = ""; }; + BA79F9A913BB70FF006A292D /* libutil.exports */ = {isa = PBXFileReference; lastKnownFileType = text; path = libutil.exports; sourceTree = ""; }; + BA79F9AA13BB70FF006A292D /* libutil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = libutil.h; sourceTree = ""; }; + BA79F9AB13BB70FF006A292D /* libutil.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = libutil.plist; sourceTree = ""; }; + BA79F9AC13BB70FF006A292D /* libutil.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = libutil.txt; sourceTree = ""; }; + BA79F9AD13BB70FF006A292D /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = ""; }; + BA79F9AE13BB70FF006A292D /* mntopts.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = mntopts.h; sourceTree = ""; }; + BA79F9AF13BB70FF006A292D /* pidfile.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = pidfile.3; sourceTree = ""; }; + BA79F9B013BB70FF006A292D /* pidfile.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = pidfile.c; sourceTree = ""; }; + BA79F9B313BB70FF006A292D /* realhostname_sa.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = realhostname_sa.3; sourceTree = ""; }; + BA79F9B413BB70FF006A292D /* realhostname.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = realhostname.3; sourceTree = ""; }; + BA79F9B513BB70FF006A292D /* realhostname.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = realhostname.c; sourceTree = ""; }; + BA79F9B613BB70FF006A292D /* reexec_to_match_kernel.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = reexec_to_match_kernel.3; sourceTree = ""; }; + BA79F9B713BB70FF006A292D /* reexec_to_match_kernel.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = reexec_to_match_kernel.c; sourceTree = ""; }; + BA79F9B813BB70FF006A292D /* trimdomain.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = trimdomain.3; sourceTree = ""; }; + BA79F9B913BB70FF006A292D /* trimdomain.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = trimdomain.c; sourceTree = ""; }; + BA79F9BC13BB70FF006A292D /* wipefs.3 */ = {isa = PBXFileReference; lastKnownFileType = text; path = wipefs.3; sourceTree = ""; }; + BA79F9BD13BB70FF006A292D /* wipefs.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = wipefs.cpp; sourceTree = ""; }; + BA79F9BE13BB70FF006A292D /* wipefs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = wipefs.h; sourceTree = ""; }; + BA79F9C013BB712E006A292D /* BSD.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = BSD.xcconfig; path = Makefiles/CoreOS/Xcode/BSD.xcconfig; sourceTree = DEVELOPER_DIR; }; + BA79F9C513BB718B006A292D /* libutil1.0.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libutil1.0.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + BA79F9C213BB718B006A292D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + BA79F99513BB70D7006A292D = { + isa = PBXGroup; + children = ( + BA79F9C013BB712E006A292D /* BSD.xcconfig */, + BA79F9A313BB70FF006A292D /* ExtentManager.cpp */, + BA79F9A413BB70FF006A292D /* ExtentManager.h */, + BA79F9A513BB70FF006A292D /* getmntopts.3 */, + BA79F9A613BB70FF006A292D /* getmntopts.c */, + BA79F9A713BB70FF006A292D /* humanize_number.3 */, + BA79F9A813BB70FF006A292D /* humanize_number.c */, + BA79F9A913BB70FF006A292D /* libutil.exports */, + BA79F9AA13BB70FF006A292D /* libutil.h */, + BA79F9AB13BB70FF006A292D /* libutil.plist */, + BA79F9AC13BB70FF006A292D /* libutil.txt */, + BA79F9AD13BB70FF006A292D /* Makefile */, + BA79F9AE13BB70FF006A292D /* mntopts.h */, + BA79F9AF13BB70FF006A292D /* pidfile.3 */, + BA79F9B013BB70FF006A292D /* pidfile.c */, + BA79F9B313BB70FF006A292D /* realhostname_sa.3 */, + BA79F9B413BB70FF006A292D /* realhostname.3 */, + BA79F9B513BB70FF006A292D /* realhostname.c */, + BA79F9B613BB70FF006A292D /* reexec_to_match_kernel.3 */, + BA79F9B713BB70FF006A292D /* reexec_to_match_kernel.c */, + BA79F9B813BB70FF006A292D /* trimdomain.3 */, + BA79F9B913BB70FF006A292D /* trimdomain.c */, + BA79F9BC13BB70FF006A292D /* wipefs.3 */, + BA79F9BD13BB70FF006A292D /* wipefs.cpp */, + BA79F9BE13BB70FF006A292D /* wipefs.h */, + BA79F9C613BB718B006A292D /* Products */, + ); + sourceTree = ""; + }; + BA79F9C613BB718B006A292D /* Products */ = { + isa = PBXGroup; + children = ( + BA79F9C513BB718B006A292D /* libutil1.0.dylib */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + BA79F9C313BB718B006A292D /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + BA79F9D513BB7235006A292D /* libutil.h in Headers */, + BA79F9D613BB7235006A292D /* mntopts.h in Headers */, + BA79F9D713BB7235006A292D /* wipefs.h in Headers */, + BA79F9D813BB7243006A292D /* ExtentManager.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + BA79F9C413BB718B006A292D /* util */ = { + isa = PBXNativeTarget; + buildConfigurationList = BA79F9C713BB718B006A292D /* Build configuration list for PBXNativeTarget "util" */; + buildPhases = ( + BA79F9C113BB718B006A292D /* Sources */, + BA79F9C213BB718B006A292D /* Frameworks */, + BA79F9C313BB718B006A292D /* Headers */, + BA79F9DA13BB750E006A292D /* ShellScript */, + BA79F9EB13BB7864006A292D /* ShellScript */, + BA79F9DB13BB7698006A292D /* CopyFiles */, + BA79F9E713BB77BB006A292D /* CopyFiles */, + BA79F9E813BB77D6006A292D /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = util; + productName = util; + productReference = BA79F9C513BB718B006A292D /* libutil1.0.dylib */; + productType = "com.apple.product-type.library.dynamic"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + BA79F99713BB70D7006A292D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0420; + }; + buildConfigurationList = BA79F99A13BB70D7006A292D /* Build configuration list for PBXProject "libutil" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = BA79F99513BB70D7006A292D; + productRefGroup = BA79F9C613BB718B006A292D /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + BA79F9C413BB718B006A292D /* util */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXShellScriptBuildPhase section */ + BA79F9DA13BB750E006A292D /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + "$(BUILT_PRODUCTS_DIR)/libutil.dylib", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "set -e\nset -x\n\nln -sf libutil1.0.dylib \"${BUILT_PRODUCTS_DIR}/libutil.dylib\"\n"; + }; + BA79F9EB13BB7864006A292D /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 8; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + "$(DSTROOT)/$(INSTALL_PREFIX)/usr/lib/libutil.dylib", + ); + runOnlyForDeploymentPostprocessing = 1; + shellPath = /bin/sh; + shellScript = "set -e\nset -x\n\nln -sf libutil1.0.dylib \"${DSTROOT}/${INSTALL_PREFIX}/usr/lib/libutil.dylib\"\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + BA79F9C113BB718B006A292D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + BA79F9CB13BB7207006A292D /* ExtentManager.cpp in Sources */, + BA79F9CC13BB7207006A292D /* getmntopts.c in Sources */, + BA79F9CD13BB7207006A292D /* humanize_number.c in Sources */, + BA79F9CE13BB7207006A292D /* pidfile.c in Sources */, + BA79F9D013BB7207006A292D /* realhostname.c in Sources */, + BA79F9D113BB7207006A292D /* reexec_to_match_kernel.c in Sources */, + BA79F9D213BB7207006A292D /* trimdomain.c in Sources */, + BA79F9D413BB7207006A292D /* wipefs.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + BA79F99C13BB70D7006A292D /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = BA79F9C013BB712E006A292D /* BSD.xcconfig */; + buildSettings = { + }; + name = Debug; + }; + BA79F99D13BB70D7006A292D /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = BA79F9C013BB712E006A292D /* BSD.xcconfig */; + buildSettings = { + }; + name = Release; + }; + BA79F9C813BB718B006A292D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + DYLIB_COMPATIBILITY_VERSION = 1.0; + DYLIB_CURRENT_VERSION = 1.0; + EXECUTABLE_PREFIX = lib; + EXPORTED_SYMBOLS_FILE = libutil.exports; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INSTALL_PATH = "$(INSTALL_PREFIX)/usr/lib"; + INSTALL_PREFIX = "$(INSTALL_PREFIX_$(PLATFORM_NAME))"; + INSTALL_PREFIX_iphonesimulator = "$(SDKROOT)"; + LD_DYLIB_INSTALL_NAME = /usr/lib/libutil.dylib; + PRIVATE_HEADERS_FOLDER_PATH = "$(INSTALL_PREFIX)/usr/local/include"; + PRODUCT_NAME = "$(TARGET_NAME)1.0"; + WARNING_CFLAGS = "-Wall"; + }; + name = Debug; + }; + BA79F9C913BB718B006A292D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ARCHS = "$(ARCHS_STANDARD_32_64_BIT)"; + DYLIB_COMPATIBILITY_VERSION = 1.0; + DYLIB_CURRENT_VERSION = 1.0; + EXECUTABLE_PREFIX = lib; + EXPORTED_SYMBOLS_FILE = libutil.exports; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + INSTALL_PATH = "$(INSTALL_PREFIX)/usr/lib"; + INSTALL_PREFIX = "$(INSTALL_PREFIX_$(PLATFORM_NAME))"; + INSTALL_PREFIX_iphonesimulator = "$(SDKROOT)"; + LD_DYLIB_INSTALL_NAME = /usr/lib/libutil.dylib; + PRIVATE_HEADERS_FOLDER_PATH = "$(INSTALL_PREFIX)/usr/local/include"; + PRODUCT_NAME = "$(TARGET_NAME)1.0"; + WARNING_CFLAGS = "-Wall"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + BA79F99A13BB70D7006A292D /* Build configuration list for PBXProject "libutil" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BA79F99C13BB70D7006A292D /* Debug */, + BA79F99D13BB70D7006A292D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + BA79F9C713BB718B006A292D /* Build configuration list for PBXNativeTarget "util" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BA79F9C813BB718B006A292D /* Debug */, + BA79F9C913BB718B006A292D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = BA79F99713BB70D7006A292D /* Project object */; +} diff --git a/libutil.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/libutil.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..2b32232 --- /dev/null +++ b/libutil.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/property.3 b/property.3 deleted file mode 100644 index 79c787d..0000000 --- a/property.3 +++ /dev/null @@ -1,99 +0,0 @@ -.\" -.\" Copyright (c) 1998 Jordan Hubbard -.\" -.\" 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 DEVELOPERS ``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 DEVELOPERS 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: src/lib/libutil/property.3,v 1.18 2005/01/20 09:17:07 ru Exp $ -.\" " -.Dd October 7, 1998 -.Os -.Dt PROPERTIES 3 -.Sh NAME -.Nm properties_read , -.Nm propery_find , -.Nm properties_free -.Nd "functions to allow creating simple property lists from ASCII file data" -.Sh LIBRARY -.Lb libutil -.Sh SYNOPSIS -.In sys/types.h -.In libutil.h -.Ft properties -.Fn properties_read "int fd" -.Ft char * -.Fn property_find "properties list" "const char *name" -.Ft void -.Fn properties_free "properties list" -.Sh DESCRIPTION -.Bd -literal -typedef struct _properties { - struct _properties *next; - char *name; - char *value; -} *properties; -.Ed -.Pp -The function -.Fn properties_read -reads -.Fa name = value -pairs from the file descriptor passed in -.Fa fd -and returns the head of a new property list, assuming that the -file's contents have been parsed properly, or NULL in case -of error. -.Pp -The -.Fn property_find -function returns the associated value string for the property named -.Fa name -if found, otherwise NULL. -The value returned may be up to -.Dv PROPERTY_MAX_VALUE -bytes in length. -.Pp -The -.Fn properties_free -function is used to free the structure returned by -.Fn properties_read -when it is no longer needed. -.Sh FILE FORMAT -Each property in the file is assumed to have the format of -.Fa name = value -where -.Fa name -is an alphanumeric string (and any punctuation not including the `=' character) -and -.Fa value -is an arbitary string of text terminated by a newline character. -If newlines -are desired, the entire value should be enclosed in { } (curly-bracket) -characters. -Any line beginning with a # or ; character is assumed to -be a comment and will be ignored. -.Sh SEE ALSO -.Xr auth_getval 3 -.Sh AUTHORS -.An Jordan Hubbard -.Sh BUGS -Simplistic. diff --git a/property.c b/property.c deleted file mode 100644 index 6d1b7f7..0000000 --- a/property.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * - * Simple property list handling code. - * - * Copyright (c) 1998 - * Jordan "Perky" Hubbard. 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, - * verbatim and that no modifications are made prior to this - * point in the file. - * 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 ``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 HIS PETS 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, LIFE 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 -#include -#include -#include -#include -#include -#include -#include -#include - -static properties -property_alloc(char *name, char *value) -{ - properties n; - - if ((n = (properties)malloc(sizeof(struct _property))) == NULL) - return (NULL); - n->next = NULL; - if (name != NULL) { - if ((n->name = strdup(name)) == NULL) { - free(n); - return (NULL); - } - } else - n->name = NULL; - if (value != NULL) { - if ((n->value = strdup(value)) == NULL) { - free(n->name); - free(n); - return (NULL); - } - } else - n->value = NULL; - return (n); -} - -properties -properties_read(int fd) -{ - properties head, ptr; - char hold_n[PROPERTY_MAX_NAME + 1]; - char hold_v[PROPERTY_MAX_VALUE + 1]; - char buf[BUFSIZ * 4]; - int bp, n, v, max; - enum { LOOK, COMMENT, NAME, VALUE, MVALUE, COMMIT, FILL, STOP } state, last_state; - int ch = 0, blevel = 0; - - n = v = bp = max = 0; - head = ptr = NULL; - state = last_state = LOOK; - while (state != STOP) { - if (state != COMMIT) { - if (bp == max) { - last_state = state; - state = FILL; - } else - ch = buf[bp++]; - } - switch(state) { - case FILL: - if ((max = read(fd, buf, sizeof buf)) < 0) { - properties_free(head); - return (NULL); - } - if (max == 0) { - state = STOP; - } else { - /* - * Restore the state from before the fill (which will be - * initialised to LOOK for the first FILL). This ensures that - * if we were part-way through eg., a VALUE state, when the - * buffer ran out, that the previous operation will be allowed - * to complete. - */ - state = last_state; - ch = buf[0]; - bp = 0; - } - continue; - - case LOOK: - if (isspace((unsigned char)ch)) - continue; - /* Allow shell or lisp style comments */ - else if (ch == '#' || ch == ';') { - state = COMMENT; - continue; - } - else if (isalnum((unsigned char)ch) || ch == '_') { - if (n >= PROPERTY_MAX_NAME) { - n = 0; - state = COMMENT; - } - else { - hold_n[n++] = ch; - state = NAME; - } - } - else - state = COMMENT; /* Ignore the rest of the line */ - break; - - case COMMENT: - if (ch == '\n') - state = LOOK; - break; - - case NAME: - if (ch == '\n' || !ch) { - hold_n[n] = '\0'; - hold_v[0] = '\0'; - v = n = 0; - state = COMMIT; - } - else if (isspace((unsigned char)ch)) - continue; - else if (ch == '=') { - hold_n[n] = '\0'; - v = n = 0; - state = VALUE; - } - else - hold_n[n++] = ch; - break; - - case VALUE: - if (v == 0 && ch == '\n') { - hold_v[v] = '\0'; - v = n = 0; - state = COMMIT; - } - else if (v == 0 && isspace((unsigned char)ch)) - continue; - else if (ch == '{') { - state = MVALUE; - ++blevel; - } - else if (ch == '\n' || !ch) { - hold_v[v] = '\0'; - v = n = 0; - state = COMMIT; - } - else { - if (v >= PROPERTY_MAX_VALUE) { - state = COMMENT; - v = n = 0; - break; - } - else - hold_v[v++] = ch; - } - break; - - case MVALUE: - /* multiline value */ - if (v >= PROPERTY_MAX_VALUE) { - warn("properties_read: value exceeds max length"); - state = COMMENT; - n = v = 0; - } - else if (ch == '}' && !--blevel) { - hold_v[v] = '\0'; - v = n = 0; - state = COMMIT; - } - else { - hold_v[v++] = ch; - if (ch == '{') - ++blevel; - } - break; - - case COMMIT: - if (head == NULL) { - if ((head = ptr = property_alloc(hold_n, hold_v)) == NULL) - return (NULL); - } else { - if ((ptr->next = property_alloc(hold_n, hold_v)) == NULL) { - properties_free(head); - return (NULL); - } - ptr = ptr->next; - } - state = LOOK; - v = n = 0; - break; - - case STOP: - /* we don't handle this here, but this prevents warnings */ - break; - } - } - if (head == NULL && (head = property_alloc(NULL, NULL)) == NULL) - return (NULL); - - return (head); -} - -char * -property_find(properties list, const char *name) -{ - if (list == NULL || name == NULL || !name[0]) - return (NULL); - while (list != NULL) { - if (list->name != NULL && strcmp(list->name, name) == 0) - return (list->value); - list = list->next; - } - return (NULL); -} - -void -properties_free(properties list) -{ - properties tmp; - - while (list) { - tmp = list->next; - if (list->name) - free(list->name); - if (list->value) - free(list->value); - free(list); - list = tmp; - } -} diff --git a/realhostname.c b/realhostname.c index 57bc651..fad7838 100644 --- a/realhostname.c +++ b/realhostname.c @@ -44,6 +44,8 @@ struct sockinet { u_short si_port; }; +void trimdomain(char *_fullhost, size_t _hostsize); + int realhostname(char *host, size_t hsize, const struct in_addr *ip) { diff --git a/trimdomain.c b/trimdomain.c index 6287e84..3c4c20a 100644 --- a/trimdomain.c +++ b/trimdomain.c @@ -34,6 +34,8 @@ #include #include +void trimdomain(char *_fullhost, size_t _hostsize); + static int isDISP(const char *); /*- @@ -50,7 +52,7 @@ static int isDISP(const char *); * trimdomain("abcde.my.domain:0.0", 8) -> "abcde.my.domain:0.0" */ void -trimdomain(char *fullhost, int hostsize) +trimdomain(char *fullhost, size_t hostsize) { static size_t dlen; static int first = 1; @@ -73,7 +75,7 @@ trimdomain(char *fullhost, int hostsize) return; s = fullhost; - end = s + hostsize + 1; + end = (char *)((uintptr_t)s + hostsize + 1); if ((s = memchr(s, '.', (size_t)(end - s))) != NULL) { if (strncasecmp(s + 1, domain, dlen) == 0) { if (s[dlen + 1] == '\0') { diff --git a/uucplock.3 b/uucplock.3 deleted file mode 100644 index 7ed6bcb..0000000 --- a/uucplock.3 +++ /dev/null @@ -1,183 +0,0 @@ -.\" -.\" Copyright (c) 1996 Brian Somers -.\" -.\" 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 DEVELOPERS ``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 DEVELOPERS 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: src/lib/libutil/uucplock.3,v 1.19 2005/02/13 22:25:14 ru Exp $ -.\" " -.Dd March 30, 1997 -.Os -.Dt UUCPLOCK 3 -.Sh NAME -.Nm uu_lock , -.Nm uu_unlock , -.Nm uu_lockerr -.Nd acquire and release control of a serial device -.Sh LIBRARY -.Lb libutil -.Sh SYNOPSIS -.In sys/types.h -.In libutil.h -.Ft int -.Fn uu_lock "const char *ttyname" -.Ft int -.Fn uu_lock_txfr "const char *ttyname" "pid_t pid" -.Ft int -.Fn uu_unlock "const char *ttyname" -.Ft const char * -.Fn uu_lockerr "int uu_lockresult" -.Sh DESCRIPTION -The -.Fn uu_lock -function attempts to create a lock file called -.Pa /var/spool/lock/LCK.. -with a suffix given by the passed -.Fa ttyname . -If the file already exists, it is expected to contain the process -id of the locking program. -.Pp -If the file does not already exist, or the owning process given by -the process id found in the lock file is no longer running, -.Fn uu_lock -will write its own process id into the file and return success. -.Pp -.Fn uu_lock_txfr -transfers lock ownership to another process. -.Fn uu_lock -must have previously been successful. -.Pp -.Fn uu_unlock -removes the lockfile created by -.Fn uu_lock -for the given -.Fa ttyname . -Care should be taken that -.Fn uu_lock -was successful before calling -.Fn uu_unlock . -.Pp -.Fn uu_lockerr -returns an error string representing the error -.Fa uu_lockresult , -as returned from -.Fn uu_lock . -.Sh RETURN VALUES -.Fn uu_unlock -returns 0 on success and -1 on failure. -.Pp -.Fn uu_lock -may return any of the following values: -.Pp -.Dv UU_LOCK_INUSE : -The lock is in use by another process. -.Pp -.Dv UU_LOCK_OK : -The lock was successfully created. -.Pp -.Dv UU_LOCK_OPEN_ERR : -The lock file could not be opened via -.Xr open 2 . -.Pp -.Dv UU_LOCK_READ_ERR : -The lock file could not be read via -.Xr read 2 . -.Pp -.Dv UU_LOCK_CREAT_ERR : -Cannot create temporary lock file via -.Xr creat 2 . -.Pp -.Dv UU_LOCK_WRITE_ERR : -The current process id could not be written to the lock file via a call to -.Xr write 2 . -.Pp -.Dv UU_LOCK_LINK_ERR : -Cannot link temporary lock file via -.Xr link 2 . -.Pp -.Dv UU_LOCK_TRY_ERR : -Locking attempts are failed after 5 tries. -.Pp -If a value of -.Dv UU_LOCK_OK -is passed to -.Fn uu_lockerr , -an empty string is returned. -Otherwise, a string specifying -the reason for failure is returned. -.Fn uu_lockerr -uses the current value of -.Va errno -to determine the exact error. -Care should be made not to allow -.Va errno -to be changed between calls to -.Fn uu_lock -and -.Fn uu_lockerr . -.Pp -.Fn uu_lock_txfr -may return any of the following values: -.Pp -.Dv UU_LOCK_OK : -The transfer was successful. -The specified process now holds the device -lock. -.Pp -.Dv UU_LOCK_OWNER_ERR : -The current process does not already own a lock on the specified device. -.Pp -.Dv UU_LOCK_WRITE_ERR : -The new process id could not be written to the lock file via a call to -.Xr write 2 . -.Sh ERRORS -If -.Fn uu_lock -returns one of the error values above, the global value -.Va errno -can be used to determine the cause. -Refer to the respective manual pages -for further details. -.Pp -.Fn uu_unlock -will set the global variable -.Va errno -to reflect the reason that the lock file could not be removed. -Refer to the description of -.Xr unlink 2 -for further details. -.Sh SEE ALSO -.Xr lseek 2 , -.Xr open 2 , -.Xr read 2 , -.Xr write 2 -.Sh BUGS -It is possible that a stale lock is not recognised as such if a new -processes is assigned the same processes id as the program that left -the stale lock. -.Pp -The calling process must have write permissions to the -.Pa /var/spool/lock -directory. -There is no mechanism in place to ensure that the -permissions of this directory are the same as those of the -serial devices that might be locked. diff --git a/uucplock.c b/uucplock.c deleted file mode 100644 index 2de06d2..0000000 --- a/uucplock.c +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (c) 1988, 1993 - * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 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. - */ - -#include - -#ifndef lint -static const char sccsid[] = "@(#)uucplock.c 8.1 (Berkeley) 6/6/93"; -#endif /* not lint */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "libutil.h" - -#define MAXTRIES 5 - -#define LOCKTMP "LCKTMP..%d" -#define LOCKFMT "LCK..%s" - -#define GORET(level, val) { err = errno; uuerr = (val); \ - goto __CONCAT(ret, level); } - -/* Forward declarations */ -static int put_pid (int fd, pid_t pid); -static pid_t get_pid (int fd,int *err); - -/* - * uucp style locking routines - */ - -int -uu_lock(const char *tty_name) -{ - int fd, tmpfd, i; - pid_t pid, pid_old; - char lckname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN], - lcktmpname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; - int err, uuerr; - - pid = getpid(); - (void)snprintf(lcktmpname, sizeof(lcktmpname), _PATH_UUCPLOCK LOCKTMP, - pid); - (void)snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, - tty_name); - if ((tmpfd = creat(lcktmpname, 0664)) < 0) - GORET(0, UU_LOCK_CREAT_ERR); - - for (i = 0; i < MAXTRIES; i++) { - if (link (lcktmpname, lckname) < 0) { - if (errno != EEXIST) - GORET(1, UU_LOCK_LINK_ERR); - /* - * file is already locked - * check to see if the process holding the lock - * still exists - */ - if ((fd = open(lckname, O_RDONLY)) < 0) - GORET(1, UU_LOCK_OPEN_ERR); - - if ((pid_old = get_pid (fd, &err)) == -1) - GORET(2, UU_LOCK_READ_ERR); - - close(fd); - - if (kill(pid_old, 0) == 0 || errno != ESRCH) - GORET(1, UU_LOCK_INUSE); - /* - * The process that locked the file isn't running, so - * we'll lock it ourselves - */ - (void)unlink(lckname); - } else { - if (!put_pid (tmpfd, pid)) - GORET(3, UU_LOCK_WRITE_ERR); - break; - } - } - GORET(1, (i >= MAXTRIES) ? UU_LOCK_TRY_ERR : UU_LOCK_OK); - -ret3: - (void)unlink(lckname); - goto ret1; -ret2: - (void)close(fd); -ret1: - (void)close(tmpfd); - (void)unlink(lcktmpname); -ret0: - errno = err; - return uuerr; -} - -int -uu_lock_txfr(const char *tty_name, pid_t pid) -{ - int fd, err; - char lckname[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; - - snprintf(lckname, sizeof(lckname), _PATH_UUCPLOCK LOCKFMT, tty_name); - - if ((fd = open(lckname, O_RDWR)) < 0) - return UU_LOCK_OWNER_ERR; - if (get_pid(fd, &err) != getpid()) - err = UU_LOCK_OWNER_ERR; - else { - lseek(fd, (off_t)0, SEEK_SET); - err = put_pid(fd, pid) ? 0 : UU_LOCK_WRITE_ERR; - } - close(fd); - - return err; -} - -int -uu_unlock(const char *tty_name) -{ - char tbuf[sizeof(_PATH_UUCPLOCK) + MAXNAMLEN]; - - (void)snprintf(tbuf, sizeof(tbuf), _PATH_UUCPLOCK LOCKFMT, tty_name); - return unlink(tbuf); -} - -const char * -uu_lockerr(int uu_lockresult) -{ - static char errbuf[128]; - const char *fmt; - - switch (uu_lockresult) { - case UU_LOCK_INUSE: - return "device in use"; - case UU_LOCK_OK: - return ""; - case UU_LOCK_OPEN_ERR: - fmt = "open error: %s"; - break; - case UU_LOCK_READ_ERR: - fmt = "read error: %s"; - break; - case UU_LOCK_CREAT_ERR: - fmt = "creat error: %s"; - break; - case UU_LOCK_WRITE_ERR: - fmt = "write error: %s"; - break; - case UU_LOCK_LINK_ERR: - fmt = "link error: %s"; - break; - case UU_LOCK_TRY_ERR: - fmt = "too many tries: %s"; - break; - case UU_LOCK_OWNER_ERR: - fmt = "not locking process: %s"; - break; - default: - fmt = "undefined error: %s"; - break; - } - - (void)snprintf(errbuf, sizeof(errbuf), fmt, strerror(errno)); - return errbuf; -} - -static int -put_pid(int fd, pid_t pid) -{ - char buf[32]; - int len; - - len = sprintf (buf, "%10d\n", (int)pid); - return write (fd, buf, (size_t)len) == len; -} - -static pid_t -get_pid(int fd, int *err) -{ - int bytes_read; - char buf[32]; - pid_t pid; - - bytes_read = read (fd, buf, sizeof (buf) - 1); - if (bytes_read > 0) { - buf[bytes_read] = '\0'; - pid = (pid_t)strtol (buf, (char **) NULL, 10); - } else { - pid = -1; - *err = bytes_read ? errno : EINVAL; - } - return pid; -} - -/* end of uucplock.c */ diff --git a/wipefs.3 b/wipefs.3 index 0f14dfc..21cee1c 100644 --- a/wipefs.3 +++ b/wipefs.3 @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2008 Apple Inc. All rights reserved. +.\" Copyright (c) 2008,2011 Apple Inc. All rights reserved. .\" .\" @APPLE_LICENSE_HEADER_START@ .\" @@ -20,7 +20,7 @@ .\" .\" @APPLE_LICENSE_HEADER_END@ .\" -.Dd 2/25/08 \" DATE +.Dd 6/30/11 \" DATE .Dt libutil 3 \" Program name and manual section number .Os Mac OS X .Sh NAME \" Section Header - required - don't modify @@ -38,14 +38,20 @@ .In wipefs.h .Ft int .Fo wipefs_alloc -.Fa "int file_desc" +.Fa "int fd" .Fa "size_t block_size" -.Fa "wipefs_ctx *handlep" +.Fa "wipefs_ctx *handle" +.Fc +.Ft int +.Fo wipefs_include_blocks +.Fa "wipefs_ctx handle" +.Fa "off_t block_offset" +.Fa "off_t nblocks" .Fc .Ft int .Fo wipefs_except_blocks .Fa "wipefs_ctx handle" -.Fa "off_t blockoff" +.Fa "off_t block_offset" .Fa "off_t nblocks" .Fc .Ft int @@ -54,10 +60,20 @@ .Fc .Ft void .Fo wipefs_free -.Fa "wipefs_ctx *handlep" +.Fa "wipefs_ctx *handle" .Fc .Sh DESCRIPTION \" Section Header - required - don't modify -The wipefs family of functions wipe existing file systems on a volume. This is usually used by the newfs_* utilities before they create new file systems on the volume, so that the existing file system will not be mounted accidentally after the new file system is created. +The wipefs family of functions wipe existing file systems on a volume. A +.Li DKIOCUNMAP +ioctl is sent to the device to invalidate all of its content. +Then zeroes are written to various locations that are used by various file systems to recognize their content and mount their volumes. +This is usually used by the newfs_* utilities before they create new file systems on the volume, so that the existing file system will not be mounted accidentally after the new file system is created. +.Pp +.Sy NOTE: +These routines do not overwrite all volume structures. +These routines do not securely erase the previous content. +They only overwrite enough to make sure that the normal utilities will no longer recognize any file system content. +It is possible that previous file system content could be recovered by other means. .Pp The .Fn wipefs_alloc @@ -78,6 +94,15 @@ must be supplied if is a regular file. This function does not write any data to the volume. .Pp The +.Fn wipefs_include_blocks +function tells wipefs to write zeroes in the block range provided, in addition to any other ranges +it would normally write. This may be more efficient than if the caller were to write this range +separately, especially if the block range overlaps or is contiguous with other ranges that wipefs +will write. This function does not write any data to the volume. If this function is called +multiple times, the union of all the ranges provided will be written by +.Fn wipefs_wipe . +.Pp +The .Fn wipefs_except_blocks function tells wipefs not to write anything in the block range provided. This function is used for performance optimizations if the caller will write to these blocks. It is the caller's responsibility to write to these blocks. @@ -88,8 +113,10 @@ written by .Pp The .Fn wipefs_wipe -function writes data to the volume to wipe out existing file systems on it. -.Cm Caution: +function sends a +.Li DKIOCUNMAP +ioctl and then writes data to the volume to wipe out existing file systems on it. +.Sy CAUTION: this function destroys any file system or partition scheme on the volume represented by .Fa file_desc . If @@ -112,6 +139,7 @@ to NULL. .Sh RETURN VALUES The .Fn wipefs_alloc , +.Fn wipefs_include_blocks , .Fn wipefs_except_blocks and .Fn wipefs_wipe diff --git a/wipefs.cpp b/wipefs.cpp index 7b0857a..2510969 100644 --- a/wipefs.cpp +++ b/wipefs.cpp @@ -25,6 +25,7 @@ // #include +#include #include #include #include @@ -202,6 +203,22 @@ wipefs_alloc(int fd, size_t block_size, wipefs_ctx *handle) return err; } // wipefs_alloc +extern "C" int +wipefs_include_blocks(wipefs_ctx handle, off_t block_offset, off_t nblocks) +{ + int err = 0; + try { + handle->extMan.AddBlockRangeExtent(block_offset, nblocks); + } + catch (bad_alloc &e) { + err = ENOMEM; + } + catch (...) { // currently only ENOMEM is possible + err = ENOMEM; + } + return err; +} + extern "C" int wipefs_except_blocks(wipefs_ctx handle, off_t block_offset, off_t nblocks) { @@ -242,7 +259,7 @@ wipefs_wipe(wipefs_ctx handle) ioctl(handle->fd, DKIOCUNMAP, (caddr_t)&unmap); - bufSize = 256 * 1024; // issue large I/O to get better performance + bufSize = 128 * 1024; // issue large I/O to get better performance bufZero = new uint8_t[bufSize]; bzero(bufZero, bufSize); diff --git a/wipefs.h b/wipefs.h index e615d5e..0a9321b 100644 --- a/wipefs.h +++ b/wipefs.h @@ -34,6 +34,7 @@ typedef struct __wipefs_ctx *wipefs_ctx; __BEGIN_DECLS extern int wipefs_alloc(int fd, size_t block_size, wipefs_ctx *handle); +extern int wipefs_include_blocks(wipefs_ctx handle, off_t block_offset, off_t nblocks); extern int wipefs_except_blocks(wipefs_ctx handle, off_t block_offset, off_t nblocks); extern int wipefs_wipe(wipefs_ctx handle); extern void wipefs_free(wipefs_ctx *handle); -- 2.47.2