Imported Upstream version 2.4.3
[platform/upstream/audit.git] / tools / aulast / aulast-llist.h
1 /*
2 * aulast-llist.h - Header file for aulastlog-llist.c
3 * Copyright (c) 2008 Red Hat Inc., Durham, North Carolina.
4 * All Rights Reserved.
5 *
6 * This software may be freely redistributed and/or modified under the
7 * terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Authors:
21 *   Steve Grubb <sgrubb@redhat.com>
22 */
23
24 #ifndef AULASTLIST_HEADER
25 #define AULASTLIST_HEADER
26
27 #include <sys/types.h>
28
29
30 typedef enum { LOG_IN, SESSION_START, LOG_OUT, DOWN, CRASH, GONE } status_t; 
31
32 /* This is the node of the linked list. message & item are the only elements
33  * at this time. Any data elements that are per item goes here. */
34 typedef struct _lnode{
35   unsigned int session; // The kernel login session id
36   time_t start;         // first time uid logged in
37   time_t end;           // last time uid logged in
38   uid_t auid;           // user ID
39   int pid;              // pid of program logging in
40   const char *name;     // user name
41   const char *term;     // terminal name
42   const char *host;     // host where logging in from
43   int result;           // login results
44   status_t status;      // Current status of this session
45   unsigned long loginuid_proof; // audit serial number for loginuid change
46   unsigned long user_login_proof; // audit serial number for user login event
47   unsigned long  user_end_proof; // audit serial number for user log out event
48   struct _lnode* next;  // Next node pointer
49 } lnode;
50
51 /* This is the linked list head. Only data elements that are 1 per
52  * event goes here. */
53 typedef struct {
54   lnode *head;          // List head
55   lnode *cur;           // Pointer to current node
56 } llist;
57
58 void list_create(llist *l);
59 static inline void list_first(llist *l) { l->cur = l->head; }
60 lnode *list_next(llist *l);
61 static inline lnode *list_get_cur(llist *l) { return l->cur; }
62 void list_clear(llist* l);
63 int list_create_session(llist* l, uid_t auid, int pid, int session,
64                 unsigned long serial);
65 int list_update_start(llist* l, time_t start, const char *host,
66                 const char *term, int res, unsigned long serial);
67 int list_update_logout(llist* l, time_t t, unsigned long serial);
68 lnode *list_delete_cur(llist *l);
69
70 /* Given a uid, find that record. */
71 lnode *list_find_auid(llist *l, uid_t auid, int pid, unsigned int session);
72 lnode *list_find_session(llist *l, unsigned int session);
73
74 #endif
75