Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars


   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*


  23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /*
  28  *      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
  29  *        All Rights Reserved
  30  */
  31 
  32 /*
  33  * University Copyright- Copyright (c) 1982, 1986, 1988
  34  * The Regents of the University of California
  35  * All Rights Reserved
  36  *
  37  * University Acknowledgment- Portions of this document are derived from
  38  * software developed by the University of California, Berkeley, and its
  39  * contributors.
  40  */
  41 
  42 #pragma ident   "%Z%%M% %I%     %E% SMI"
  43 
  44 /*
  45  * last
  46  */
  47 #include <sys/types.h>
  48 #include <stdio.h>
  49 #include <stdlib.h>
  50 #include <unistd.h>
  51 #include <strings.h>
  52 #include <signal.h>
  53 #include <sys/stat.h>
  54 #include <pwd.h>
  55 #include <fcntl.h>
  56 #include <utmpx.h>
  57 #include <locale.h>
  58 #include <ctype.h>
  59 
  60 /*
  61  * NMAX, LMAX and HMAX are set to these values for now. They
  62  * should be much higher because of the max allowed limit in
  63  * utmpx.h
  64  */
  65 #define NMAX    8
  66 #define LMAX    12
  67 #define HMAX    (sizeof (((struct utmpx *)0)->ut_host))





  68 #define SECDAY  (24*60*60)
  69 #define CHUNK_SIZE 256
  70 
  71 #define lineq(a, b)     (strncmp(a, b, LMAX) == 0)
  72 #define nameq(a, b)     (strncmp(a, b, NMAX) == 0)
  73 #define hosteq(a, b)    (strncmp(a, b, HMAX) == 0)
  74 #define linehostnameq(a, b, c, d) \
  75             (lineq(a, b)&&hosteq(a+LMAX+1, c)&&nameq(a+LMAX+HMAX+2, d))
  76 
  77 #define USAGE   "usage: last [-n number] [-f filename] [-a ] [name | tty] ...\n"
  78 
  79 /* Beware: These are set in main() to exclude the executable name.  */
  80 static char     **argv;
  81 static int      argc;
  82 static char     **names;
  83 static int      names_num;
  84 
  85 static struct   utmpx buf[128];
  86 
  87 /*


 273                                                 ut_user, NMAX+1);
 274                                                 record_time(&otime, &print,
 275                                                         i, bp);
 276                                                 break;
 277                                         } else if (linehostnameq(ttnames[i],
 278                                             bp->ut_line, ut_host, ut_user)) {
 279                                                 record_time(&otime,
 280                                                     &print, i, bp);
 281                                                 break;
 282                                         }
 283                                 }
 284                         }
 285                         if (print) {
 286                                 if (strncmp(bp->ut_line, "ftp", 3) == 0)
 287                                         bp->ut_line[3] = '\0';
 288                                 if (strncmp(bp->ut_line, "uucp", 4) == 0)
 289                                         bp->ut_line[4] = '\0';
 290 
 291                                 ct = ctime(&bp->ut_xtime);
 292                                 (void) printf(gettext("%-*.*s  %-*.*s "),
 293                                     NMAX, NMAX, bp->ut_name,
 294                                     LMAX, LMAX, bp->ut_line);
 295                                 hostf_len = strlen(bp->ut_host);
 296                                 (void) snprintf(hostf, sizeof (hostf),
 297                                     "%-*.*s", hostf_len, hostf_len,
 298                                     bp->ut_host);
 299                                 fpos = snprintf(timef, sizeof (timef),
 300                                         "%10.10s %5.5s ",
 301                                     ct, 11 + ct);
 302                                 if (!lineq(bp->ut_line, "system boot") &&
 303                                     !lineq(bp->ut_line, "system down")) {
 304                                         if (otime == 0 &&
 305                                             bp->ut_type == USER_PROCESS) {
 306 
 307         if (fpos < sizeof (timef)) {
 308                 /* timef still has room */
 309                 (void) snprintf(timef + fpos, sizeof (timef) - fpos,
 310                         gettext("  still logged in"));
 311         }
 312 
 313                                         } else {
 314                                         time_t delta;




   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License, Version 1.0 only
   6  * (the "License").  You may not use this file except in compliance
   7  * with the License.
   8  *
   9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10  * or http://www.opensolaris.org/os/licensing.
  11  * See the License for the specific language governing permissions
  12  * and limitations under the License.
  13  *
  14  * When distributing Covered Code, include this CDDL HEADER in each
  15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16  * If applicable, add the following below this CDDL HEADER, with the
  17  * fields enclosed by brackets "[]" replaced with your own identifying
  18  * information: Portions Copyright [yyyy] [name of copyright owner]
  19  *
  20  * CDDL HEADER END
  21  */
  22 /*
  23  * Copyright (c) 2013 Gary Mills
  24  *
  25  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  */
  28 
  29 /*
  30  *      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
  31  *        All Rights Reserved
  32  */
  33 
  34 /*
  35  * University Copyright- Copyright (c) 1982, 1986, 1988
  36  * The Regents of the University of California
  37  * All Rights Reserved
  38  *
  39  * University Acknowledgment- Portions of this document are derived from
  40  * software developed by the University of California, Berkeley, and its
  41  * contributors.
  42  */
  43 


  44 /*
  45  * last
  46  */
  47 #include <sys/types.h>
  48 #include <stdio.h>
  49 #include <stdlib.h>
  50 #include <unistd.h>
  51 #include <strings.h>
  52 #include <signal.h>
  53 #include <sys/stat.h>
  54 #include <pwd.h>
  55 #include <fcntl.h>
  56 #include <utmpx.h>
  57 #include <locale.h>
  58 #include <ctype.h>
  59 
  60 /*
  61  * Use the full lengths from utmpx for NMAX, LMAX and HMAX .


  62  */
  63 #define NMAX    (sizeof (((struct utmpx *)0)->ut_user))
  64 #define LMAX    (sizeof (((struct utmpx *)0)->ut_line))
  65 #define HMAX    (sizeof (((struct utmpx *)0)->ut_host))
  66 
  67 /* Print minimum field widths. */
  68 #define LOGIN_WIDTH     8
  69 #define LINE_WIDTH      12
  70 
  71 #define SECDAY  (24*60*60)
  72 #define CHUNK_SIZE 256
  73 
  74 #define lineq(a, b)     (strncmp(a, b, LMAX) == 0)
  75 #define nameq(a, b)     (strncmp(a, b, NMAX) == 0)
  76 #define hosteq(a, b)    (strncmp(a, b, HMAX) == 0)
  77 #define linehostnameq(a, b, c, d) \
  78             (lineq(a, b)&&hosteq(a+LMAX+1, c)&&nameq(a+LMAX+HMAX+2, d))
  79 
  80 #define USAGE   "usage: last [-n number] [-f filename] [-a ] [name | tty] ...\n"
  81 
  82 /* Beware: These are set in main() to exclude the executable name.  */
  83 static char     **argv;
  84 static int      argc;
  85 static char     **names;
  86 static int      names_num;
  87 
  88 static struct   utmpx buf[128];
  89 
  90 /*


 276                                             ut_user, NMAX+1);
 277                                                 record_time(&otime, &print,
 278                                                     i, bp);
 279                                                 break;
 280                                         } else if (linehostnameq(ttnames[i],
 281                                             bp->ut_line, ut_host, ut_user)) {
 282                                                 record_time(&otime,
 283                                                     &print, i, bp);
 284                                                 break;
 285                                         }
 286                                 }
 287                         }
 288                         if (print) {
 289                                 if (strncmp(bp->ut_line, "ftp", 3) == 0)
 290                                         bp->ut_line[3] = '\0';
 291                                 if (strncmp(bp->ut_line, "uucp", 4) == 0)
 292                                         bp->ut_line[4] = '\0';
 293 
 294                                 ct = ctime(&bp->ut_xtime);
 295                                 (void) printf(gettext("%-*.*s  %-*.*s "),
 296                                     LOGIN_WIDTH, NMAX, bp->ut_name,
 297                                     LINE_WIDTH, LMAX, bp->ut_line);
 298                                 hostf_len = strlen(bp->ut_host);
 299                                 (void) snprintf(hostf, sizeof (hostf),
 300                                     "%-*.*s", hostf_len, hostf_len,
 301                                     bp->ut_host);
 302                                 fpos = snprintf(timef, sizeof (timef),
 303                                     "%10.10s %5.5s ",
 304                                     ct, 11 + ct);
 305                                 if (!lineq(bp->ut_line, "system boot") &&
 306                                     !lineq(bp->ut_line, "system down")) {
 307                                         if (otime == 0 &&
 308                                             bp->ut_type == USER_PROCESS) {
 309 
 310         if (fpos < sizeof (timef)) {
 311                 /* timef still has room */
 312                 (void) snprintf(timef + fpos, sizeof (timef) - fpos,
 313                     gettext("  still logged in"));
 314         }
 315 
 316                                         } else {
 317                                         time_t delta;