Ignore:
Timestamp:
26/07/06 11:18:55 (13 years ago)
Author:
spascoe
Message:

I've created a bbftpd log facility to replace syslog.
At present it allows you to log messages to a file in addition
to syslog. This should help testing on other machines.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_login.c

    r773 r1328  
    5656 
    5757#include <pwd.h> 
    58 #include <syslog.h> 
     58#include <bbftpd_log.h> 
    5959#include <sys/types.h> 
    6060#include <unistd.h> 
     
    183183            } 
    184184            if ( decodersapass(receive_buffer,username,password) < 0 ) { 
    185                 syslog(BBFTPD_ERR,"Decode user/password error") ; 
     185                bbftpd_log(BBFTPD_ERR,"Decode user/password error") ; 
    186186                strcat(logmessage," : Decode user/password error") ; 
    187187                reply(MSG_BAD,logmessage) ; 
     
    200200            break ; 
    201201        default : 
    202             syslog(BBFTPD_ERR,"Unkwown encryption %d",msg_sec->crtype) ; 
     202            bbftpd_log(BBFTPD_ERR,"Unkwown encryption %d",msg_sec->crtype) ; 
    203203            strcat(logmessage," : Unknwon encryption") ; 
    204204            reply(MSG_BAD,logmessage) ; 
     
    209209    */ 
    210210    if ( (uspass = getpwnam(username)) == NULL ) { 
    211         syslog(BBFTPD_ERR,"Unknown user %s",username) ; 
     211        bbftpd_log(BBFTPD_ERR,"Unknown user %s",username) ; 
    212212        strcat(logmessage," : Unknown user (") ; 
    213213        strcat(logmessage, username); 
     
    223223    retcode = ka_UserAuthenticate(username,inst,0,password,0,&calcpass) ; 
    224224    if ( retcode != 0 ) { 
    225         syslog(BBFTPD_ERR,"ka_UserAuthenticate message : %s ",calcpass) ; 
     225        bbftpd_log(BBFTPD_ERR,"ka_UserAuthenticate message : %s ",calcpass) ; 
    226226        /* 
    227227        ** Check local user  
     
    231231#ifdef SHADOW_PASSWORD 
    232232            if ( (sunpass = getspnam(username)) == NULL ) { 
    233                 syslog(BBFTPD_ERR,"Unknown user %s",username) ; 
     233                bbftpd_log(BBFTPD_ERR,"Unknown user %s",username) ; 
    234234                /* 
    235235                ** We send ka_UserAuthenticate error msg 
     
    242242            calcpass = (char *) crypt(password,sunpass->sp_pwdp) ; 
    243243            if ( strcmp(calcpass,sunpass->sp_pwdp) != 0 ) { 
    244                 syslog(BBFTPD_ERR,"Incorrect password user %s",username) ; 
     244                bbftpd_log(BBFTPD_ERR,"Incorrect password user %s",username) ; 
    245245                strcat(logmessage," : Incorrect password") ; 
    246246                reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    249249#elif defined(HAVE_SECURITY_PASS) 
    250250            if ( (secpass = getuserpw(username)) == NULL ) { 
    251                 syslog(BBFTPD_ERR,"Unknown user %s",username) ; 
     251                bbftpd_log(BBFTPD_ERR,"Unknown user %s",username) ; 
    252252                /* 
    253253                ** We send ka_UserAuthenticate error msg 
     
    260260            calcpass = (char *) crypt(password,secpass->upw_passwd) ; 
    261261            if ( strcmp(calcpass,secpass->upw_passwd) != 0 ) { 
    262                 syslog(BBFTPD_ERR,"Incorrect password user %s",username) ; 
     262                bbftpd_log(BBFTPD_ERR,"Incorrect password user %s",username) ; 
    263263                strcat(logmessage," : Incorrect password") ; 
    264264                reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    267267#else 
    268268 
    269             syslog(BBFTPD_ERR,"No Password user %s",username) ; 
     269            bbftpd_log(BBFTPD_ERR,"No Password user %s",username) ; 
    270270            strcat(logmessage," : No password user") ; 
    271271            reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    275275            calcpass = (char *) crypt(password,uspass->pw_passwd) ; 
    276276            if ( strcmp(calcpass,uspass->pw_passwd) != 0 ) { 
    277                 syslog(BBFTPD_ERR,"Incorrect password user %s",username) ; 
     277                bbftpd_log(BBFTPD_ERR,"Incorrect password user %s",username) ; 
    278278                strcat(logmessage," : Incorrect password") ; 
    279279                reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    289289    PAM_password = password ; 
    290290    retcode = pam_start("bbftp", username, &PAM_conversation, &pamh); 
    291 #define PAM_BAIL if (retcode != PAM_SUCCESS) { pam_end(pamh, 0); syslog(BBFTPD_ERR,"PAM error (%d) user %s",retcode,username) ;reply(MSG_BAD_NO_RETRY,logmessage) ;return -1; } 
     291#define PAM_BAIL if (retcode != PAM_SUCCESS) { pam_end(pamh, 0); bbftpd_log(BBFTPD_ERR,"PAM error (%d) user %s",retcode,username) ;reply(MSG_BAD_NO_RETRY,logmessage) ;return -1; } 
    292292    PAM_BAIL; 
    293293    retcode = pam_authenticate(pamh, PAM_SILENT); 
     
    305305    ** Reopen the lag as the pam functions close it 
    306306    */ 
    307     openlog(daemonchar, LOG_PID | LOG_NDELAY, BBFTPD_FACILITY); 
     307#ifdef NO_SYSLOG 
     308    bbftpd_openlogfile("bbftpd.log", LOG_PID | LOG_NDELAY, BBFTPD_FACILITY); 
     309#else 
     310    bbftpd_openlog(daemonchar, LOG_PID | LOG_NDELAY, BBFTPD_FACILITY); 
     311#endif 
    308312#else 
    309313    /* 
     
    314318#ifdef SHADOW_PASSWORD 
    315319            if ( (sunpass = getspnam(username)) == NULL ) { 
    316                 syslog(BBFTPD_ERR,"Unknown user %s",username) ; 
     320                bbftpd_log(BBFTPD_ERR,"Unknown user %s",username) ; 
    317321                strcat(logmessage," : Unknown user") ; 
    318322                reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    321325            calcpass = (char *) crypt(password,sunpass->sp_pwdp) ; 
    322326            if ( strcmp(calcpass,sunpass->sp_pwdp) != 0 ) { 
    323                 syslog(BBFTPD_ERR,"Incorrect password user %s",username) ; 
     327                bbftpd_log(BBFTPD_ERR,"Incorrect password user %s",username) ; 
    324328                strcat(logmessage," : Incorrect password") ; 
    325329                reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    328332#elif defined(HAVE_SECURITY_PASS) 
    329333            if ( (secpass = getuserpw(username)) == NULL ) { 
    330                 syslog(BBFTPD_ERR,"Unknown user %s",username) ; 
     334                bbftpd_log(BBFTPD_ERR,"Unknown user %s",username) ; 
    331335                strcat(logmessage," : Unknown user") ; 
    332336                reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    335339            calcpass = (char *) crypt(password,secpass->upw_passwd) ; 
    336340            if ( strcmp(calcpass,secpass->upw_passwd) != 0 ) { 
    337                 syslog(BBFTPD_ERR,"Incorrect password user %s",username) ; 
     341                bbftpd_log(BBFTPD_ERR,"Incorrect password user %s",username) ; 
    338342                strcat(logmessage," : Incorrect password") ; 
    339343                reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    341345            } 
    342346#else 
    343             syslog(BBFTPD_ERR,"No Password user %s",username) ; 
     347            bbftpd_log(BBFTPD_ERR,"No Password user %s",username) ; 
    344348            strcat(logmessage," : No password") ; 
    345349            reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    349353        calcpass = (char *) crypt(password,uspass->pw_passwd) ; 
    350354        if ( strcmp(calcpass,uspass->pw_passwd) != 0 ) { 
    351             syslog(BBFTPD_ERR,"Incorrect password user %s",username) ; 
     355            bbftpd_log(BBFTPD_ERR,"Incorrect password user %s",username) ; 
    352356            strcat(logmessage," : Incorrect password") ; 
    353357            reply(MSG_BAD_NO_RETRY,logmessage) ; 
     
    360364    */ 
    361365    if ( setgid(uspass->pw_gid) < 0 ) { 
    362         syslog(BBFTPD_ERR,"Error setgid user %s : %s",username,strerror(errno)) ; 
     366        bbftpd_log(BBFTPD_ERR,"Error setgid user %s : %s",username,strerror(errno)) ; 
    363367        strcat(logmessage," : Unable to set gid: ") ; 
    364368        strcat(logmessage,strerror(errno)); 
     
    369373    if (getuid() == 0) { 
    370374      if (initgroups(uspass->pw_name, uspass->pw_gid) < 0) { 
    371         syslog(BBFTPD_WARNING,"Error Initialize the group list %s : %s",username,strerror(errno)) ; 
     375        bbftpd_log(BBFTPD_WARNING,"Error Initialize the group list %s : %s",username,strerror(errno)) ; 
    372376        return -1 ; 
    373377      } 
     
    376380 
    377381    if ( setuid(uspass->pw_uid) < 0 ) { 
    378         syslog(BBFTPD_ERR,"Error setuid user %s : %s",username,strerror(errno)) ; 
     382        bbftpd_log(BBFTPD_ERR,"Error setuid user %s : %s",username,strerror(errno)) ; 
    379383        strcat(logmessage," : Unable to set uid: ") ; 
    380384        strcat(logmessage,strerror(errno)); 
     
    383387    } 
    384388    if ( uspass->pw_dir == NULL ) { 
    385         syslog(BBFTPD_ERR,"No home directory user %s : %s",username,strerror(errno)) ; 
     389        bbftpd_log(BBFTPD_ERR,"No home directory user %s : %s",username,strerror(errno)) ; 
    386390        strcat(logmessage," : No home directory: ") ; 
    387391        strcat(logmessage,strerror(errno)); 
     
    390394    } 
    391395    if ( chdir(uspass->pw_dir) < 0) { 
    392         syslog(BBFTPD_ERR,"Error chdir user %s : %s",username,strerror(errno)) ; 
     396        bbftpd_log(BBFTPD_ERR,"Error chdir user %s : %s",username,strerror(errno)) ; 
    393397        strcat(logmessage," : Unable to change directory: ") ; 
    394398        strcat(logmessage,strerror(errno)); 
     
    397401    } 
    398402                 
    399     syslog(BBFTPD_DEBUG,"User %s connected",username) ; 
     403    bbftpd_log(BBFTPD_DEBUG,"User %s connected",username) ; 
    400404    strcpy(currentusername,username) ; 
    401405    return 0 ; 
Note: See TracChangeset for help on using the changeset viewer.