ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

finger.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1989, 1993
00003  *  The Regents of the University of California.  All rights reserved.
00004  *
00005  * This code is derived from software contributed to Berkeley by
00006  * Tony Nardo of the Johns Hopkins University/Applied Physics Lab.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. All advertising materials mentioning features or use of this software
00017  *    must display the following acknowledgement:
00018  *  This product includes software developed by the University of
00019  *  California, Berkeley and its contributors.
00020  * 4. Neither the name of the University nor the names of its contributors
00021  *    may be used to endorse or promote products derived from this software
00022  *    without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00025  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00027  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00030  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00031  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00033  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00034  * SUCH DAMAGE.
00035  *
00036  * 8/2/97 - Ted Felix <tfelix@fred.net>
00037  *          Ported to Win32 from 4.4BSD-LITE2 at wcarchive.
00038  *          NT Workstation already has finger, and it runs fine under
00039  *          Win95.  Thought I'd do this anyways since not everyone has
00040  *          access to NT.
00041  *          Had to remove local handling.    Otherwise, same as whois.
00042  */
00043 
00044 /*
00045  * Finger prints out information about users.  It is not portable since
00046  * certain fields (e.g. the full user name, office, and phone numbers) are
00047  * extracted from the gecos field of the passwd file which other UNIXes
00048  * may not have or may use for other things.
00049  *
00050  * There are currently two output formats; the short format is one line
00051  * per user and displays login name, tty, login time, real name, idle time,
00052  * and office location/phone number.  The long format gives the same
00053  * information (in a more legible format) as well as home directory, shell,
00054  * mail info, and .plan/.project files.
00055  */
00056 
00057 #include "precomp.h"
00058 
00059 char *__progname;
00060 
00061 time_t now;
00062 int lflag, mflag, pplan, sflag;
00063 
00064 static void userlist(int, char **);
00065 void usage();
00066 
00067 int
00068 main(int argc, char **argv)
00069 {
00070     int ch;
00071 
00072     while ((ch = getopt(argc, argv, "lmps")) != EOF)
00073         switch(ch) {
00074         case 'l':
00075             lflag = 1;      /* long format */
00076             break;
00077         case 'm':
00078             mflag = 1;      /* force exact match of names */
00079             break;
00080         case 'p':
00081             pplan = 1;      /* don't show .plan/.project */
00082             break;
00083         case 's':
00084             sflag = 1;      /* short format */
00085             break;
00086         case '?':
00087         default:
00088             (void)fprintf(stderr,
00089                 "usage: finger [-lmps] login [...]\n");
00090             exit(1);
00091         }
00092     argc -= optind;
00093     argv += optind;
00094 
00095     (void)time(&now);
00096     if (!*argv) {
00097         usage();
00098     } else {
00099         userlist(argc, argv);
00100         /*
00101          * Assign explicit "large" format if names given and -s not
00102          * explicitly stated.  Force the -l AFTER we get names so any
00103          * remote finger attempts specified won't be mishandled.
00104          */
00105         if (!sflag)
00106             lflag = 1;  /* if -s not explicit, force -l */
00107     }
00108     return 0;
00109 }
00110 
00111 
00112 static void
00113 userlist(int argc, char **argv)
00114 {
00115     int *used = NULL;
00116     char **ap, **nargv, **np, **p;
00117     WORD wVersionRequested;
00118     WSADATA wsaData;
00119     int iErr;
00120 
00121 
00122     if ((nargv = (char**) malloc((argc+1) * sizeof(char *))) == NULL ||
00123         (used = (int*) calloc(argc, sizeof(int))) == NULL)
00124         err(1, NULL);
00125 
00126     /* Pull out all network requests into nargv. */
00127     for (ap = p = argv, np = nargv; *p; ++p)
00128         if (index(*p, '@'))
00129             *np++ = *p;
00130         else
00131             *ap++ = *p;
00132 
00133     *np++ = NULL;
00134     *ap++ = NULL;
00135 
00136     /* If there are local requests */
00137     if (*argv)
00138     {
00139         fprintf(stderr, "Warning: Can't do local finger\n");
00140     }
00141 
00142     /* Start winsock */
00143     wVersionRequested = MAKEWORD( 1, 1 );
00144     iErr = WSAStartup( wVersionRequested, &wsaData );
00145     if ( iErr != 0 )
00146     {
00147         /* Tell the user that we couldn't find a usable */
00148         /* WinSock DLL.                                  */
00149         fprintf(stderr, "WSAStartup failed\n");
00150         return;
00151     }
00152 
00153     /* Handle network requests. */
00154     for (p = nargv; *p;)
00155         netfinger(*p++);
00156 
00157     /* Bring down winsock */
00158     WSACleanup();
00159     free(nargv);
00160     free(used);
00161     exit(0);
00162 }
00163 
00164 void usage()
00165 {
00166     (void)fprintf(stderr,
00167                   "usage: finger [-lmps] login [...]\n");
00168     exit(1);
00169 }
00170 

Generated on Sat May 26 2012 04:16:07 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.