10
10
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
11
11
*
12
12
* IDENTIFICATION
13
- * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.111 2006/02/12 20:04:42 momjian Exp $
13
+ * $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.112 2006/02/12 20:08:29 momjian Exp $
14
14
*
15
15
*-------------------------------------------------------------------------
16
16
*/
@@ -101,33 +101,22 @@ pg_an_to_ln(char *aname)
101
101
* Various krb5 state which is not connection specific, and a flag to
102
102
* indicate whether we have initialised it yet.
103
103
*/
104
- /*
105
104
static int pg_krb5_initialised ;
106
105
static krb5_context pg_krb5_context ;
107
106
static krb5_ccache pg_krb5_ccache ;
108
107
static krb5_principal pg_krb5_client ;
109
108
static char * pg_krb5_name ;
110
- */
111
-
112
- struct krb5_info
113
- {
114
- int pg_krb5_initialised ;
115
- krb5_context pg_krb5_context ;
116
- krb5_ccache pg_krb5_ccache ;
117
- krb5_principal pg_krb5_client ;
118
- char * pg_krb5_name ;
119
- };
120
109
121
110
122
111
static int
123
- pg_krb5_init (char * PQerrormsg , struct krb5_info * info )
112
+ pg_krb5_init (char * PQerrormsg )
124
113
{
125
114
krb5_error_code retval ;
126
115
127
- if (info -> pg_krb5_initialised )
116
+ if (pg_krb5_initialised )
128
117
return STATUS_OK ;
129
118
130
- retval = krb5_init_context (& ( info -> pg_krb5_context ) );
119
+ retval = krb5_init_context (& pg_krb5_context );
131
120
if (retval )
132
121
{
133
122
snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
@@ -136,56 +125,46 @@ pg_krb5_init(char *PQerrormsg, struct krb5_info *info)
136
125
return STATUS_ERROR ;
137
126
}
138
127
139
- retval = krb5_cc_default (info -> pg_krb5_context , & ( info -> pg_krb5_ccache ) );
128
+ retval = krb5_cc_default (pg_krb5_context , & pg_krb5_ccache );
140
129
if (retval )
141
130
{
142
131
snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
143
132
"pg_krb5_init: krb5_cc_default: %s\n" ,
144
133
error_message (retval ));
145
- krb5_free_context (info -> pg_krb5_context );
134
+ krb5_free_context (pg_krb5_context );
146
135
return STATUS_ERROR ;
147
136
}
148
137
149
- retval = krb5_cc_get_principal (info -> pg_krb5_context , info -> pg_krb5_ccache ,
150
- & ( info -> pg_krb5_client ) );
138
+ retval = krb5_cc_get_principal (pg_krb5_context , pg_krb5_ccache ,
139
+ & pg_krb5_client );
151
140
if (retval )
152
141
{
153
142
snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
154
143
"pg_krb5_init: krb5_cc_get_principal: %s\n" ,
155
144
error_message (retval ));
156
- krb5_cc_close (info -> pg_krb5_context , info -> pg_krb5_ccache );
157
- krb5_free_context (info -> pg_krb5_context );
145
+ krb5_cc_close (pg_krb5_context , pg_krb5_ccache );
146
+ krb5_free_context (pg_krb5_context );
158
147
return STATUS_ERROR ;
159
148
}
160
149
161
- retval = krb5_unparse_name (info -> pg_krb5_context , info -> pg_krb5_client , & ( info -> pg_krb5_name ) );
150
+ retval = krb5_unparse_name (pg_krb5_context , pg_krb5_client , & pg_krb5_name );
162
151
if (retval )
163
152
{
164
153
snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
165
154
"pg_krb5_init: krb5_unparse_name: %s\n" ,
166
155
error_message (retval ));
167
- krb5_free_principal (info -> pg_krb5_context , info -> pg_krb5_client );
168
- krb5_cc_close (info -> pg_krb5_context , info -> pg_krb5_ccache );
169
- krb5_free_context (info -> pg_krb5_context );
156
+ krb5_free_principal (pg_krb5_context , pg_krb5_client );
157
+ krb5_cc_close (pg_krb5_context , pg_krb5_ccache );
158
+ krb5_free_context (pg_krb5_context );
170
159
return STATUS_ERROR ;
171
160
}
172
161
173
- info -> pg_krb5_name = pg_an_to_ln (info -> pg_krb5_name );
162
+ pg_krb5_name = pg_an_to_ln (pg_krb5_name );
174
163
175
- info -> pg_krb5_initialised = 1 ;
164
+ pg_krb5_initialised = 1 ;
176
165
return STATUS_OK ;
177
166
}
178
167
179
- static void
180
- pg_krb5_destroy (struct krb5_info * info )
181
- {
182
- krb5_free_principal (info -> pg_krb5_context , info -> pg_krb5_client );
183
- krb5_cc_close (info -> pg_krb5_context , info -> pg_krb5_ccache );
184
- krb5_free_context (info -> pg_krb5_context );
185
- free (info -> pg_krb5_name );
186
- }
187
-
188
-
189
168
190
169
/*
191
170
* pg_krb5_authname -- returns a pointer to static space containing whatever
@@ -194,16 +173,10 @@ pg_krb5_destroy(struct krb5_info *info)
194
173
static const char *
195
174
pg_krb5_authname (char * PQerrormsg )
196
175
{
197
- char * tmp_name ;
198
- struct krb5_info info ;
199
- info .pg_krb5_initialised = 0 ;
200
-
201
- if (pg_krb5_init (PQerrormsg , & info ) != STATUS_OK )
176
+ if (pg_krb5_init (PQerrormsg ) != STATUS_OK )
202
177
return NULL ;
203
- tmp_name = strdup (info .pg_krb5_name );
204
- pg_krb5_destroy (& info );
205
178
206
- return tmp_name ;
179
+ return pg_krb5_name ;
207
180
}
208
181
209
182
@@ -219,8 +192,6 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname, const char *s
219
192
krb5_principal server ;
220
193
krb5_auth_context auth_context = NULL ;
221
194
krb5_error * err_ret = NULL ;
222
- struct krb5_info info ;
223
- info .pg_krb5_initialised = 0 ;
224
195
225
196
if (!hostname )
226
197
{
@@ -229,18 +200,17 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname, const char *s
229
200
return STATUS_ERROR ;
230
201
}
231
202
232
- ret = pg_krb5_init (PQerrormsg , & info );
203
+ ret = pg_krb5_init (PQerrormsg );
233
204
if (ret != STATUS_OK )
234
205
return ret ;
235
206
236
- retval = krb5_sname_to_principal (info . pg_krb5_context , hostname , servicename ,
207
+ retval = krb5_sname_to_principal (pg_krb5_context , hostname , servicename ,
237
208
KRB5_NT_SRV_HST , & server );
238
209
if (retval )
239
210
{
240
211
snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
241
212
"pg_krb5_sendauth: krb5_sname_to_principal: %s\n" ,
242
213
error_message (retval ));
243
- pg_krb5_destroy (& info );
244
214
return STATUS_ERROR ;
245
215
}
246
216
@@ -255,17 +225,16 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname, const char *s
255
225
256
226
snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
257
227
libpq_gettext ("could not set socket to blocking mode: %s\n" ), pqStrerror (errno , sebuf , sizeof (sebuf )));
258
- krb5_free_principal (info .pg_krb5_context , server );
259
- pg_krb5_destroy (& info );
228
+ krb5_free_principal (pg_krb5_context , server );
260
229
return STATUS_ERROR ;
261
230
}
262
231
263
- retval = krb5_sendauth (info . pg_krb5_context , & auth_context ,
232
+ retval = krb5_sendauth (pg_krb5_context , & auth_context ,
264
233
(krb5_pointer ) & sock , (char * ) servicename ,
265
- info . pg_krb5_client , server ,
234
+ pg_krb5_client , server ,
266
235
AP_OPTS_MUTUAL_REQUIRED ,
267
236
NULL , 0 , /* no creds, use ccache instead */
268
- info . pg_krb5_ccache , & err_ret , NULL , NULL );
237
+ pg_krb5_ccache , & err_ret , NULL , NULL );
269
238
if (retval )
270
239
{
271
240
if (retval == KRB5_SENDAUTH_REJECTED && err_ret )
@@ -290,12 +259,12 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname, const char *s
290
259
}
291
260
292
261
if (err_ret )
293
- krb5_free_error (info . pg_krb5_context , err_ret );
262
+ krb5_free_error (pg_krb5_context , err_ret );
294
263
295
264
ret = STATUS_ERROR ;
296
265
}
297
266
298
- krb5_free_principal (info . pg_krb5_context , server );
267
+ krb5_free_principal (pg_krb5_context , server );
299
268
300
269
if (!pg_set_noblock (sock ))
301
270
{
@@ -306,7 +275,6 @@ pg_krb5_sendauth(char *PQerrormsg, int sock, const char *hostname, const char *s
306
275
pqStrerror (errno , sebuf , sizeof (sebuf )));
307
276
ret = STATUS_ERROR ;
308
277
}
309
- pg_krb5_destroy (& info );
310
278
311
279
return ret ;
312
280
}
@@ -519,9 +487,6 @@ pg_fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
519
487
char *
520
488
pg_fe_getauthname (char * PQerrormsg )
521
489
{
522
- #ifdef KRB5
523
- const char * krb5_name = NULL ;
524
- #endif
525
490
const char * name = NULL ;
526
491
char * authn ;
527
492
@@ -546,12 +511,7 @@ pg_fe_getauthname(char *PQerrormsg)
546
511
pglock_thread ();
547
512
548
513
#ifdef KRB5
549
- /* pg_krb5_authname gives us a strdup'd value that we need
550
- * to free later, however, we don't want to free 'name' directly
551
- * in case it's *not* a Kerberos login and we fall through to
552
- * name = pw->pw_name; */
553
- krb5_name = pg_krb5_authname (PQerrormsg );
554
- name = krb5_name ;
514
+ name = pg_krb5_authname (PQerrormsg );
555
515
#endif
556
516
557
517
if (!name )
@@ -567,12 +527,6 @@ pg_fe_getauthname(char *PQerrormsg)
567
527
568
528
authn = name ? strdup (name ) : NULL ;
569
529
570
- #ifdef KRB5
571
- /* Free the strdup'd string from pg_krb5_authname, if we got one */
572
- if (krb5_name )
573
- free (krb5_name );
574
- #endif
575
-
576
530
pgunlock_thread ();
577
531
578
532
return authn ;
0 commit comments