~ubuntu-branches/ubuntu/saucy/libpam-unix2/saucy

« back to all changes in this revision

Viewing changes to src/unix_sess.c

  • Committer: Package Import Robot
  • Author(s): Petter Reinholdtsen
  • Date: 2013-07-01 09:10:06 UTC
  • mfrom: (1.1.5) (3.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20130701091006-ow1d723ztam3abhk
Tags: 1:2.6-1
* QA upload.
* New upstream version.
* New patch 05_glibc216.diff to get the source to build with the
  new glibc version without the locking functions used
  (Closes: #701308).  Thanks to Andreas Jaeger for the patch
  and Thorsten Kukuk for letting me know where to find it.
* New patch 06_format_security.diff to fix format issue with
  pam_sysloc() call.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2006 SUSE Linux Products GmbH Nuernberg,Germany.
 
2
 * Copyright (c) 2006, 2008 SUSE Linux Products GmbH Nuernberg,Germany.
3
3
 * Copyright (c) 1999, 2000, 2002, 2003, 2004 SuSE GmbH Nuernberg, Germany.
4
4
 * Author: Thorsten Kukuk <kukuk@suse.de>
5
5
 *
52
52
 
53
53
#include "public.h"
54
54
 
 
55
static int
 
56
pam_log_session (pam_handle_t *pamh, int flags, int argc,
 
57
                 const char **argv, const char *kind)
 
58
{
 
59
  int retval;
 
60
  const char *name;
 
61
  char *service, *tty, *rhost;
 
62
  options_t options;
 
63
  char *logmsg = NULL;
 
64
 
 
65
  memset (&options, 0, sizeof (options));
 
66
  options.log_level = -1; /* Initialize to default "none".  */
 
67
 
 
68
  if (get_options (pamh, &options, "session", argc, argv) < 0)
 
69
    {
 
70
      pam_syslog (pamh, LOG_ERR, "cannot get options");
 
71
      return PAM_SYSTEM_ERR;
 
72
    }
 
73
 
 
74
  /* get the user name */
 
75
  if ((retval = pam_get_user (pamh, &name, NULL)) != PAM_SUCCESS)
 
76
    return retval;
 
77
 
 
78
  if (name == NULL || name[0] == '\0')
 
79
    return PAM_SESSION_ERR;
 
80
 
 
81
  /* Move this after getting the user name, else PAM test suite
 
82
     will not pass ... */
 
83
  if (options.log_level == -1)
 
84
    return PAM_SUCCESS;
 
85
 
 
86
  retval = pam_get_item (pamh, PAM_SERVICE, (void *) &service);
 
87
  if (retval != PAM_SUCCESS)
 
88
    return retval;
 
89
  if (service == NULL)
 
90
    return PAM_CONV_ERR;
 
91
 
 
92
  retval = pam_get_item(pamh, PAM_TTY, (void *) &tty);
 
93
  if (retval !=PAM_SUCCESS)
 
94
    return retval;
 
95
 
 
96
  retval = pam_get_item(pamh, PAM_RHOST, (void *) &rhost);
 
97
  if (retval !=PAM_SUCCESS)
 
98
    return retval;
 
99
 
 
100
  if (tty && !rhost)
 
101
    {
 
102
      if (asprintf (&logmsg, "session %s for user %s: service=%s, tty=%s",
 
103
                    kind, name, service, tty) == -1)
 
104
        return PAM_SESSION_ERR;
 
105
    }
 
106
  else if (!tty && rhost)
 
107
    {
 
108
      if (asprintf (&logmsg,
 
109
                    "session %s for user %s: service=%s, rhost=%s",
 
110
                    kind, name, service, rhost) == -1)
 
111
        return PAM_SESSION_ERR;
 
112
    }
 
113
  else if (tty && rhost)
 
114
    {
 
115
      if (asprintf (&logmsg,
 
116
                    "session %s for user %s: service=%s, tty=%s, rhost=%s",
 
117
                    kind, name, service, tty, rhost) == -1)
 
118
        return PAM_SESSION_ERR;
 
119
    }
 
120
  else
 
121
    {
 
122
      if (asprintf (&logmsg, "session %s for user %s: service=%s",
 
123
                    kind, name, service) == -1)
 
124
        return PAM_SESSION_ERR;
 
125
    }
 
126
 
 
127
  pam_syslog (pamh, options.log_level, "%s", logmsg);
 
128
  free (logmsg);
 
129
 
 
130
  return PAM_SUCCESS;
 
131
}
 
132
 
55
133
int
56
134
pam_sm_open_session (pam_handle_t *pamh, int flags, int argc,
57
135
                     const char **argv)
58
136
{
59
 
  int retval;
60
 
  const char *name;
61
 
  char *service;
62
 
  options_t options;
63
 
 
64
 
  memset (&options, 0, sizeof (options));
65
 
  options.log_level = -1; /* Initialize to default "none".  */
66
 
 
67
 
  if (get_options (pamh, &options, "session", argc, argv) < 0)
68
 
    {
69
 
      pam_syslog (pamh, LOG_ERR, "cannot get options");
70
 
      return PAM_SYSTEM_ERR;
71
 
    }
72
 
 
73
 
  /* get the user name */
74
 
  if ((retval = pam_get_user (pamh, &name, NULL)) != PAM_SUCCESS)
75
 
    return retval;
76
 
 
77
 
  if (name == NULL || name[0] == '\0')
78
 
    return PAM_SESSION_ERR;
79
 
 
80
 
  /* Move this after getting the user name, else PAM test suite
81
 
     will not pass ... */
82
 
  if (options.log_level == -1)
83
 
    return PAM_SUCCESS;
84
 
 
85
 
  retval = pam_get_item (pamh, PAM_SERVICE, (void *) &service);
86
 
  if (retval != PAM_SUCCESS)
87
 
    return retval;
88
 
  if (service == NULL)
89
 
    return PAM_CONV_ERR;
90
 
 
91
 
  pam_syslog (pamh, options.log_level,
92
 
              "session started for user %s, service %s\n",
93
 
              name, service);
94
 
 
95
 
  return PAM_SUCCESS;
 
137
  return pam_log_session (pamh, flags, argc, argv, "started");
96
138
}
97
139
 
98
140
int
99
141
pam_sm_close_session (pam_handle_t * pamh, int flags,
100
142
                      int argc, const char **argv)
101
143
{
102
 
  int retval;
103
 
  const char *name;
104
 
  char *service;
105
 
  options_t options;
106
 
 
107
 
  memset (&options, 0, sizeof (options));
108
 
  options.log_level = -1; /* Initialize to default "none".  */
109
 
 
110
 
  if (get_options (pamh, &options, "session", argc, argv) < 0)
111
 
    {
112
 
      pam_syslog (pamh, LOG_ERR, "cannot get options");
113
 
      return PAM_SYSTEM_ERR;
114
 
    }
115
 
 
116
 
  /* get the user name */
117
 
  if ((retval = pam_get_user (pamh, &name, NULL)) != PAM_SUCCESS)
118
 
    return retval;
119
 
 
120
 
  if (name == NULL || name[0] == '\0')
121
 
    return PAM_SESSION_ERR;
122
 
 
123
 
  /* Move this after getting the user name, else PAM test suite
124
 
     will not pass ... */
125
 
  if (options.log_level == -1)
126
 
    return PAM_SUCCESS;
127
 
 
128
 
  retval = pam_get_item (pamh, PAM_SERVICE, (void *) &service);
129
 
  if (retval != PAM_SUCCESS)
130
 
    return retval;
131
 
  if (service == NULL)
132
 
    return PAM_CONV_ERR;
133
 
 
134
 
  pam_syslog (pamh, options.log_level,
135
 
              "session finished for user %s, service %s\n",
136
 
              name, service);
137
 
 
138
 
  return PAM_SUCCESS;
 
144
  return pam_log_session (pamh, flags, argc, argv, "finished");
139
145
}