File: utmp_init.c

package info (click to toggle)
inetutils 2%3A1.6-3.1%2Bsqueeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 8,972 kB
  • ctags: 7,360
  • sloc: ansic: 58,631; sh: 5,284; yacc: 1,151; makefile: 498; perl: 47
file content (105 lines) | stat: -rw-r--r-- 2,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/************************************************************************
* Copyright 1995 by Wietse Venema.  All rights reserved. Individual files
* may be covered by other copyrights (as noted in the file itself.)
*
* This material was originally written and compiled by Wietse Venema at
* Eindhoven University of Technology, The Netherlands, in 1990, 1991,
* 1992, 1993, 1994 and 1995.
*
* Redistribution and use in source and binary forms are permitted
* provided that this entire copyright notice is duplicated in all such
* copies.
*
* This software is provided "as is" and without any expressed or implied
* warranties, including, without limitation, the implied warranties of
* merchantibility and fitness for any particular purpose.
************************************************************************/
/* Author: Wietse Venema <wietse@wzv.win.tue.nl> */
/* light changes where done to accomodate libinetutils: Alain Magloire */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <sys/types.h>

#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#else
# include <time.h>
#endif
#ifdef HAVE_UTMPX_H
# ifndef __USE_GNU
#  define __USE_GNU
# endif
# include <utmpx.h>
#else
# include <utmp.h>
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
#include <unistd.h>

/* utmp_init - update utmp and wtmp before login */

void
utmp_init (char *line, char *user, char *id)
{
#ifdef HAVE_UTMPX_H
  struct utmpx utx;
#else
  struct utmp utx;
#endif

  memset ((char *) &utx, 0, sizeof (utx));
#if defined(HAVE_STRUCT_UTMP_UT_ID)
  strncpy (utx.ut_id, id, sizeof (utx.ut_id));
#endif
#if defined(HAVE_STRUCT_UTMP_UT_USER)
  strncpy (utx.ut_user, user, sizeof (utx.ut_user));
#else
  strncpy (utx.ut_name, user, sizeof (utx.ut_name));
#endif
  strncpy (utx.ut_line, line, sizeof (utx.ut_line));
#if defined(HAVE_STRUCT_UTMP_UT_PID)
  utx.ut_pid = getpid ();
#endif
#if defined(HAVE_STRUCT_UTMP_UT_TYPE)
  utx.ut_type = LOGIN_PROCESS;
#endif
#if defined(HAVE_STRUCT_UTMPX_UT_TV)
  gettimeofday (&(utx.ut_tv), 0);
#else
  time (&(utx.ut_time));
#endif
#ifdef HAVE_UTMPX_H
  pututxline (&utx);
# ifdef HAVE_UPDWTMPX
  updwtmpx (PATH_WTMPX, &utx);
# endif
  endutxent ();
#else
  pututline (&utx);
# ifdef HAVE_UPDWTMP
  updwtmp (PATH_WTMP, &utx);
# else
  logwtmp (line, user, id);
# endif
  endutent ();
#endif
}

/* utmp_ptsid - generate utmp id for pseudo terminal */

char *
utmp_ptsid (char *line, char *tag)
{
  static char buf[5];

  strncpy (buf, tag, 2);
  strncpy (buf + 2, line + strlen (line) - 2, 2);
  return (buf);
}