Support This Project

Changeset 2018

Show
Ignore:
Timestamp:
08/14/08 17:39:33 (4 months ago)
Author:
virdiq
Message:

Fix another segfault in do_login due to the assumption that the backend always returns a valid group struct. Also includes a code cleanup of this part of the function. Thanks Bauruine again for the backtrace that led to this fix.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libwzd-core/wzd_login.c

    r2017 r2018  
    727727 
    728728  { 
    729     const char * groupname = NULL; 
    730     const char * remote_host; 
    731     struct hostent *h; 
     729    struct hostent * h = NULL; 
    732730    char inet_str[256]; 
    733731    int af = (context->family == WZD_INET6) ? AF_INET6 : AF_INET; 
    734     wzd_user_t * user; 
     732    wzd_user_t * user = NULL; 
     733    wzd_group_t * group = NULL; 
    735734 
    736735    user = GetUserByID(context->userid); 
    737     if (user && user->group_num > 0) groupname = GetGroupByID(user->groups[0])->groupname; 
     736    if (user && user->group_num > 0) { 
     737      group = GetGroupByID(user->groups[0]); 
     738    } 
    738739    inet_str[0] = '\0'; 
    739     inet_ntop(af,context->hostip,inet_str,sizeof(inet_str)); 
    740     h = gethostbyaddr((char*)&context->hostip,sizeof(context->hostip),af); 
    741     if (h==NULL) 
    742       remote_host = inet_str; 
    743     else 
    744       remote_host = h->h_name; 
    745     log_message( (ret)?"LOGIN_FAILED":"LOGIN" ,"%s (%s) \"%s\" \"%s\" \"%s\"", 
    746         (remote_host)?remote_host:"no host!", 
    747         inet_str, 
    748         user ? user->username : "unknown", 
    749         (groupname)?groupname:"No Group", 
    750         user ? user->tagline : "unknown" 
     740    inet_ntop(af, context->hostip, inet_str, sizeof(inet_str)); 
     741    h = gethostbyaddr((char*)&context->hostip, sizeof(context->hostip), af); 
     742    log_message(ret ? "LOGIN_FAILED" : "LOGIN", 
     743        "%s (%s) \"%s\" \"%s\" \"%s\"", 
     744        h && h->h_name ? h->h_name : "No hostname", 
     745        *inet_str ? inet_str : "No IP address", 
     746        user && user->username ? user->username : "No username", 
     747        group && group->groupname ? group->groupname : "No groupname", 
     748        user && user->tagline ? user->tagline : "No tagline" 
    751749        ); 
    752750  }