Changeset a15c097


Ignore:
Timestamp:
2006-03-24T16:48:16Z (19 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
9779c18
Parents:
d5dfc3d
Message:

More work on LDAP backend; report errors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • storage_ldap.c

    rd5dfc3d ra15c097  
    4646
    4747        if (!ld) {
    48                 /* FIXME: report error */
     48                log_message( LOGLVL_WARNING, "Unable to connect to LDAP server at %s", BB_LDAP_HOST );
    4949                return STORAGE_OTHER_ERROR;
    5050        }
     
    5858         case LDAP_INVALID_CREDENTIALS: status = STORAGE_INVALID_PASSWORD; break;
    5959         default:
    60                 /* FIXME: Log */
     60                log_message( LOGLVL_WARNING, "Unable to authenticate %s: %s", mydn, ldap_err2string(ret) );
    6161                status = STORAGE_OTHER_ERROR;
    6262                break;
     
    6868}
    6969
    70 static void sldap_init (void)
    71 {
    72 }
    73 
    7470static storage_status_t sldap_load ( const char *my_nick, const char* password, irc_t *irc )
    7571{
    76         LDAPMessage *res;
     72        LDAPMessage *res, *msg;
    7773        LDAP *ld;
    78         int ret;
     74        int ret, i;
    7975        storage_status_t status;
    8076        char *mydn;
     
    8682        mydn = nick_dn(my_nick);
    8783
    88         ret = ldap_search_s(ld, mydn, LDAP_SCOPE_ONELEVEL, "(objectClass=*)", NULL, 0, &res);
     84        ret = ldap_search_s(ld, mydn, LDAP_SCOPE_BASE, "(objectClass=*)", NULL, 0, &res);
     85
     86        if (ret != LDAP_SUCCESS) {
     87                log_message( LOGLVL_WARNING, "Unable to search for %s: %s", mydn, ldap_err2string(ret) );
     88                ldap_unbind_s(ld);
     89                return STORAGE_OTHER_ERROR;
     90        }
    8991
    9092        g_free(mydn);
    9193
    92         /* FIXME: Check ret */
     94        for (msg = ldap_first_entry(ld, res); msg; msg = ldap_next_entry(ld, msg)) {
     95        }
    9396
    9497        /* FIXME: Store in irc_t */
    95        
    96         return STORAGE_OK;
    97 }
    9898
    99 static storage_status_t sldap_save( irc_t *irc, int overwrite )
    100 {
    101         LDAP *ld;
    102         char *mydn;
    103         storage_status_t status;
    104 
    105         status = nick_connect(irc->nick, irc->password, &ld);
    106         if (status != STORAGE_OK)
    107                 return status;
    108 
    109         mydn = nick_dn(irc->nick);
    110 
    111         /* FIXME */
    112        
    113         g_free(mydn);
     99        ldap_unbind_s(ld);
    114100       
    115101        return STORAGE_OK;
     
    145131
    146132        if (ret != LDAP_SUCCESS) {
    147                 /* FIXME: report */
     133                log_message( LOGLVL_WARNING, "Error removing %s: %s", mydn, ldap_err2string(ret) );
     134                ldap_unbind_s(ld);
    148135                return STORAGE_OTHER_ERROR;
    149136        }
     137
     138        ldap_unbind_s(ld);
    150139
    151140        g_free(mydn);
     
    153142}
    154143
     144static storage_status_t sldap_save( irc_t *irc, int overwrite )
     145{
     146        LDAP *ld;
     147        char *mydn;
     148        storage_status_t status;
     149        LDAPMessage *msg;
     150
     151        status = nick_connect(irc->nick, irc->password, &ld);
     152        if (status != STORAGE_OK)
     153                return status;
     154
     155        mydn = nick_dn(irc->nick);
     156
     157        /* FIXME: Make this a bit more atomic? What if we crash after
     158         * removing the old account but before adding the new one ? */
     159        if (overwrite)
     160                sldap_remove(irc->nick, irc->password);
     161
     162        g_free(mydn);
     163
     164        ldap_unbind_s(ld);
     165       
     166        return STORAGE_OK;
     167}
     168
     169
     170
    155171storage_t storage_ldap = {
    156172        .name = "ldap",
    157         .init = sldap_init,
    158173        .check_pass = sldap_check_pass,
    159174        .remove = sldap_remove,
Note: See TracChangeset for help on using the changeset viewer.