comparison src/client.c @ 187:166008a80f03 noffle

[svn] src/client.c,src/protocol.h: perform authentication at connect time, accept new and deprecated authentication status codes.
author enz
date Sat, 01 Sep 2001 16:57:45 +0100
parents fed1334d766b
children f1bacee93ca6
comparison
equal deleted inserted replaced
186:7d1f26e7c728 187:166008a80f03
1 /* 1 /*
2 client.c 2 client.c
3 3
4 $Id: client.c 300 2001-08-05 08:24:22Z bears $ 4 $Id: client.c 306 2001-09-01 15:57:45Z enz $
5 */ 5 */
6 6
7 #if HAVE_CONFIG_H 7 #if HAVE_CONFIG_H
8 #include <config.h> 8 #include <config.h>
9 #endif 9 #endif
178 Log_err( "No username for authentication set" ); 178 Log_err( "No username for authentication set" );
179 return STAT_AUTH_REQUIRED; 179 return STAT_AUTH_REQUIRED;
180 } 180 }
181 putCmd( "AUTHINFO USER %s", user ); 181 putCmd( "AUTHINFO USER %s", user );
182 stat = getStat(); 182 stat = getStat();
183 if ( stat == STAT_AUTH_ACCEPTED ) 183 if ( stat == STAT_AUTH_ACCEPTED
184 || stat == STAT_AUTH_ACCEPTED_DEPREC )
184 return stat; 185 return stat;
185 else if ( stat != STAT_MORE_AUTH_REQUIRED ) 186 else if ( stat != STAT_MORE_AUTH_REQUIRED_DEPREC
187 && stat != STAT_AUTH_REQUIRED )
186 { 188 {
187 Log_err( "Username rejected. Server stat: %s", client.lastStat ); 189 Log_err( "Username rejected. Server stat: %s", client.lastStat );
188 return stat; 190 return stat;
189 } 191 }
190 if ( strcmp( pass, "" ) == 0 ) 192 if ( strcmp( pass, "" ) == 0 )
192 Log_err( "No password for authentication set" ); 194 Log_err( "No password for authentication set" );
193 return STAT_AUTH_REQUIRED; 195 return STAT_AUTH_REQUIRED;
194 } 196 }
195 putCmd( "AUTHINFO PASS %s", pass ); 197 putCmd( "AUTHINFO PASS %s", pass );
196 stat = getStat(); 198 stat = getStat();
197 if ( stat != STAT_AUTH_ACCEPTED ) 199 if ( stat != STAT_AUTH_ACCEPTED
200 && stat != STAT_AUTH_ACCEPTED_DEPREC)
198 Log_err( "Password rejected. Server status: %s", client.lastStat ); 201 Log_err( "Password rejected. Server status: %s", client.lastStat );
199 return stat; 202 return stat;
200 } 203 }
201 204
202 static int 205 static int
210 else if ( sscanf( client.lastStat, "%d", &result ) != 1 ) 213 else if ( sscanf( client.lastStat, "%d", &result ) != 1 )
211 { 214 {
212 Log_err( "Invalid server status: %s", client.lastStat ); 215 Log_err( "Invalid server status: %s", client.lastStat );
213 result = STAT_PROGRAM_FAULT; 216 result = STAT_PROGRAM_FAULT;
214 } 217 }
215 if ( result == STAT_AUTH_REQUIRED && ! client.auth ) 218 if ( ( result == STAT_AUTH_REQUIRED
219 || result == STAT_AUTH_REQUIRED_DEPREC )
220 && ! client.auth )
216 { 221 {
217 client.auth = TRUE; 222 client.auth = TRUE;
218 strcpy( lastCmd, client.lastCmd ); 223 strcpy( lastCmd, client.lastCmd );
219 result = performAuth(); 224 result = performAuth();
220 if ( result == STAT_AUTH_ACCEPTED ) 225 if ( result == STAT_AUTH_ACCEPTED
226 || result == STAT_AUTH_ACCEPTED_DEPREC )
221 { 227 {
222 putCmd( lastCmd ); 228 putCmd( lastCmd );
223 return getStat(); 229 return getStat();
224 } 230 }
225 } 231 }
286 int sock, i; 292 int sock, i;
287 unsigned int stat; 293 unsigned int stat;
288 struct hostent *hp; 294 struct hostent *hp;
289 char *pStart, *pColon; 295 char *pStart, *pColon;
290 Str host, s; 296 Str host, s;
297 Str user, pass;
291 struct sockaddr_in sIn; 298 struct sockaddr_in sIn;
292 299
293 ASSERT( client.in == NULL && client.out == NULL ); 300 ASSERT( client.in == NULL && client.out == NULL );
294 client.auth = FALSE; 301 client.auth = FALSE;
295 Utl_cpyStr( s, serv ); 302 Utl_cpyStr( s, serv );
342 client.in = client.out = NULL; 349 client.in = client.out = NULL;
343 break; 350 break;
344 } 351 }
345 Utl_cpyStr( client.serv, serv ); 352 Utl_cpyStr( client.serv, serv );
346 stat = getStat(); 353 stat = getStat();
347 if ( stat == STAT_READY_POST_ALLOW ||
348 stat == STAT_READY_NO_POST_ALLOW )
349 {
350 /* INN needs a MODE READER before it will permit POST. */
351 putCmd( "MODE READER" );
352 stat = getStat();
353 }
354 switch( stat ) { 354 switch( stat ) {
355 case STAT_READY_POST_ALLOW: 355 case STAT_READY_POST_ALLOW:
356 case STAT_READY_NO_POST_ALLOW: 356 case STAT_READY_NO_POST_ALLOW:
357 Log_inf( "Connected to %s:%d", 357 Log_inf( "Connected to %s:%d",
358 inet_ntoa( sIn.sin_addr ), port ); 358 inet_ntoa( sIn.sin_addr ), port );
359 /* INN needs a MODE READER before it will permit POST. */
360 putCmd( "MODE READER" );
361 getStat();
362 Cfg_authInfo( client.serv, user, pass );
363 if ( strcmp( user, "" ) != 0 )
364 performAuth();
359 return TRUE; 365 return TRUE;
360 default: 366 default:
361 Log_err( "Bad server stat %d", stat ); 367 Log_err( "Bad server stat %d", stat );
362 } 368 }
363 shutdown( fileno( client.out ), 0 ); 369 shutdown( fileno( client.out ), 0 );