~ubuntu-branches/ubuntu/natty/freeradius/natty-updates

« back to all changes in this revision

Viewing changes to src/modules/rlm_pam/rlm_pam.c

  • Committer: Bazaar Package Importer
  • Author(s): Paul Hampson
  • Date: 2006-01-15 13:34:13 UTC
  • mto: (3.1.3 dapper) (4.1.3 sid) (1.1.14 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20060115133413-zo1dslttvdoalqym
Tags: upstream-1.1.0
ImportĀ upstreamĀ versionĀ 1.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 *              That, in fact, was again based on the original stuff
8
8
 *              from Jeph Blaize <jblaize@kiva.net> done in May 1997.
9
9
 *
10
 
 * Version:     $Id: rlm_pam.c,v 1.32 2004/02/26 19:04:33 aland Exp $
 
10
 * Version:     $Id: rlm_pam.c,v 1.32.4.2 2006/01/04 05:51:50 fcusack Exp $
11
11
 *
12
12
 *   This program is free software; you can redistribute it and/or modify
13
13
 *   it under the terms of the GNU General Public License as published by
121
121
                     const struct pam_message **msg,
122
122
                     struct pam_response **resp,
123
123
                     void *appdata_ptr) {
124
 
  int count = 0, replies = 0;
125
 
  struct pam_response *reply = NULL;
126
 
  int size = sizeof(struct pam_response);
 
124
  int count;
 
125
  struct pam_response *reply;
127
126
  my_PAM *pam_config = (my_PAM *) appdata_ptr;
128
127
 
129
 
#define GET_MEM if (reply) realloc(reply, size); else reply = rad_malloc(size); \
130
 
  size += sizeof(struct pam_response)
 
128
/* strdup(NULL) doesn't work on some platforms */
131
129
#define COPY_STRING(s) ((s) ? strdup(s) : NULL)
132
130
 
 
131
  reply = rad_malloc(num_msg * sizeof(struct pam_response));
 
132
  memset(reply, 0, num_msg * sizeof(struct pam_response));
133
133
  for (count = 0; count < num_msg; count++) {
134
134
    switch (msg[count]->msg_style) {
135
135
    case PAM_PROMPT_ECHO_ON:
136
 
      GET_MEM;
137
 
      reply[replies].resp_retcode = PAM_SUCCESS;
138
 
      reply[replies++].resp = COPY_STRING(pam_config->username);
139
 
      /* PAM frees resp */
 
136
      reply[count].resp_retcode = PAM_SUCCESS;
 
137
      reply[count].resp = COPY_STRING(pam_config->username);
140
138
      break;
141
139
    case PAM_PROMPT_ECHO_OFF:
142
 
      GET_MEM;
143
 
      reply[replies].resp_retcode = PAM_SUCCESS;
144
 
      reply[replies++].resp = COPY_STRING(pam_config->password);
145
 
      /* PAM frees resp */
 
140
      reply[count].resp_retcode = PAM_SUCCESS;
 
141
      reply[count].resp = COPY_STRING(pam_config->password);
146
142
      break;
147
143
    case PAM_TEXT_INFO:
148
144
      /* ignore it... */
150
146
    case PAM_ERROR_MSG:
151
147
    default:
152
148
      /* Must be an error of some sort... */
153
 
      free (reply);
 
149
      for (count = 0; count < num_msg; count++) {
 
150
        if (reply[count].resp) {
 
151
          /* could be a password, let's be sanitary */
 
152
          memset(reply[count].resp, 0, strlen(reply[count].resp));
 
153
          free(reply[count].resp);
 
154
        }
 
155
      }
 
156
      free(reply);
154
157
      pam_config->error = 1;
155
158
      return PAM_CONV_ERR;
156
159
    }
157
160
  }
158
 
  if (reply) *resp = reply;
 
161
  *resp = reply;
 
162
  /* PAM frees reply (including reply[].resp) */
159
163
 
160
164
  return PAM_SUCCESS;
161
165
}