ucspi-unix-0.36/0040775000076400007640000000000007501213046013115 5ustar bruceguenterucspi-unix-0.36/ANNOUNCEMENT0100664000076400007640000000342407501213046014732 0ustar bruceguenterVersion 0.36 of ucspi-unix is now available at: http://untroubled.org/ucspi-unix/ ------------------------------------------------------------------------------ Changes in version 0.36 - Fixed a header ordering problem on FreeBSD. - Adjusted to SPAC build environment, including additional portability fixes, and external bglibs. - Added options for setting the ownership, group ownership, and mode of the created socket. - Added man pages (contributed by Tomas Kuliavas) Development of this version has been sponsored by FutureQuest, Inc. ossi@FutureQuest.net http://www.FutureQuest.net/ ------------------------------------------------------------------------------- ucspi-unix UNIX-domain socket client-server command-line tools Bruce Guenter Version 0.36 2002-06-10 This package contains UNIX domain socket client and server programs that conform to UCSPI, the UNIX Client-Server Program Interface. A mailing list has been set up to discuss this and other packages. To subscribe, send an email to: bgware-subscribe@lists.em.ca A mailing list archive is available at: http://lists.em.ca/?list=bgware Development versions of ucspi-unix are available via anonymous CVS. Set your CVSROOT to ":pserver:cvs@bruce-guenter.dyndns.org:/CVS", login with an empty password, and check out the "ucspi-unix" module. Requirements: - A UNIX system supporting UNIX domain sockets. - Systems supporting the SO_PEERCRED socket option (only Linux currently) will have extra functionality. How to install: - As root, run "make ; ./installer" This program is Copyright(C) 2002 Bruce Guenter, and may be copied according to the GNU GENERAL PUBLIC LICENSE (GPL) Version 2 or a later version. A copy of this license is included with this package. This package comes with no warranty of any kind. ucspi-unix-0.36/COPYING0100664000076400007640000004311007501213046014144 0ustar bruceguenter GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. ucspi-unix-0.36/FILES0100664000076400007640000000036207501213046013700 0ustar bruceguenterANNOUNCEMENT COPYING FILES Makefile NEWS PROTOCOL README TARGETS TODO VERSION conf-bin conf-cc conf-ld conf-man env.c insthier.c trylib.c ucspi-unix-0.36.spec unixcat.sh unixclient.1 unixclient.c unixserver.1 unixserver.c utoa.c warn-auto.sh ucspi-unix-0.36/Makefile0100664000076400007640000000373607501213046014563 0ustar bruceguenter# Don't edit Makefile! Use conf-* for configuration. # # Generated by spac see http://untroubled.org/spac/ SHELL=/bin/sh DEFAULT: all all: programs installer instcheck instshow clean: TARGETS rm -f `cat TARGETS` clean-spac: clean AUTOFILES rm -f `cat AUTOFILES` compile: conf-cc ( echo '#!/bin/sh'; \ echo 'source=$$1; shift'; \ echo 'base=`echo "$$source" | sed -e s:\\\\.c$$::`'; \ echo exec `head -1 conf-cc` '-I. -o $${base}.o -c $$source $${1+"$$@"}'; \ ) >compile chmod 755 compile conf_bin.c: conf-bin head -1 conf-bin | \ sed -e 's/"/\\"/g' \ -e 's/^/const char conf_bin[] = "/' \ -e 's/$$/";/' >conf_bin.c conf_man.c: conf-man head -1 conf-man | \ sed -e 's/"/\\"/g' \ -e 's/^/const char conf_man[] = "/' \ -e 's/$$/";/' >conf_man.c env.o: compile env.c ./compile env.c installer: load insthier.o ./load insthier -linstaller mv insthier installer instcheck: load insthier.o ./load insthier -linstcheck mv insthier instcheck insthier.o: compile insthier.c conf_bin.c conf_man.c ./compile insthier.c instshow: load insthier.o ./load insthier -linstshow mv insthier instshow load: conf-ld ( echo '#!/bin/sh';\ echo 'main="$$1"; shift';\ echo exec `head -1 conf-ld` '-o "$$main" "$$main.o" $${1+"$$@"}' -lsysdeps;\ ) >load chmod 755 load programs: unixclient unixserver unixcat socket.lib: compile load trylib.c ( ( ./compile trylib.c && ./load trylib -lsocket -lnsl ) >/dev/null 2>&1 \ && echo -lsocket -lnsl || exit 0 ) >socket.lib rm -f trylib.o trylib unixcat: warn-auto.sh unixcat.sh cat warn-auto.sh unixcat.sh >unixcat chmod 755 unixcat unixclient: load unixclient.o env.o utoa.o socket.lib ./load unixclient env.o utoa.o `cat socket.lib` unixclient.o: compile unixclient.c ./compile unixclient.c unixserver: load unixserver.o env.o utoa.o socket.lib ./load unixserver env.o utoa.o `cat socket.lib` unixserver.o: compile unixserver.c ./compile unixserver.c utoa.o: compile utoa.c ./compile utoa.c ucspi-unix-0.36/NEWS0100664000076400007640000000471707501213046013622 0ustar bruceguenter------------------------------------------------------------------------------- Changes in version 0.36 - Fixed a header ordering problem on FreeBSD. - Adjusted to SPAC build environment, including additional portability fixes, and external bglibs. - Added options for setting the ownership, group ownership, and mode of the created socket. - Added man pages (contributed by Tomas Kuliavas) Development of this version has been sponsored by FutureQuest, Inc. ossi@FutureQuest.net http://www.FutureQuest.net/ ------------------------------------------------------------------------------- Changes in version 0.34 - If getsockopt fails, don't fail the connection. This fixes problems with Linux 2.0 systems. ------------------------------------------------------------------------------- Changes in version 0.33 - Fixed a bug in unixserver that could cause it to enter an infinite loop. - Should now compile on FreeBSD. ------------------------------------------------------------------------------- Changes in version 0.32 - unixserver now sets the umask before creating the socket, and restores it afterwards. The default umask is 0, so that all users can open the socket. ------------------------------------------------------------------------------- Changes in version 0.31 (brown paper bag release) - Fixed bug in reading the UID/GID values from the environment. - Fixed exit bug that caused the socket to be deleted after the first use. - Fixed uninitialized variable bug in getting socket options. ------------------------------------------------------------------------------- Changes in version 0.30 - Now supports UID/GID switching, setting the backlog, and printing out a banner on connection in tcpserver. ------------------------------------------------------------------------------- Changes in version 0.20 - The environment is now set up properly according to the UCSPI specification, and documented in the PROTOCOL file. - Added code to determine the socket peer credentials (UID, GID, and PID) on systems supporting SO_PEERCRED (specifically Linux). Question: Should the protocol be called "UNIX" as it currently is, or "local" which more accurately reflects that they are local-domain sockets? ------------------------------------------------------------------------------- Changes in version 0.10 - First release, includes base functionality for unixserver and unixclient. ------------------------------------------------------------------------------- ucspi-unix-0.36/PROTOCOL0100664000076400007640000000200207501213046014270 0ustar bruceguenterUNIX UCSPI protocol definition Copyright (C) 2000 Bruce Guenter This document defines the UNIX protocol for UCSPI tools. A UNIX client communicates with a UNIX server on the same machine through a local-domain stream socket. See http://cr.yp.to/proto/ucspi.txt for further details on the UCSPI standard. Both the client and the server set up the following environment variables: PROTO the string "UNIX" UNIXLOCALPATH is the path associated with the local-domain socket UNIXLOCALUID is the UID of the local process UNIXLOCALGID is the GID of the local process UNIXLOCALPID is the PID of the local process UNIXREMOTEEUID is the effective UID of the remote process UNIXREMOTEEGID is the effective GID of the remote process UNIXREMOTEPID is the PID of the remote process Note that the remote variables are only supported on operating systems that support some way of identifying the process connecting to a socket. For now this is limited to Linux kernel 2.1 or later with SO_PEERCRED support. ucspi-unix-0.36/README0100664000076400007640000000215707501213046013777 0ustar bruceguenterucspi-unix UNIX-domain socket client-server command-line tools Bruce Guenter Version 0.36 2002-06-10 This package contains UNIX domain socket client and server programs that conform to UCSPI, the UNIX Client-Server Program Interface. A mailing list has been set up to discuss this and other packages. To subscribe, send an email to: bgware-subscribe@lists.em.ca A mailing list archive is available at: http://lists.em.ca/?list=bgware Development versions of ucspi-unix are available via anonymous CVS. Set your CVSROOT to ":pserver:cvs@bruce-guenter.dyndns.org:/CVS", login with an empty password, and check out the "ucspi-unix" module. Requirements: - A UNIX system supporting UNIX domain sockets. - Systems supporting the SO_PEERCRED socket option (only Linux currently) will have extra functionality. How to install: - As root, run "make ; ./installer" This program is Copyright(C) 2002 Bruce Guenter, and may be copied according to the GNU GENERAL PUBLIC LICENSE (GPL) Version 2 or a later version. A copy of this license is included with this package. This package comes with no warranty of any kind. ucspi-unix-0.36/TARGETS0100664000076400007640000000027107501213046014146 0ustar bruceguenterall clean clean-spac compile conf_bin.c conf_man.c env.o installer instcheck insthier.o instshow load programs socket.lib unixcat unixclient unixclient.o unixserver unixserver.o utoa.o ucspi-unix-0.36/TODO0100664000076400007640000000005407501213046013601 0ustar bruceguenter- Needs LIBS = -lsocket -lxnet -ldl -lnsl ? ucspi-unix-0.36/VERSION0100664000076400007640000000002007501213046014152 0ustar bruceguenterucspi-unix 0.36 ucspi-unix-0.36/conf-bin0100664000076400007640000000007607501213046014533 0ustar bruceguenter/usr/local/bin Programs will be installed in this directory. ucspi-unix-0.36/conf-cc0100664000076400007640000000012707501213046014345 0ustar bruceguentergcc -W -Wall -O -g -I/usr/local/bglibs/include This will be used to compile .c files. ucspi-unix-0.36/conf-ld0100664000076400007640000000013607501213046014357 0ustar bruceguentergcc -s -L/usr/local/bglibs/lib This will be used to link .o and .a files into an executable. ucspi-unix-0.36/conf-man0100664000076400007640000000021407501213046014530 0ustar bruceguenter/usr/local/man Man pages will be installed in subdirectories of this directory. An unformatted man page foo.1 will go into .../man1/foo.1. ucspi-unix-0.36/env.c0100664000076400007640000000123407501213046014046 0ustar bruceguenter#include #include #include #include extern const char* utoa(unsigned long); void setup_env(int fd, const char* socket) { #ifdef HASPEERCRED struct ucred peer; int optlen = sizeof(peer); if(getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &peer, &optlen) != -1) { setenv("UNIXREMOTEEGID", utoa(peer.gid), 1); setenv("UNIXREMOTEEUID", utoa(peer.uid), 1); setenv("UNIXREMOTEPID", utoa(peer.pid), 1); } #endif setenv("PROTO", "UNIX", 1); setenv("UNIXLOCALGID", utoa(getgid()), 1); setenv("UNIXLOCALPID", utoa(getpid()), 1); setenv("UNIXLOCALPATH", socket, 1); setenv("UNIXLOCALUID", utoa(getuid()), 1); } ucspi-unix-0.36/insthier.c0100664000076400007640000000062307501213046015104 0ustar bruceguenter#include #include "conf_bin.c" #include "conf_man.c" void insthier(void) { int bin = opendir(conf_bin); int man = opendir(conf_man); int man1; c(bin, "unixcat", -1, -1, 0755); c(bin, "unixclient", -1, -1, 0755); c(bin, "unixserver", -1, -1, 0755); man1 = d(man, "man1", -1, -1, 0755); c(man1, "unixclient.1", -1, -1, 0644); c(man1, "unixserver.1", -1, -1, 0644); } ucspi-unix-0.36/trylib.c0100664000076400007640000000001707501213046014561 0ustar bruceguentermain() { ; } ucspi-unix-0.36/ucspi-unix-0.36.spec0100664000076400007640000000242307501213046016457 0ustar bruceguenterName: ucspi-unix Summary: UNIX-domain socket client-server command-line tools Version: 0.36 Release: 1 Copyright: GPL Group: Utilities/System Source: http://em.ca/~bruceg/ucspi-unix/%{version}/ucspi-unix-%{version}.tar.gz BuildRoot: %{_tmppath}/ucspi-unix-root URL: http://em.ca/~bruceg/ucspi-unix/ Packager: Bruce Guenter BuildRequires: bglibs %description unixclient and unixserver are command-line tools for building UNIX domain client-server applications. unixclient connects to a UNIX domain socket and runs a program of your choice. unixserver creates a UNIX domain socket, waits for incoming connections and, for each connection, runs a program of your choice. unixclient and unixserver conform to UCSPI, the UNIX Client-Server Program Interface, using UNIX domain sockets. UCSPI tools are available for several different networks. %prep %setup %build echo %{_bindir} >conf-bin echo %{_mandir} >conf-man make programs %install rm -fr %{buildroot} mkdir -p %{buildroot}%{_bindir} mkdir -p %{buildroot}%{_mandir} echo %{buildroot}%{_bindir} >conf-bin echo %{buildroot}%{_mandir} >conf-man make installer instcheck ./installer ./instcheck %clean rm -rf %{buildroot} %files %defattr(-,root,root) %doc COPYING NEWS PROTOCOL README TODO VERSION %{_bindir}/* %{_mandir}/*/* ucspi-unix-0.36/unixcat.sh0100664000076400007640000000005207501213046015116 0ustar bruceguenterexec unixclient "$1" sh -c 'exec cat <&6' ucspi-unix-0.36/unixclient.10100664000076400007640000000143607501213046015362 0ustar bruceguenter.TH UNIXCLIENT 1 .SH NAME unixclient - UNIX domain socket client .SH SYNOPSIS unixclient [options] socket program .SH DESCRIPTION Unixclient is UNIX domain socket client that conform to UCSPI, the UNIX Client-Server Program Interface. .SH OPTIONS .HP .TP \fB\-q \fR Quiet. Do not print any messages. .TP \fB\-Q \fR (default) Print error messages. .TP \fB\-v \fR Verbose. Print error and status messages. \fB\-c N \fR Do not handle more than N simultaneous connections. (default 10) .SH SEE ALSO unixserver(1), unixcat(1) http://cr.yp.to/proto/ucspi.txt .SH AUTHOR ucspi-unix package was written by Bruce Guenter .PP This manual page was originally written by Tomas Kuliavas for the Debian GNU/Linux system, but may be used elsewhere under the GPL. ucspi-unix-0.36/unixclient.c0100664000076400007640000000363707501213046015451 0ustar bruceguenter#include #include #include #include #include #include #include #include #include extern void setup_env(int, const char*); #ifndef SUN_LEN /* Evaluate to actual length of the `sockaddr_un' structure. */ #define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ + strlen ((ptr)->sun_path)) #endif static const char* argv0; static const char* opt_socket; static char** command_argv; void die(const char* msg) { perror(msg); exit(1); } int do_connect(void) { size_t size; struct sockaddr_un* saddr; int s = socket(AF_UNIX, SOCK_STREAM, 0); if(s == -1) die("socket"); size = sizeof(struct sockaddr_un) + strlen(opt_socket)+1; saddr = (struct sockaddr_un*)malloc(size); saddr->sun_family = AF_UNIX; strcpy(saddr->sun_path, opt_socket); if(connect(s, (struct sockaddr*)saddr, SUN_LEN(saddr)) == -1) die("connect"); free(saddr); return s; } void usage(const char* message) { if(message) fprintf(stderr, "%s: %s\n", argv0, message); fprintf(stderr, "usage: %s [options] socket program\n" " -q Quiet. Do not print any messages.\n" " -Q (default) Print error messages.\n" " -v Verbose. Print error and status messages.\n" " -c N Do not handle more than N simultaneous connections.\n" " (default 10)\n", argv0); exit(1); } void parse_options(int argc, char* argv[]) { argv0 = argv[0]; ++argv; --argc; if(argc < 2) usage(0); opt_socket = argv[0]; command_argv = argv + 1; } void exec_program(int fd) { setup_env(fd, opt_socket); if(dup2(fd, 6) == -1 || dup2(fd, 7) == -1) die("dup2"); close(fd); execvp(command_argv[0], command_argv); die("execvp"); } int main(int argc, char* argv[]) { int fd; parse_options(argc, argv); fd = do_connect(); exec_program(fd); return 1; } ucspi-unix-0.36/unixserver.10100664000076400007640000000317307501213046015412 0ustar bruceguenter.TH UNIXSERVER 1 .SH NAME unixserver - UNIX domain socket server .SH SYNOPSIS unixserver [options] socket program .SH DESCRIPTION Unixserver is UNIX domain socket server that conform to UCSPI, the UNIX Client-Server Program Interface. .SH OPTIONS .HP .TP \fB\-q \fR Quiet. Do not print any messages. .TP \fB\-Q \fR (default) Print error messages. .TP \fB\-v \fR Verbose. Print error and status messages. .TP \fB\-d \fR Do not delete the socket file on exit. .TP \fB\-D \fR (default) Delete the socket file on exit. .TP \fB\-u UID \fR Change user id to UID after creating socket. .TP \fB\-g GID \fR Change group id to GID after creating socket. .TP \fB\-U \fR Same as '-u $UID -g $GID'. .TP \fB\-o UID\fR Make the socket owned by UID. .TP \fB\-r GID\fR Make the socket group owned by GID. .TP \fB\-O\fR Same as '-o $SOCKET_UID -r $SOCKET_GID'. .TP \fB\-p PERM\fR Set the permissions on the created socket (in octal). Note: this option, if set, overrides the mask below. (defaults to 0666 minus umask) .TP \fB\-m MASK \fR Set umask to MASK (in octal) before creating socket. (defaults to 0, previous value is restored afterwards) .TP \fB\-c N \fR Do not handle more than N simultaneous connections. (default 10) .TP \fB\-b N \fR Allow a backlog of N connections. .TP \fB\-B BANNER \fR Write BANNER to the client immediately after connecting. .SH SEE ALSO unixclient(1), unixcat(1) http://cr.yp.to/proto/ucspi.txt .SH AUTHOR ucspi-unix package was written by Bruce Guenter .PP This manual page was originally written by Tomas Kuliavas for the Debian GNU/Linux system, but may be used elsewhere under the GPL. ucspi-unix-0.36/unixserver.c0100664000076400007640000001673407501213046015503 0ustar bruceguenter#include #include #include #include #include #include #include #include #include #include extern void setup_env(int, const char*); #ifndef SUN_LEN /* Evaluate to actual length of the `sockaddr_un' structure. */ #define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ + strlen ((ptr)->sun_path)) #endif static const char* argv0; static char** command_argv; static unsigned forked = 0; static unsigned opt_quiet = 0; static unsigned opt_verbose = 0; static unsigned opt_delete = 1; static unsigned opt_connections = 10; static const char* opt_socket; static uid_t opt_uid = -1; static gid_t opt_gid = -1; static uid_t opt_socket_uid = -1; static gid_t opt_socket_gid = -1; static mode_t opt_perms = 0; static mode_t opt_umask = 0; static int opt_backlog = 128; static const char* opt_banner = 0; void usage(const char* message) { if(message) fprintf(stderr, "%s: %s\n", argv0, message); fprintf(stderr, "usage: %s [options] socket program\n" " -q Quiet. Do not print any messages.\n" " -Q (default) Print error messages.\n" " -v Verbose. Print error and status messages.\n" " -d Do not delete the socket file on exit.\n" " -D (default) Delete the socket file on exit.\n" " -u UID Change user id to UID after creating socket.\n" " -g GID Change group id to GID after creating socket.\n" " -U Same as '-u $UID -g $GID'.\n" " -o UID Make the socket owned by UID.\n" " -r GID Make the socket group owned by GID.\n" " -O Same as '-o $SOCKET_UID -r $SOCKET_GID'.\n" " -p PERM Set the permissions on the created socket (in octal).\n" " Note: this option, if set, overrides the mask below.\n" " (defaults to 0666 minus umask)\n" " -m MASK Set umask to MASK (in octal) before creating socket.\n" " (defaults to 0, previous value is restored afterwards)\n" " -c N Do not handle more than N simultaneous connections.\n" " (default 10)\n" " -b N Allow a backlog of N connections.\n" " -B BANNER Write BANNER to the client immediately after connecting.\n", argv0); exit(1); } void log_status(void) { if(opt_verbose) printf("unixserver: status: %d/%d\n", forked, opt_connections); } void log_child_exit(pid_t pid, int status) { if(opt_verbose) printf("unixserver: end %d status %d\n", pid, status); log_status(); } void log_child_start(pid_t pid) { if(opt_verbose) printf("unixserver: pid %d\n", pid); } void die(const char* msg) { perror(msg); if(opt_delete) unlink(opt_socket); exit(1); } static int parseu(const char* str, unsigned* out, int base) { char* ptr; if (!str) return 0; *out = strtoul(str, &ptr, base); return (*ptr == 0); } static void use_uid(const char* str) { if (!str) usage("UID not found in environment."); if (!parseu(str, &opt_uid, 10)) usage("Invalid UID number"); } static void use_gid(const char* str) { if (!str) usage("GID not found in environment."); if (!parseu(str, &opt_gid, 10)) usage("Invalid GID number"); } static void use_socket_uid(const char* str) { if (!str) usage("Socket UID not found in environment."); if (!parseu(str, &opt_socket_uid, 10)) usage("Invalid socket UID number"); } static void use_socket_gid(const char* str) { if (!str) usage("Socket GID not found in environment."); if (!parseu(str, &opt_socket_gid, 10)) usage("Invalid socket GID number"); } void parse_options(int argc, char* argv[]) { int opt; argv0 = argv[0]; while((opt = getopt(argc, argv, "qQvc:u:g:Ub:B:m:o:r:Op:")) != EOF) { switch(opt) { case 'q': opt_quiet = 1; opt_verbose = 0; break; case 'Q': opt_quiet = 0; break; case 'v': opt_quiet = 0; opt_verbose = 1; break; case 'd': opt_delete = 0; break; case 'D': opt_delete = 1; break; case 'c': if (!parseu(optarg, &opt_connections, 10)) usage("Invalid connection limit number."); break; case 'u': use_uid(optarg); break; case 'g': use_gid(optarg); break; case 'U': use_uid(getenv("UID")); use_gid(getenv("GID")); break; case 'o': use_socket_uid(optarg); break; case 'r': use_socket_gid(optarg); break; case 'O': use_socket_uid(getenv("SOCKET_UID")); use_socket_gid(getenv("SOCKET_GID")); break; case 'p': if (!parseu(optarg, &opt_perms, 8)) usage("Invalid permissions value."); break; case 'm': if (!parseu(optarg, &opt_umask, 8)) usage("Invalid mask value."); break; case 'b': if (!parseu(optarg, &opt_backlog, 10)) usage("Invalid backlog count."); break; case 'B': opt_banner = optarg; break; default: usage(0); } } argc -= optind; argv += optind; if(argc < 2) usage(0); opt_socket = argv[0]; command_argv = argv + 1; } int make_socket() { struct sockaddr_un* saddr; int s; mode_t old_umask; saddr = (struct sockaddr_un*)malloc(sizeof(struct sockaddr_un) + strlen(opt_socket) + 1); saddr->sun_family = AF_UNIX; strcpy(saddr->sun_path, opt_socket); unlink(opt_socket); s = socket(AF_UNIX, SOCK_STREAM, 0); if(s < 0) die("socket"); old_umask = umask(opt_umask); if(bind(s, (struct sockaddr*)saddr, SUN_LEN(saddr)) != 0) die("bind"); umask(old_umask); if(chown(opt_socket, opt_socket_uid, opt_socket_gid) == -1) die("chown"); if(opt_perms && chmod(opt_socket, opt_perms) == -1) die("chmod"); if(listen(s, opt_backlog) != 0) die("listen"); if(opt_gid != (gid_t)-1 && setgid(opt_gid) == -1) die("setgid"); if(opt_uid != (uid_t)-1 && setuid(opt_uid) == -1) die("setuid"); return s; } void start_child(int fd) { if(opt_banner) write(fd, opt_banner, strlen(opt_banner)); setup_env(fd, opt_socket); close(0); close(1); if(dup2(fd, 0) == -1 || dup2(fd, 1) == -1) { perror("dup2"); exit(-1); } close(fd); execvp(command_argv[0], command_argv); perror("execvp"); exit(-1); } void handle_connection(int s) { int fd; pid_t pid; do { fd = accept(s, NULL, NULL); // All the listed error return values are not possible except for // buggy code, so just try again if accept fails. } while(fd < 0); ++forked; log_status(); pid = fork(); switch(pid) { case -1: // Could not fork close(fd); perror("fork"); --forked; log_status(); break; case 0: start_child(fd); break; default: close(fd); log_child_start(pid); } } void handle_children() { pid_t pid; int status; #if HASWAITPID while((pid = waitpid(0, &status, WNOHANG | WUNTRACED)) > 0) { --forked; log_child_exit(pid, status); } #else pid = wait(&status); --forked; log_child_exit(pid, status); #endif signal(SIGCHLD, handle_children); } void handle_child(void) { int status; pid_t pid = wait(&status); if(pid == -1) die("wait"); --forked; log_child_exit(pid, status); } void handle_intr() { if(opt_delete) unlink(opt_socket); exit(0); } int main(int argc, char* argv[]) { int s; parse_options(argc, argv); signal(SIGCHLD, handle_children); signal(SIGINT, handle_intr); signal(SIGTERM, handle_intr); signal(SIGQUIT, handle_intr); signal(SIGHUP, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGALRM, SIG_IGN); s = make_socket(); log_status(); for(;;) { while(forked >= opt_connections) handle_child(); handle_connection(s); } } ucspi-unix-0.36/utoa.c0100664000076400007640000000037107501213046014227 0ustar bruceguenterconst char* utoa(unsigned long i) { #define LONGLEN (sizeof(unsigned long)*4) static char buf[LONGLEN]; char* ptr = buf + LONGLEN; if(!i) return "0"; *--ptr = 0; while(i) { *--ptr = (i % 10) + '0'; i /= 10; } return ptr; } ucspi-unix-0.36/warn-auto.sh0100664000076400007640000000010007501213046015352 0ustar bruceguenter#!/bin/sh # WARNING: This file was auto-generated. Do not edit!