finger client for reactos
authorSteven Edwards <winehacker@gmail.com>
Mon, 28 Jan 2002 07:17:21 +0000 (07:17 +0000)
committerSteven Edwards <winehacker@gmail.com>
Mon, 28 Jan 2002 07:17:21 +0000 (07:17 +0000)
svn path=/trunk/; revision=2573

rosapps/net/finger/LICENSE.txt [new file with mode: 0644]
rosapps/net/finger/err.c [new file with mode: 0644]
rosapps/net/finger/err.h [new file with mode: 0644]
rosapps/net/finger/finger.c [new file with mode: 0644]
rosapps/net/finger/finger.rc [new file with mode: 0644]
rosapps/net/finger/getopt.c [new file with mode: 0644]
rosapps/net/finger/getopt.h [new file with mode: 0644]
rosapps/net/finger/makefile [new file with mode: 0644]
rosapps/net/finger/net.c [new file with mode: 0644]
rosapps/net/finger/unistd.h [new file with mode: 0644]
rosapps/net/finger/various.h [new file with mode: 0644]

diff --git a/rosapps/net/finger/LICENSE.txt b/rosapps/net/finger/LICENSE.txt
new file mode 100644 (file)
index 0000000..3f506f7
--- /dev/null
@@ -0,0 +1,23 @@
+July 22, 1999 
+
+To All Licensees, Distributors of Any Version of BSD: 
+
+As you know, certain of the Berkeley Software Distribution ("BSD") source code files 
+require that further distributions of products containing all or portions of the 
+software, acknowledge within their advertising materials that such products contain 
+software developed by UC Berkeley and its contributors. 
+
+Specifically, the provision reads: 
+
+      * 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.
+
+Effective immediately, licensees and distributors are no longer required to include 
+the acknowledgement within advertising materials. Accordingly, the foregoing paragraph 
+of those BSD Unix files containing it is hereby deleted in its entirety. 
+
+William Hoskins
+Director, Office of Technology Licensing
+University of California, Berkeley " 
diff --git a/rosapps/net/finger/err.c b/rosapps/net/finger/err.c
new file mode 100644 (file)
index 0000000..5f96668
--- /dev/null
@@ -0,0 +1,180 @@
+/*-
+ * Copyright (c) 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)err.c      8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+
+#include "err.h"
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+
+extern char *__progname;               /* Program name, from crt0. */
+
+void
+#ifdef __STDC__
+err(int eval, const char *fmt, ...)
+#else
+err(eval, fmt, va_alist)
+       int eval;
+       const char *fmt;
+       va_dcl
+#endif
+{
+       va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       verr(eval, fmt, ap);
+       va_end(ap);
+}
+
+void
+verr(int eval, const char *fmt, va_list ap)
+{
+       int sverrno;
+
+       sverrno = errno;
+       (void)fprintf(stderr, "%s: ", __progname);
+       if (fmt != NULL) {
+               (void)vfprintf(stderr, fmt, ap);
+               (void)fprintf(stderr, ": ");
+       }
+       (void)fprintf(stderr, "%s\n", strerror(sverrno));
+       exit(eval);
+}
+
+void
+#if __STDC__
+errx(int eval, const char *fmt, ...)
+#else
+errx(eval, fmt, va_alist)
+       int eval;
+       const char *fmt;
+       va_dcl
+#endif
+{
+       va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       verrx(eval, fmt, ap);
+       va_end(ap);
+}
+
+void
+verrx(int eval, const char *fmt, va_list ap)
+{
+       (void)fprintf(stderr, "%s: ", __progname);
+       if (fmt != NULL)
+               (void)vfprintf(stderr, fmt, ap);
+       (void)fprintf(stderr, "\n");
+       exit(eval);
+}
+
+void
+#if __STDC__
+warn(const char *fmt, ...)
+#else
+warn(fmt, va_alist)
+       const char *fmt;
+       va_dcl
+#endif
+{
+       va_list ap;
+#if __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       vwarn(fmt, ap);
+       va_end(ap);
+}
+
+void
+vwarn(fmt, ap)
+       const char *fmt;
+       va_list ap;
+{
+       int sverrno;
+
+       sverrno = errno;
+       (void)fprintf(stderr, "%s: ", __progname);
+       if (fmt != NULL) {
+               (void)vfprintf(stderr, fmt, ap);
+               (void)fprintf(stderr, ": ");
+       }
+       (void)fprintf(stderr, "%s\n", strerror(sverrno));
+}
+
+void
+#ifdef __STDC__
+warnx(const char *fmt, ...)
+#else
+warnx(fmt, va_alist)
+       const char *fmt;
+       va_dcl
+#endif
+{
+       va_list ap;
+#ifdef __STDC__
+       va_start(ap, fmt);
+#else
+       va_start(ap);
+#endif
+       vwarnx(fmt, ap);
+       va_end(ap);
+}
+
+void
+vwarnx(fmt, ap)
+       const char *fmt;
+       va_list ap;
+{
+       (void)fprintf(stderr, "%s: ", __progname);
+       if (fmt != NULL)
+               (void)vfprintf(stderr, fmt, ap);
+       (void)fprintf(stderr, "\n");
+}
diff --git a/rosapps/net/finger/err.h b/rosapps/net/finger/err.h
new file mode 100644 (file)
index 0000000..bbc7397
--- /dev/null
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 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.
+ *
+ *     @(#)err.h       8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _ERR_H_
+#define        _ERR_H_
+
+/*
+ * Don't use va_list in the err/warn prototypes.   Va_list is typedef'd in two
+ * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
+ * of them here we may collide with the utility's includes.  It's unreasonable
+ * for utilities to have to include one of them to include err.h, so we get
+ * _BSD_VA_LIST_ from <machine/ansi.h> and use it.
+ */
+/*#include <machine/ansi.h>*/
+/*#include <sys/cdefs.h>*/
+#include "various.h"
+#include <stdarg.h>
+
+void   err __P((int, const char *, ...));
+void   verr __P((int, const char *, va_list));
+void   errx __P((int, const char *, ...));
+void   verrx __P((int, const char *, va_list));
+void           warn __P((const char *, ...));
+void           vwarn __P((const char *, va_list));
+void           warnx __P((const char *, ...));
+void           vwarnx __P((const char *, va_list));
+
+#endif /* !_ERR_H_ */
diff --git a/rosapps/net/finger/finger.c b/rosapps/net/finger/finger.c
new file mode 100644 (file)
index 0000000..125f878
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
+ *
+ * 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.
+ *
+ * 8/2/97 - Ted Felix <tfelix@fred.net>
+ *          Ported to Win32 from 4.4BSD-LITE2 at wcarchive.
+ *          NT Workstation already has finger, and it runs fine under
+ *          Win95.  Thought I'd do this anyways since not everyone has
+ *          access to NT.
+ *          Had to remove local handling.       Otherwise, same as whois.
+ */
+
+#ifndef lint
+static char copyright[] =
+"@(#) Copyright (c) 1989, 1993\n\
+       The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)finger.c   8.5 (Berkeley) 5/4/95";
+#endif /* not lint */
+
+/*
+ * Finger prints out information about users.  It is not portable since
+ * certain fields (e.g. the full user name, office, and phone numbers) are
+ * extracted from the gecos field of the passwd file which other UNIXes
+ * may not have or may use for other things.
+ *
+ * There are currently two output formats; the short format is one line
+ * per user and displays login name, tty, login time, real name, idle time,
+ * and office location/phone number.  The long format gives the same
+ * information (in a more legible format) as well as home directory, shell,
+ * mail info, and .plan/.project files.
+ */
+
+#include <winsock2.h>
+#include "err.h"
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include "unistd.h"
+
+#include "various.h"
+#include "getopt.h"
+
+char *__progname;
+
+time_t now;
+int lflag, mflag, pplan, sflag;
+
+static void userlist(int, char **);
+void usage();
+void netfinger(char *);
+
+int
+main(int argc, char **argv)
+{
+       int ch;
+
+       while ((ch = getopt(argc, argv, "lmps")) != EOF)
+               switch(ch) {
+               case 'l':
+                       lflag = 1;              /* long format */
+                       break;
+               case 'm':
+                       mflag = 1;              /* force exact match of names */
+                       break;
+               case 'p':
+                       pplan = 1;              /* don't show .plan/.project */
+                       break;
+               case 's':
+                       sflag = 1;              /* short format */
+                       break;
+               case '?':
+               default:
+                       (void)fprintf(stderr,
+                           "usage: finger [-lmps] login [...]\n");
+                       exit(1);
+               }
+       argc -= optind;
+       argv += optind;
+
+       (void)time(&now);
+       if (!*argv) {
+               usage();
+       } else {
+               userlist(argc, argv);
+               /*
+                * Assign explicit "large" format if names given and -s not
+                * explicitly stated.  Force the -l AFTER we get names so any
+                * remote finger attempts specified won't be mishandled.
+                */
+               if (!sflag)
+                       lflag = 1;      /* if -s not explicit, force -l */
+       }
+       return 0;
+}
+
+
+static void
+userlist(int argc, char **argv)
+{
+       int *used;
+       char **ap, **nargv, **np, **p;
+       WORD wVersionRequested;
+       WSADATA wsaData;
+       int iErr;
+
+
+       if ((nargv = malloc((argc+1) * sizeof(char *))) == NULL ||
+           (used = calloc(argc, sizeof(int))) == NULL)
+               err(1, NULL);
+
+       /* Pull out all network requests into nargv. */
+       for (ap = p = argv, np = nargv; *p; ++p)
+               if (index(*p, '@'))
+                       *np++ = *p;
+               else
+                       *ap++ = *p;
+
+       *np++ = NULL;
+       *ap++ = NULL;
+
+       /* If there are local requests */
+       if (*argv)
+       {
+               fprintf(stderr, "Warning: Can't do local finger\n");
+       }
+
+       /* Start winsock */ 
+       wVersionRequested = MAKEWORD( 1, 1 );
+       iErr = WSAStartup( wVersionRequested, &wsaData );
+       if ( iErr != 0 ) 
+       {
+               /* Tell the user that we couldn't find a usable */
+               /* WinSock DLL.                                  */
+               fprintf(stderr, "WSAStartup failed\n");
+               return;
+       }
+
+       /* Handle network requests. */
+       for (p = nargv; *p;)
+               netfinger(*p++);
+
+       /* Bring down winsock */
+       WSACleanup();
+       exit(0);
+}
+
+void usage()
+{
+       (void)fprintf(stderr,
+                     "usage: finger [-lmps] login [...]\n");
+       exit(1);
+}
+
diff --git a/rosapps/net/finger/finger.rc b/rosapps/net/finger/finger.rc
new file mode 100644 (file)
index 0000000..cc50a37
--- /dev/null
@@ -0,0 +1,39 @@
+#include <defines.h>
+#include <reactos/resource.h>
+
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+
+VS_VERSION_INFO VERSIONINFO
+       FILEVERSION     RES_UINT_FV_MAJOR,RES_UINT_FV_MINOR,RES_UINT_FV_REVISION,RES_UINT_FV_BUILD
+       PRODUCTVERSION  RES_UINT_PV_MAJOR,RES_UINT_PV_MINOR,RES_UINT_PV_REVISION,RES_UINT_PV_BUILD      
+       FILEFLAGSMASK   0x3fL
+#ifdef _DEBUG
+       FILEFLAGS       0x1L
+#else
+       FILEFLAGS       0x0L
+#endif
+       FILEOS          0x40004L
+       FILETYPE        0x2L
+       FILESUBTYPE     0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "040904b0"
+        BEGIN
+            VALUE "CompanyName",       RES_STR_COMPANY_NAME
+            VALUE "FileDescription",   "ReactOS TCP/IPv4 Win32 finger\0"
+            VALUE "FileVersion",       RES_STR_FILE_VERSION
+            VALUE "InternalName",      "finger\0"
+            VALUE "LegalCopyright",    RES_STR_LEGAL_COPYRIGHT
+            VALUE "OriginalCopyright", "Steven Edwards (Isolation@users.sourceforge.net)\0"
+            VALUE "OriginalFilename",  "finger.exe\0"
+            VALUE "ProductName",       RES_STR_PRODUCT_NAME
+            VALUE "ProductVersion",    RES_STR_PRODUCT_VERSION
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        VALUE "Translation", 0x409, 1200
+    END
+END
+
diff --git a/rosapps/net/finger/getopt.c b/rosapps/net/finger/getopt.c
new file mode 100644 (file)
index 0000000..eacc86e
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 1987 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.
+ *
+ * Fri Jun 13 10:39:00 1997, tfelix@fred.net:
+ *     Ported to Win32, changed index/rindex to strchr/strrchr
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)getopt.c   4.13 (Berkeley) 2/23/91";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/*
+ * get option letter from argument vector
+ */
+int    opterr = 1,             /* if error message should be printed */
+       optind = 1,             /* index into parent argv vector */
+       optopt;                 /* character checked for validity */
+char   *optarg;                /* argument associated with option */
+
+#define        BADCH   (int)'?'
+#define        EMSG    ""
+
+int
+getopt(int nargc, char * const *nargv, const char *ostr)
+{
+       static char *place = EMSG;              /* option letter processing */
+       register char *oli;                     /* option letter list index */
+       char *p;
+
+       if (!*place) {                          /* update scanning pointer */
+               if (optind >= nargc || *(place = nargv[optind]) != '-') {
+                       place = EMSG;
+                       return(EOF);
+               }
+               if (place[1] && *++place == '-') {      /* found "--" */
+                       ++optind;
+                       place = EMSG;
+                       return(EOF);
+               }
+       }                                       /* option letter okay? */
+       if ((optopt = (int)*place++) == (int)':' ||
+           !(oli = strchr(ostr, optopt))) {
+               /*
+                * if the user didn't specify '-' as an option,
+                * assume it means EOF.
+                */
+               if (optopt == (int)'-')
+                       return(EOF);
+               if (!*place)
+                       ++optind;
+               if (opterr) {
+                       if (!(p = strrchr(*nargv, '/')))
+                               p = *nargv;
+                       else
+                               ++p;
+                       (void)fprintf(stderr, "%s: illegal option -- %c\n",
+                           p, optopt);
+               }
+               return(BADCH);
+       }
+       if (*++oli != ':') {                    /* don't need argument */
+               optarg = NULL;
+               if (!*place)
+                       ++optind;
+       }
+       else {                                  /* need an argument */
+               if (*place)                     /* no white space */
+                       optarg = place;
+               else if (nargc <= ++optind) {   /* no arg */
+                       place = EMSG;
+                       if (!(p = strrchr(*nargv, '/')))
+                               p = *nargv;
+                       else
+                               ++p;
+                       if (opterr)
+                               (void)fprintf(stderr,
+                                   "%s: option requires an argument -- %c\n",
+                                   p, optopt);
+                       return(BADCH);
+               }
+               else                            /* white space */
+                       optarg = nargv[optind];
+               place = EMSG;
+               ++optind;
+       }
+       return(optopt);                         /* dump back option letter */
+}
diff --git a/rosapps/net/finger/getopt.h b/rosapps/net/finger/getopt.h
new file mode 100644 (file)
index 0000000..bad5c84
--- /dev/null
@@ -0,0 +1,7 @@
+/* getopt.h */
+
+extern char *optarg;
+extern int optind;
+
+int
+getopt(int nargc, char * const *nargv, const char *ostr);
diff --git a/rosapps/net/finger/makefile b/rosapps/net/finger/makefile
new file mode 100644 (file)
index 0000000..a23770e
--- /dev/null
@@ -0,0 +1,23 @@
+
+PATH_TO_TOP=../../../reactos
+
+TARGET_TYPE = program
+
+TARGET_APPTYPE = console
+
+TARGET_NAME = finger
+
+TARGET_SDKLIBS = ws2_32.a
+
+TARGET_OBJECTS = $(TARGET_NAME).o \
+err.o \
+getopt.o \
+net.o 
+
+TARGET_GCCLIBS = iberty
+
+include $(PATH_TO_TOP)/rules.mak
+
+include $(TOOLS_PATH)/helper.mk
+
+# EOF
diff --git a/rosapps/net/finger/net.c b/rosapps/net/finger/net.c
new file mode 100644 (file)
index 0000000..3cf4bdb
--- /dev/null
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
+ *
+ * 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.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)net.c      8.4 (Berkeley) 4/28/95";
+#endif /* not lint */
+
+#include <sys/types.h>
+#include <winsock2.h>
+#include "unistd.h"
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "various.h"
+
+void
+netfinger(char *name)
+{
+       extern int lflag;
+       char c, lastc;
+       struct in_addr defaddr;
+       struct hostent *hp, def;
+       struct servent *sp;
+       struct sockaddr_in sin;
+       int s;
+       char *alist[1], *host;
+
+       /* If this is a local request */
+       if (!(host = rindex(name, '@')))
+               return;
+
+       *host++ = NULL;
+       if (isdigit(*host) && (defaddr.s_addr = inet_addr(host)) != -1) {
+               def.h_name = host;
+               def.h_addr_list = alist;
+               def.h_addr = (char *)&defaddr;
+               def.h_length = sizeof(struct in_addr);
+               def.h_addrtype = AF_INET;
+               def.h_aliases = 0;
+               hp = &def;
+       } else if (!(hp = gethostbyname(host))) {
+               (void)fprintf(stderr,
+                   "finger: unknown host: %s\n", host);
+               return;
+       }
+       if (!(sp = getservbyname("finger", "tcp"))) {
+               (void)fprintf(stderr, "finger: tcp/finger: unknown service\n");
+               return;
+       }
+       sin.sin_family = hp->h_addrtype;
+       bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
+       sin.sin_port = sp->s_port;
+       if ((s = socket(hp->h_addrtype, SOCK_STREAM, 0)) < 0) {
+               perror("finger: socket");
+               return;
+       }
+
+       /* have network connection; identify the host connected with */
+       (void)printf("[%s]\n", hp->h_name);
+       if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+               fprintf(stderr, "finger: connect rc = %d", WSAGetLastError());
+               (void)close(s);
+               return;
+       }
+
+       /* -l flag for remote fingerd  */
+       if (lflag)
+               send(s, "/W ", 3, 0);
+       /* send the name followed by <CR><LF> */
+       send(s, name, strlen(name), 0);
+       send(s, "\r\n", 2, 0);
+
+       /*
+        * Read from the remote system; once we're connected, we assume some
+        * data.  If none arrives, we hang until the user interrupts.
+        *
+        * If we see a <CR> or a <CR> with the high bit set, treat it as
+        * a newline; if followed by a newline character, only output one
+        * newline.
+        *
+        * Otherwise, all high bits are stripped; if it isn't printable and
+        * it isn't a space, we can simply set the 7th bit.  Every ASCII
+        * character with bit 7 set is printable.
+        */ 
+       lastc = 0;
+       while (recv(s, &c, 1, 0) == 1) {
+               c &= 0x7f;
+               if (c == 0x0d) {
+                       if (lastc == '\r')      /* ^M^M - skip dupes */
+                               continue;
+                       c = '\n';
+                       lastc = '\r';
+               } else {
+                       if (!isprint(c) && !isspace(c))
+                               c |= 0x40;
+                       if (lastc != '\r' || c != '\n')
+                               lastc = c;
+                       else {
+                               lastc = '\n';
+                               continue;
+                       }
+               }
+               putchar(c);
+       }
+       if (lastc != '\n')
+               putchar('\n');
+       putchar('\n');
+}
diff --git a/rosapps/net/finger/unistd.h b/rosapps/net/finger/unistd.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/rosapps/net/finger/various.h b/rosapps/net/finger/various.h
new file mode 100644 (file)
index 0000000..184f879
--- /dev/null
@@ -0,0 +1,53 @@
+// Various things you need when porting BSD and GNU utilities to
+// Win32.
+
+#ifndef VARIOUS_H
+#define VARIOUS_H
+
+/* types.h */
+typedef unsigned char u_char;
+typedef unsigned int u_int;
+typedef float f4byte_t;
+typedef double f8byte_t;
+//typedef __int16 s2byte_t;
+//typedef __int32 s4byte_t;
+//typedef __int64 s8byte_t;
+//typedef unsigned __int16 u2byte_t;
+//typedef unsigned __int32 u4byte_t;
+//typedef unsigned __int64 u8byte_t;
+//typedef __int32 quad_t;
+//typedef unsigned __int32 u_quad_t;
+//typedef unsigned __int16 u_int16_t;
+//typedef unsigned __int32 u_int32_t;
+
+typedef long uid_t;  // SunOS 5.5
+
+#define __P(x) x
+#define __STDC__ 1
+
+/* utmp.h */
+#define UT_LINESIZE 8
+#define UT_HOSTSIZE 16
+
+/* stat.h */
+#define  S_ISREG(mode)   (((mode)&0xF000) == 0x8000)
+#define  S_ISDIR(mode)   (((mode)&0xF000) == 0x4000)
+
+#define MIN(a, b) ((a) <= (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+#define bcopy(s1, s2, n)  memmove(s2, s1, n)
+#define bcmp(s1, s2, n)  (memcmp(s1, s2, n) != 0)
+#define bzero(s, n)  memset(s, 0, n)
+
+#define index(s, c)  strchr(s, c)
+#define rindex(s, c)  strrchr(s, c)
+
+//#ifndef _WINSOCKAPI_
+//struct timeval {
+//        long    tv_sec;         /* seconds */
+//        long    tv_usec;        /* and microseconds */
+//};
+//#endif
+
+#endif
\ No newline at end of file