ucspi-unix-1.0/0000775000076400007640000000000012562534004013024 5ustar bruceguenterucspi-unix-1.0/TARGETS0000664000076400007640000000031712562534004014061 0ustar bruceguenterall clean clean-spac compile docs env.o haspeercred.h haswaitp.h install libraries load programs socket.lib unixcat unixclient unixclient.1.html unixclient.o unixserver unixserver.1.html unixserver.o utoa.o ucspi-unix-1.0/conf-ld0000664000076400007640000000010612562534004014266 0ustar bruceguentergcc -s This will be used to link .o and .a files into an executable. ucspi-unix-1.0/FILES0000664000076400007640000000053312562534004013612 0ustar bruceguenterANNOUNCEMENT AUTOFILES COPYING ChangeLog FILES Makefile NEWS PROTOCOL README SRCFILES TARGETS TODO VERSION conf-cc conf-ld env.c haspeercred.h0 haspeercred.h1 haswaitp.h0 haswaitp.h1 trypeercred.c trywaitp.c ucspi-unix-1.0.spec unixcat.sh unixclient.1 unixclient.1.html unixclient.c unixserver.1 unixserver.1.html unixserver.c utoa.c warn-auto.sh ucspi-unix-1.0/unixclient.10000664000076400007640000000143612562534004015274 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-1.0/haswaitp.h00000664000076400007640000000002712562534004015074 0ustar bruceguenter/* sysdep: -waitpid */ ucspi-unix-1.0/trypeercred.c0000664000076400007640000000032312562534004015516 0ustar bruceguenter#define _GNU_SOURCE 1 #include #include int main() { struct ucred peer; socklen_t optlen = sizeof(peer); getsockopt(0, SOL_SOCKET, SO_PEERCRED, &peer, &optlen); return 0; } ucspi-unix-1.0/haswaitp.h10000664000076400007640000000005412562534004015075 0ustar bruceguenter/* sysdep: +waitpid */ #define HASWAITPID 1 ucspi-unix-1.0/COPYING0000664000076400007640000004311012562534004014056 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-1.0/SRCFILES0000664000076400007640000000023312562534004014157 0ustar bruceguenterenv.c haspeercred.h0 haspeercred.h1 haswaitp.h0 haswaitp.h1 trypeercred.c trywaitp.c unixcat.sh unixclient.1 unixclient.c unixserver.1 unixserver.c utoa.c ucspi-unix-1.0/unixserver.1.html0000664000076400007640000001351612562534004016271 0ustar bruceguenter UNIXSERVER

UNIXSERVER

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
SEE ALSO
AUTHOR

NAME

unixserver - UNIX domain socket server

SYNOPSIS

unixserver [options] socket program

DESCRIPTION

Unixserver is UNIX domain socket server that conform to UCSPI, the UNIX Client-Server Program Interface.

OPTIONS

−q

Quiet. Do not print any messages.

−Q

(default) Print error messages.

−v

Verbose. Print error and status messages.

−d

Do not delete the socket file on exit.

−D

(default) Delete the socket file on exit.

−u UID

Change user id to UID after creating socket.

−g GID

Change group id to GID after creating socket.

−U

Same as ’-u $UID -g $GID’.

−o UID

Make the socket owned by UID.

−r GID

Make the socket group owned by GID.

−O

Same as ’-o $SOCKET_UID -r $SOCKET_GID’.

−p PERM

Set the permissions on the created socket (in octal). Note: this option, if set, overrides the mask below. (defaults to 0666 minus umask)

−m MASK

Set umask to MASK (in octal) before creating socket. (defaults to 0, previous value is restored afterwards)

−c N

Do not handle more than N simultaneous connections. (default 10)

−b N

Allow a backlog of N connections.

−B BANNER

Write BANNER to the client immediately after connecting.

SEE ALSO

unixclient(1), unixcat(1) http://cr.yp.to/proto/ucspi.txt

AUTHOR

ucspi-unix package was written by Bruce Guenter <bruceg@em.ca>

This manual page was originally written by Tomas Kuliavas <tokul@bigfoot.com> for the Debian GNU/Linux system, but may be used elsewhere under the GPL.


