~ubuntu-branches/ubuntu/utopic/audit/utopic

« back to all changes in this revision

Viewing changes to tools/aulast/aulast.c

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Matthias Hahn
  • Date: 2009-04-07 00:03:54 UTC
  • mfrom: (1.2.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20090407000354-ny4m29eckoycogz5
Tags: 1.7.12-1
* New upstream release. (Closes: #522026)
* Fix "typo in long description: (Closes: #513937)
* debian/control:
  - Bump Standards-Version: 3.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * aulast.c - A last program based on audit logs 
3
 
 * Copyright (c) 2008 Red Hat Inc., Durham, North Carolina.
 
3
 * Copyright (c) 2008-2009 Red Hat Inc., Durham, North Carolina.
4
4
 * All Rights Reserved.
5
5
 *
6
6
 * This software may be freely redistributed and/or modified under the
36
36
static FILE *f = NULL;
37
37
 
38
38
/* command line params */
39
 
static int cuid = -1, bad = 0, proof = 0;
 
39
static int cuid = -1, bad = 0, proof = 0, debug = 0;
40
40
static char *cterm = NULL;
41
41
 
42
42
void usage(void)
43
43
{
44
 
        fprintf(stderr, "usage: aulast [-f file] [user name] [tty]\n");
 
44
        fprintf(stderr,
 
45
 "usage: aulast [--stdin] [--proof] [--extract] [-f file] [user name] [tty]\n");
45
46
}
46
47
 
47
48
/* This outputs a line of text reporting the login/out times */
167
168
                ses = auparse_get_field_int(au);
168
169
 
169
170
        // Check that they are valid
170
 
        if (pid == -1 || auid ==-1 || ses == -1)
 
171
        if (pid == -1 || auid ==-1 || ses == -1) {
 
172
                if (debug)
 
173
                        fprintf(stderr, "Bad login for event: %lu\n",
 
174
                                        auparse_get_serial(au));
171
175
                return;
 
176
        }
172
177
 
173
178
        // See if this session is already open
174
179
        //cur = list_find_auid(&l, auid, pid, ses);
183
188
 
184
189
        // If this is supposed to be limited to a specific
185
190
        // uid and we don't have that record, skip creating it
186
 
        if (cuid != -1 && cuid != auid)
 
191
        if (cuid != -1 && cuid != auid) {
 
192
                if (debug)
 
193
                        fprintf(stderr,
 
194
                            "login reporting limited to %d for event: %lu\n",
 
195
                                cuid, auparse_get_serial(au));
187
196
                return;
 
197
        }
188
198
 
189
199
        list_create_session(&l, auid, pid, ses, auparse_get_serial(au));
190
200
}
207
217
                ses = auparse_get_field_int(au);
208
218
 
209
219
        // Get second uid field - we should be positioned past the first one
 
220
        // gdm sends uid, everything else sends id, we try acct as last resort
210
221
        tuid = auparse_find_field(au, "uid");
211
222
        if (tuid)
212
223
                uid = auparse_get_field_int(au);
213
 
        else
 
224
        else {
214
225
                auparse_first_record(au);
 
226
                tuid = auparse_find_field(au, "id");
 
227
                if (tuid)
 
228
                        uid = auparse_get_field_int(au);
 
229
                else {
 
230
                        auparse_first_record(au);
 
231
                        tuid = auparse_find_field(au, "acct");
 
232
                        if (tuid) {
 
233
                                const char *tacct = auparse_interpret_field(au);
 
234
                                struct passwd *pw = getpwnam (tacct);
 
235
                                if (pw != NULL)
 
236
                                        uid = pw->pw_uid;
 
237
                        } else
 
238
                                auparse_first_record(au);
 
239
                }
 
240
        }
215
241
 
216
242
        start = auparse_get_time(au);
217
243
 
237
263
                        tacct = auparse_interpret_field(au);
238
264
        } else {
239
265
                // Check that they are valid
240
 
                if (pid == -1 || uid ==-1 || ses == -1) 
 
266
                if (pid == -1 || uid ==-1 || ses == -1) { 
 
267
                        if (debug)
 
268
                                fprintf(stderr,
 
269
                                        "Bad user login for event: %lu\n",
 
270
                                        auparse_get_serial(au));
241
271
                        return;
 
272
                }
242
273
        }
243
274
 
244
275
        // See if this session is already open
252
283
                // the terminal of interest, delete the current node
253
284
                if (cterm && strstr(term, cterm) == NULL) {
254
285
                        list_delete_cur(&l);
 
286
                        if (debug)
 
287
                                fprintf(stderr,
 
288
                                "User login limited to %s for event: %lu\n",
 
289
                                        cterm, auparse_get_serial(au));
255
290
                        return;
256
291
                }
257
292
 
304
339
                ses = auparse_get_field_int(au);
305
340
 
306
341
        // Check that they are valid
307
 
        if (pid == -1 || auid ==-1 || ses == -1)
 
342
        if (pid == -1 || auid ==-1 || ses == -1) {
 
343
                if (debug)
 
344
                        fprintf(stderr, "Bad user logout for event: %lu\n",
 
345
                                        auparse_get_serial(au));
308
346
                return;
 
347
        }
309
348
 
310
349
        // See if this session is already open
311
350
        cur = list_find_auid(&l, auid, pid, ses);
317
356
                        time_t end = auparse_get_time(au);
318
357
                        list_update_logout(&l, end, auparse_get_serial(au));
319
358
                        report_session(cur);
320
 
                }
 
359
                } else if (debug)
 
360
                        fprintf(stderr, "start time error for event: %lu\n",
 
361
                                        auparse_get_serial(au));
321
362
                list_delete_cur(&l);
322
363
        }
323
364
}
395
436
        struct passwd *p;
396
437
        auparse_state_t *au;
397
438
 
 
439
        setlocale (LC_ALL, "");
398
440
        for (i=1; i<argc; i++) {
399
441
                if (argv[i][0] != '-') {
400
442
                        //take input and lookup as if it were a user name
435
477
                                        fprintf(stderr, "file already given\n");
436
478
                                        return 1;
437
479
                                }
 
480
                        } else if (strcmp(argv[i], "--debug") == 0) {
 
481
                                debug = 1;
438
482
                        } else {
439
483
                                usage();
440
484
                                return 1;
441
485
                        }
442
486
                }
443
487
        }
444
 
 
445
 
        setlocale (LC_ALL, "");
446
488
        list_create(&l);
447
489
 
448
490
        // Search for successful user logins