~ubuntu-branches/ubuntu/utopic/acct/utopic

« back to all changes in this revision

Viewing changes to last.c

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2010-08-05 00:08:34 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20100805000834-y9k7nlasjm3t5che
Tags: 6.5.4-2ubuntu1
* Merge from Debian testing, remaining changes: (LP: #609754)
  - Remove stop links from rc0 and rc6. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
Copyright (C) 1993, 1996, 1997, 2003, 2008, 2009 Free Software Foundation, Inc.
 
2
Copyright (C) 1993, 1996, 1997, 2003, 2008, 2009, 2010 Free Software Foundation, Inc.
3
3
 
4
4
This file is part of the GNU Accounting Utilities
5
5
 
52
52
#endif
53
53
 
54
54
#include "common.h"
 
55
#include "files.h"
55
56
#include "utmp_rd.h"
56
57
#ifdef HAVE_GETOPT_LONG_ONLY
57
58
#include <getopt.h>
113
114
                                   this by default, but we should have
114
115
                                   a flag for it */
115
116
 
116
 
#ifdef HAVE_UT_TYPE
 
117
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
117
118
int print_which_recs = 0;       /* If 0, only print the usual.  If 1,
118
119
                                   print run level information,
119
120
                                   shutdowns, and time changes.  If 2
121
122
                                   business. */
122
123
#endif
123
124
 
124
 
#ifdef HAVE_UT_ADDR
 
125
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
125
126
int print_addresses = 0;        /* should we print the ut_addr field? */
126
127
#endif
127
128
 
147
148
struct hashtab *login_table = NULL;
148
149
 
149
150
struct login_data
150
 
  {
151
 
    time_t time;
152
 
    short fake_entry;
153
 
  };
154
 
 
155
 
/* prototypes */
156
 
 
157
 
void log_everyone_in PARAMS((time_t));
158
 
void give_usage PARAMS((void));
159
 
void parse_entries PARAMS((void));
160
 
void update_system_time PARAMS((time_t));
161
 
void log_out PARAMS((struct utmp *entry, short fake_flag));
162
 
void log_in PARAMS((struct utmp *));
163
 
void print_record PARAMS((struct utmp *, time_t logout_time,
164
 
                          char *, char *, char *));
165
 
void display_date PARAMS((time_t now));
 
151
{
 
152
  time_t time;
 
153
  short fake_entry;
 
154
};
 
155
 
 
156
void log_everyone_in (time_t);
 
157
void update_system_time (time_t);
 
158
void log_out (struct utmp *entry, short fake_flag);
 
159
void log_in (struct utmp *);
 
160
void print_record (struct utmp *, time_t logout_time,
 
161
                   char *, char *, char *);
 
162
void display_date (time_t now);
166
163
 
167
164
#if defined (SVR4) && !defined (_POSIX_SOURCE)
168
 
RETSIGTYPE handler PARAMS((int, int, struct sigcontext *));
 
165
RETSIGTYPE handler (int, int, struct sigcontext *);
169
166
#else
170
 
RETSIGTYPE handler PARAMS((int));
 
167
RETSIGTYPE handler (int);
171
168
#endif
172
169
 
173
170
/* code */
216
213
      int option_index = 0;
217
214
 
218
215
      static struct option long_options[] =
219
 
        {
220
 
          { "complain", no_argument, NULL, 1
221
 
          },
222
 
          { "lines", required_argument, NULL, 3 },
223
 
          { "debug", no_argument, NULL, 4 },
224
 
          { "tw-leniency", required_argument, NULL, 5 },
225
 
          { "version", no_argument, NULL, 6 },
226
 
          { "help", no_argument, NULL, 7 },
227
 
          { "file", required_argument, NULL, 8 },
228
 
          { "no-truncate-ftp-entries", no_argument, NULL, 9 },
229
 
#ifdef HAVE_UT_TYPE
230
 
          { "all-records", no_argument, NULL, 10 },
231
 
#endif
232
 
#ifdef HAVE_UT_ADDR
233
 
          { "ip-address", no_argument, NULL, 11 },
234
 
#endif
235
 
          { "print-year", no_argument, NULL, 12 },
236
 
#ifdef HAVE_UT_TYPE
237
 
          { "more-records", no_argument, NULL, 13 },
238
 
#endif
239
 
          { "tw-suspicious", required_argument, NULL, 14 },
240
 
          { "print-seconds", no_argument, NULL, 15 },
241
 
          { "wide", no_argument, NULL, 16 },
242
 
          { 0, 0, 0, 0 }
243
 
        };
 
216
      {
 
217
        { "complain", no_argument, NULL, 1
 
218
        },
 
219
        { "lines", required_argument, NULL, 3 },
 
220
        { "debug", no_argument, NULL, 4 },
 
221
        { "tw-leniency", required_argument, NULL, 5 },
 
222
        { "version", no_argument, NULL, 6 },
 
223
        { "help", no_argument, NULL, 7 },
 
224
        { "file", required_argument, NULL, 8 },
 
225
        { "no-truncate-ftp-entries", no_argument, NULL, 9 },
 
226
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
 
227
        { "all-records", no_argument, NULL, 10 },
 
228
#endif
 
229
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
 
230
        { "ip-address", no_argument, NULL, 11 },
 
231
#endif
 
232
        { "print-year", no_argument, NULL, 12 },
 
233
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
 
234
        { "more-records", no_argument, NULL, 13 },
 
235
#endif
 
236
        { "tw-suspicious", required_argument, NULL, 14 },
 
237
        { "print-seconds", no_argument, NULL, 15 },
 
238
        { "wide", no_argument, NULL, 16 },
 
239
        { 0, 0, 0, 0 }
 
240
      };
244
241
 
245
242
      c = getopt_long (argc, argv,
246
 
#ifdef HAVE_UT_TYPE
 
243
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
247
244
                       "a"
248
245
#endif
249
 
#ifdef HAVE_UT_ADDR
 
246
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
250
247
                       "i"
251
248
#endif
252
249
                       "f:n:s"
253
 
#ifdef HAVE_UT_TYPE
 
250
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
254
251
                       "x"
255
252
#endif
256
253
                       "wyV",
292
289
        case 9:
293
290
          truncate_ftp_entries = 0;
294
291
          break;
295
 
#ifdef HAVE_UT_TYPE
 
292
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
296
293
        case 'a':
297
294
        case 10:
298
295
          print_which_recs = 2;
299
296
          break;
300
297
#endif
301
 
#ifdef HAVE_UT_ADDR
 
298
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
302
299
        case 'i':
303
300
        case 11:
304
301
          print_addresses = 1;
308
305
        case 12:
309
306
          print_year = 1;
310
307
          break;
311
 
#ifdef HAVE_UT_TYPE
 
308
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
312
309
        case 'x':
313
310
        case 13:
314
311
          print_which_recs = 1;
368
365
 
369
366
          optind++;
370
367
 
371
 
#ifdef HAVE_UT_TYPE
 
368
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
372
369
          if (!print_which_recs)
373
370
            print_which_recs = 1;
374
371
#endif
402
399
{
403
400
  (void)printf("\
404
401
                Usage: %s [-"
405
 
#ifdef HAVE_UT_TYPE
 
402
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
406
403
               "a"
407
404
#endif
408
 
#ifdef HAVE_UT_ADDR
 
405
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
409
406
               "i"
410
407
#endif
411
408
               "hs"
412
 
#ifdef HAVE_UT_TYPE
 
409
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
413
410
               "x"
414
411
#endif
415
412
               "yV] [-<lines>] [-n <lines>] [-f <file>] [people] [ttys] ...\n\
417
414
                [--version] [--tw-leniency <value>] [--tw-suspicious <value>]\n\
418
415
                [--no-truncate-ftp-entries] [--print-year] [--print-seconds]\n\
419
416
                "
420
 
#ifdef HAVE_UT_TYPE
 
417
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
421
418
               "[--more-records] [--all-records] "
422
419
#endif
423
 
#ifdef HAVE_UT_ADDR
 
420
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
424
421
               "[--ip-address] "
425
422
#endif
426
423
               "[--help]\n", program_name);
500
497
 
501
498
  /* Match the most recent login on the terminal. */
502
499
 
503
 
  he = hashtab_find (login_table, entry->ut_line, TTY_LEN);
 
500
  he = hashtab_find (login_table, entry->ut_line, (unsigned int)TTY_LEN);
504
501
 
505
502
  if (he != NULL)
506
503
    {
552
549
      return;
553
550
    }
554
551
 
555
 
  he = hashtab_find (login_table, entry->ut_line, TTY_LEN);
 
552
  he = hashtab_find (login_table, entry->ut_line, (unsigned int)TTY_LEN);
556
553
 
557
554
  if (he != NULL)
558
555
    {
606
603
     items. */
607
604
 
608
605
  if (! ((names == NULL)
609
 
         || hashtab_find (names, login->ut_name, NAME_LEN)
610
 
         || hashtab_find (names, login->ut_line, TTY_LEN)))
 
606
         || hashtab_find (names, login->ut_name, (unsigned int)NAME_LEN)
 
607
         || hashtab_find (names, login->ut_line, (unsigned int)TTY_LEN)))
611
608
    return;                     /* don't want to print this record */
612
609
 
613
610
 
614
611
  /* Choose replacement names, if provided.  Don't do this if we're on
615
612
     a BSD system. */
616
613
 
617
 
#ifdef HAVE_UT_TYPE
 
614
#ifdef HAVE_STRUCT_UTMP_UT_TYPE
618
615
  if (replacement_tty)
619
616
    print_tty = replacement_tty;
620
617
  else
632
629
  {
633
630
    int i = 0;
634
631
 
635
 
    for (;(print_tty[i] != '\0') && (i < TTY_LEN); i++)
 
632
    for (; (print_tty[i] != '\0') && (i < TTY_LEN); i++)
636
633
      sanitized_tty[i] = (isprint (print_tty[i]) && isascii (print_tty[i])
637
634
                          ? print_tty[i]
638
635
                          : '?');
647
644
               print_tty_len, print_tty_len, sanitized_tty);
648
645
 
649
646
 
650
 
#ifdef HAVE_UT_ADDR
 
647
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
651
648
  if (print_addresses)
652
649
    {
653
650
      struct in_addr a;
656
653
    }
657
654
#endif
658
655
 
659
 
#ifdef HAVE_UT_HOST
660
 
#ifdef HAVE_UT_ADDR
 
656
#ifdef HAVE_STRUCT_UTMP_UT_HOST
 
657
#ifdef HAVE_STRUCT_UTMP_UT_ADDR
661
658
  /* If we have both HOST and ADDR, only print one, or else we go
662
659
         beyond 80 characters in width. */
663
660
  if (!print_addresses)
754
751
    {
755
752
      num_lines_to_print--;
756
753
      if (num_lines_to_print == 0)    /* max lines printed */
757
 
        exit (0);
 
754
        exit(EXIT_SUCCESS);
758
755
    }
759
756
}
760
757