ucspi-unix-1.0/PROTOCOL0000664000076400007640000000200212562534004014202 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-1.0/TODO0000664000076400007640000000005412562534004013513 0ustar bruceguenter- Needs LIBS = -lsocket -lxnet -ldl -lnsl ? ucspi-unix-1.0/trywaitp.c0000664000076400007640000000013312562534004015050 0ustar bruceguenter#include #include int main() { waitpid(0,0,0); return 0; } ucspi-unix-1.0/unixserver.10000664000076400007640000000317312562534004015324 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-1.0/env.c0000664000076400007640000000124612562534004013763 0ustar bruceguenter#include "haspeercred.h" #include #include #include extern const char* utoa(unsigned long); void setup_env(int fd, const char* socket) { #ifdef HASPEERCRED struct ucred peer; socklen_t 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-1.0/unixcat.sh0000664000076400007640000000005212562534004015030 0ustar bruceguenterexec unixclient "$1" sh -c 'exec cat <&6' ucspi-unix-1.0/utoa.c0000664000076400007640000000037112562534004014141 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-1.0/ucspi-unix-1.0.spec0000664000076400007640000000211512562534004016277 0ustar bruceguenterName: ucspi-unix Summary: UNIX-domain socket client-server command-line tools Version: 1.0 Release: 1 License: GPL Group: Utilities/System Source: http://untroubled.org/ucspi-unix/archive/ucspi-unix-%{version}.tar.gz BuildRoot: %{_tmppath}/ucspi-unix-root URL: http://untroubled.org/ucspi-unix/ Packager: Bruce Guenter %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 make %install rm -fr %{buildroot} make install prefix=%{buildroot} bindir=%{_bindir} mandir=%{_mandir} %clean rm -rf %{buildroot} %files %defattr(-,root,root) %doc COPYING NEWS PROTOCOL README TODO VERSION %{_bindir}/* %{_mandir}/*/* ucspi-unix-1.0/ANNOUNCEMENT0000664000076400007640000000321712562534004014644 0ustar bruceguenterVersion 1.0 of ucspi-unix is now available at: http://untroubled.org/ucspi-unix/ ------------------------------------------------------------------------------ Changes in version 1.0 - Dropped vestigal dependencies on bglibs. - Fixed unixclient closing wrong file descriptor when additional ones are open. 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 1.0 2015-08-11 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.untroubled.org A mailing list archive is available at: http://lists.untroubled.org/?list=bgware Development versions of ucspi-unix are available at GitHub: https://github.com/bruceg/ucspi-unix 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: - Run "make" - As root, run "make install" - To install in alternate locations, use: make install prefix=/usr bindir=/bin mandir=/share/man This program is Copyright(C) 2015 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-1.0/ChangeLog0000664000076400007640000000351412562534004014601 0ustar bruceguenter2000-10-22 Bruce Guenter * unixclient.c: #include sys/socket.h after sys/types.h to fix FreeBSD compile failures. * unixserver.c: #include sys/socket.h after sys/types.h to fix FreeBSD compile failures. 2000-08-25 Bruce Guenter * env.c (setup_env): Modified to not fail if getsockopt does not succeed. 2000-07-24 Bruce Guenter * Released version 0.33 2000-07-05 Bruce Guenter * Released version 0.32 * unixserver.c (make_socket): Set the umask before creating the socket. 2000-06-20 Bruce Guenter * Released version 0.31 * env.c (setup_env): Set "optlen" to prevent getsockopt from failing. * unixserver.c (use_gid,use_uid): Fixed a stupid typo in using the environment UID/GID strings. (main): Eliminated the use of exitfn, which caused the socket to be deleted after its first use. * Released version 0.30 * unixserver.c: Changed the default for "verbose" to off. * unixserver.c (parse_options): Parse UID and GID options. (make_socket): Do setgid and setuid if they are set. (parse_options): Added backlog and banner options. (start_child): Write the optional banner immediately. 2000-06-13 Bruce Guenter * unixclient.c (exec_program): Call the new setup_env. * unixserver.c (start_child): Call the new setup_env. * env.c (setup_env): Merged all the code used to setup environment variables into this one routine, used by both unixserver and unixclient. * unixserver.c: Added the necessary code to use SO_PEERCRED to retrieve socket credentials on Linux, as well as to set up the environment. (make_socket): Dynamically allocate the socket structure, to prevent problems with long socket path names. ucspi-unix-1.0/VERSION0000664000076400007640000000001712562534004014072 0ustar bruceguenterucspi-unix 1.0 ucspi-unix-1.0/AUTOFILES0000664000076400007640000000010112562534004014272 0ustar bruceguenterAUTOFILES Makefile SRCFILES TARGETS conf-cc conf-ld warn-auto.sh ucspi-unix-1.0/conf-cc0000664000076400007640000000007312562534004014257 0ustar bruceguentergcc -W -Wall -O -g This will be used to compile .c files. ucspi-unix-1.0/warn-auto.sh0000664000076400007640000000010012562534004015264 0ustar bruceguenter#!/bin/sh # WARNING: This file was auto-generated. Do not edit! ucspi-unix-1.0/unixserver.c0000664000076400007640000001707412562534004015413 0ustar bruceguenter#include #include #include #include #include #include #include #include #include #include "haswaitp.h" 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 unsigned 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) { ssize_t len = strlen(opt_banner); if(write(fd, opt_banner, len) != len) { perror("write"); exit(-1); } } 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-1.0/haspeercred.h10000664000076400007640000000016712562534004015547 0ustar bruceguenter/* sysdep: +struct ucred */ #define HASPEERCRED 1 #define _GNU_SOURCE 1 #include #include ucspi-unix-1.0/unixclient.c0000664000076400007640000000366612562534004015365 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"); if(fd != 6 && fd != 7) 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-1.0/NEWS0000664000076400007640000000545412562534004013533 0ustar bruceguenter------------------------------------------------------------------------------- Changes in version 1.0 - Dropped vestigal dependencies on bglibs. - Fixed unixclient closing wrong file descriptor when additional ones are open. Development of this version has been sponsored by FutureQuest, Inc. ossi@FutureQuest.net http://www.FutureQuest.net/ ------------------------------------------------------------------------------- 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-1.0/haspeercred.h00000664000076400007640000000003412562534004015537 0ustar bruceguenter/* sysdep: -struct ucred */ ucspi-unix-1.0/Makefile0000664000076400007640000000474412562534004014475 0ustar bruceguenter# Don't edit Makefile! Use conf-* for configuration. # # Generated by spac see http://untroubled.org/spac/ SHELL=/bin/sh DEFAULT: all all: libraries programs docs 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 -n 1 conf-cc` -I. '-o $${base}.o -c $$source $${1+"$$@"}'; \ ) >compile chmod 755 compile docs: unixclient.1.html unixserver.1.html env.o: compile env.c haspeercred.h ./compile env.c haspeercred.h: compile load haspeercred.h0 haspeercred.h1 trypeercred.c ( ( ./compile trypeercred.c && ./load trypeercred; ) && cat haspeercred.h1 || cat haspeercred.h0 ) > $@ @rm -f trypeercred.o trypeercred haswaitp.h: compile load haswaitp.h0 haswaitp.h1 trywaitp.c ( ( ./compile trywaitp.c && ./load trywaitp; ) && cat haswaitp.h1 || cat haswaitp.h0 ) > $@ @rm -f trywaitp.o trywaitp install: install -d $(or $(prefix),/usr/local)/$(or $(bindir),bin) install -m 755 unixcat unixclient unixserver $(or $(prefix),/usr)/$(or $(bindir),bin) install -d $(or $(prefix),/usr/local)/$(or $(mandir),man)/man1 install -m 644 unixclient.1 unixserver.1 $(or $(prefix),/usr)/$(or $(mandir),man)/man1 libraries: load: conf-ld ( echo '#!/bin/sh';\ echo 'main="$$1"; shift';\ echo exec `head -n 1 conf-ld` -L. '-o "$$main" "$$main.o" $${1+"$$@"}'; \ ) >load chmod 755 load programs: unixclient unixserver unixcat socket.lib: compile load @echo -n 'Checking for socket libraries: ' @echo 'main() { ; }' >trylib-lsocket.c @{ ./compile trylib-lsocket.c && ./load trylib-lsocket -lsocket -lnsl; } >/dev/null 2>&1 \ && { echo -lsocket -lnsl >socket.lib; echo -lsocket -lnsl; } \ || { : >socket.lib; echo no; } @rm -f trylib-lsocket.c trylib-lsocket.o trylib-lsocket unixcat: warn-auto.sh unixcat.sh cat warn-auto.sh unixcat.sh >unixcat chmod 755 unixcat unixclient: unixclient.o load env.o utoa.o socket.lib ./load unixclient env.o utoa.o `cat socket.lib` unixclient.1.html: unixclient.1 man --html='cat %s' ./unixclient.1 > unixclient.1.html unixclient.o: compile unixclient.c ./compile unixclient.c unixserver: unixserver.o load env.o utoa.o socket.lib ./load unixserver env.o utoa.o `cat socket.lib` unixserver.1.html: unixserver.1 man --html='cat %s' ./unixserver.1 > unixserver.1.html unixserver.o: compile unixserver.c haswaitp.h ./compile unixserver.c utoa.o: compile utoa.c ./compile utoa.c ucspi-unix-1.0/README0000664000076400007640000000222112562534004013701 0ustar bruceguenterucspi-unix UNIX-domain socket client-server command-line tools Bruce Guenter Version 1.0 2015-08-11 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.untroubled.org A mailing list archive is available at: http://lists.untroubled.org/?list=bgware Development versions of ucspi-unix are available at GitHub: https://github.com/bruceg/ucspi-unix 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: - Run "make" - As root, run "make install" - To install in alternate locations, use: make install prefix=/usr bindir=/bin mandir=/share/man This program is Copyright(C) 2015 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-1.0/unixclient.1.html0000664000076400007640000000601212562534004016232 0ustar bruceguenter UNIXCLIENT

UNIXCLIENT

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
SEE ALSO
AUTHOR

NAME

unixclient - UNIX domain socket client

SYNOPSIS

unixclient [options] socket program

DESCRIPTION

Unixclient is UNIX domain socket client that conform to UCSPI, the UNIX Client-Server Program Interface.

OPTIONS

−q

Quiet. Do not print any messages.

−Q

(default) Print error messages.

−v

Verbose. Print error and status messages. −c N Do not handle more than N simultaneous connections. (default 10)

SEE ALSO

unixserver(1), unixcat(1) http://cr.yp.to/proto/ucspi.txt

AUTHOR

ucspi-unix package was written by Bruce Guenter <bruceg@em.ca>

This manual page was originally written by Tomas Kuliavas <tokul@bigfoot.com> for the Debian GNU/Linux system, but may be used elsewhere under the GPL.