Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/lib/smbldap.c

    r618 r740  
    2525#include "includes.h"
    2626#include "smbldap.h"
    27 
    28 #ifndef LDAP_OPT_SUCCESS
    29 #define LDAP_OPT_SUCCESS 0
    30 #endif
     27#include "secrets.h"
     28#include "../libcli/security/security.h"
    3129
    3230/* Try not to hit the up or down server forever */
     
    508506 ***********************************************************************/
    509507
    510  void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value)
     508static void smbldap_set_mod_internal(LDAPMod *** modlist, int modop, const char *attribute, const char *value, const DATA_BLOB *blob)
    511509{
    512510        LDAPMod **mods;
     
    559557        }
    560558
    561         if (value != NULL) {
     559        if (blob && (modop & LDAP_MOD_BVALUES)) {
     560                j = 0;
     561                if (mods[i]->mod_bvalues != NULL) {
     562                        for (; mods[i]->mod_bvalues[j] != NULL; j++);
     563                }
     564                mods[i]->mod_bvalues = SMB_REALLOC_ARRAY(mods[i]->mod_bvalues, struct berval *, j + 2);
     565
     566                if (mods[i]->mod_bvalues == NULL) {
     567                        smb_panic("smbldap_set_mod: out of memory!");
     568                        /* notreached. */
     569                }
     570
     571                mods[i]->mod_bvalues[j] = SMB_MALLOC_P(struct berval);
     572                SMB_ASSERT(mods[i]->mod_bvalues[j] != NULL);
     573
     574                mods[i]->mod_bvalues[j]->bv_val = (char *)memdup(blob->data, blob->length);
     575                SMB_ASSERT(mods[i]->mod_bvalues[j]->bv_val != NULL);
     576                mods[i]->mod_bvalues[j]->bv_len = blob->length;
     577
     578                mods[i]->mod_bvalues[j + 1] = NULL;
     579        } else if (value != NULL) {
    562580                char *utf8_value = NULL;
    563581                size_t converted_size;
     
    586604        }
    587605        *modlist = mods;
     606}
     607
     608 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value)
     609{
     610        smbldap_set_mod_internal(modlist, modop, attribute, value, NULL);
     611}
     612
     613 void smbldap_set_mod_blob(LDAPMod *** modlist, int modop, const char *attribute, const DATA_BLOB *value)
     614{
     615        smbldap_set_mod_internal(modlist, modop | LDAP_MOD_BVALUES, attribute, NULL, value);
    588616}
    589617
     
    593621*********************************************************************/
    594622
    595  void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
    596                       LDAPMod ***mods,
    597                       const char *attribute, const char *newval)
     623static void smbldap_make_mod_internal(LDAP *ldap_struct, LDAPMessage *existing,
     624                                      LDAPMod ***mods,
     625                                      const char *attribute, int op,
     626                                      const char *newval,
     627                                      const DATA_BLOB *newblob)
    598628{
    599629        char oldval[2048]; /* current largest allowed value is mungeddial */
    600630        bool existed;
     631        DATA_BLOB oldblob = data_blob_null;
    601632
    602633        if (attribute == NULL) {
     
    607638
    608639        if (existing != NULL) {
    609                 existed = smbldap_get_single_attribute(ldap_struct, existing, attribute, oldval, sizeof(oldval));
     640                if (op & LDAP_MOD_BVALUES) {
     641                        existed = smbldap_talloc_single_blob(talloc_tos(), ldap_struct, existing, attribute, &oldblob);
     642                } else {
     643                        existed = smbldap_get_single_attribute(ldap_struct, existing, attribute, oldval, sizeof(oldval));
     644                }
    610645        } else {
    611646                existed = False;
     
    613648        }
    614649
    615         /* all of our string attributes are case insensitive */
    616 
    617         if (existed && newval && (StrCaseCmp(oldval, newval) == 0)) {
    618 
    619                 /* Believe it or not, but LDAP will deny a delete and
    620                    an add at the same time if the values are the
    621                    same... */
    622                 DEBUG(10,("smbldap_make_mod: attribute |%s| not changed.\n", attribute));
    623                 return;
    624         }
    625 
    626650        if (existed) {
     651                bool equal = false;
     652                if (op & LDAP_MOD_BVALUES) {
     653                        equal = (newblob && (data_blob_cmp(&oldblob, newblob) == 0));
     654                } else {
     655                        /* all of our string attributes are case insensitive */
     656                        equal = (newval && (StrCaseCmp(oldval, newval) == 0));
     657                }
     658
     659                if (equal) {
     660                        /* Believe it or not, but LDAP will deny a delete and
     661                           an add at the same time if the values are the
     662                           same... */
     663                        DEBUG(10,("smbldap_make_mod: attribute |%s| not changed.\n", attribute));
     664                        return;
     665                }
     666
    627667                /* There has been no value before, so don't delete it.
    628668                 * Here's a possible race: We might end up with
     
    636676                 * you could add new value */
    637677
    638                 DEBUG(10,("smbldap_make_mod: deleting attribute |%s| values |%s|\n", attribute, oldval));
    639                 smbldap_set_mod(mods, LDAP_MOD_DELETE, attribute, oldval);
     678                if (op & LDAP_MOD_BVALUES) {
     679                        DEBUG(10,("smbldap_make_mod: deleting attribute |%s| blob\n", attribute));
     680                        smbldap_set_mod_blob(mods, LDAP_MOD_DELETE, attribute, &oldblob);
     681                } else {
     682                        DEBUG(10,("smbldap_make_mod: deleting attribute |%s| values |%s|\n", attribute, oldval));
     683                        smbldap_set_mod(mods, LDAP_MOD_DELETE, attribute, oldval);
     684                }
    640685        }
    641686
     
    644689           the old value, should it exist. */
    645690
    646         if ((newval != NULL) && (strlen(newval) > 0)) {
    647                 DEBUG(10,("smbldap_make_mod: adding attribute |%s| value |%s|\n", attribute, newval));
    648                 smbldap_set_mod(mods, LDAP_MOD_ADD, attribute, newval);
    649         }
     691        if (op & LDAP_MOD_BVALUES) {
     692                if (newblob && newblob->length) {
     693                        DEBUG(10,("smbldap_make_mod: adding attribute |%s| blob\n", attribute));
     694                        smbldap_set_mod_blob(mods, LDAP_MOD_ADD, attribute, newblob);
     695                }
     696        } else {
     697                if ((newval != NULL) && (strlen(newval) > 0)) {
     698                        DEBUG(10,("smbldap_make_mod: adding attribute |%s| value |%s|\n", attribute, newval));
     699                        smbldap_set_mod(mods, LDAP_MOD_ADD, attribute, newval);
     700                }
     701        }
     702}
     703
     704 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing,
     705                      LDAPMod ***mods,
     706                      const char *attribute, const char *newval)
     707{
     708        smbldap_make_mod_internal(ldap_struct, existing, mods, attribute,
     709                                  0, newval, NULL);
     710}
     711
     712 void smbldap_make_mod_blob(LDAP *ldap_struct, LDAPMessage *existing,
     713                            LDAPMod ***mods,
     714                            const char *attribute, const DATA_BLOB *newblob)
     715{
     716        smbldap_make_mod_internal(ldap_struct, existing, mods, attribute,
     717                                  LDAP_MOD_BVALUES, NULL, newblob);
    650718}
    651719
     
    745813*******************************************************************/
    746814
    747 int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri)
     815static int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri)
    748816{
    749817        int rc;
     
    849917 *******************************************************************/
    850918
    851 int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version)
     919static int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version)
    852920{
    853921        int version;
     
    9621030{
    9631031        struct smbldap_state *ldap_state = arg;
     1032        struct timespec ts;
    9641033
    9651034        /** @TODO Should we be doing something to check what servers we rebind to?
     
    9941063        }
    9951064
    996         GetTimeOfDay(&ldap_state->last_rebind);
     1065        clock_gettime_mono(&ts);
     1066        ldap_state->last_rebind = convert_timespec_to_timeval(ts);
    9971067
    9981068        return 0;
     
    10141084                (struct smbldap_state *)arg;
    10151085        int rc;
     1086        struct timespec ts;
    10161087        int version;
    10171088
     
    10461117                                "setting last_rebind timestamp "
    10471118                                "(req: 0x%02x)\n", (unsigned int)request));
    1048                         GetTimeOfDay(&ldap_state->last_rebind);
     1119                        clock_gettime_mono(&ts);
     1120                        ldap_state->last_rebind = convert_timespec_to_timeval(ts);
    10491121                        break;
    10501122                default:
     
    11791251static void smbldap_idle_fn(struct event_context *event_ctx,
    11801252                            struct timed_event *te,
    1181                             struct timeval now,
     1253                            struct timeval now_abs,
    11821254                            void *private_data);
    11831255
     
    11911263        SMB_ASSERT(ldap_state);
    11921264
    1193         if ((ldap_state->ldap_struct != NULL) && ((ldap_state->last_ping + SMBLDAP_DONT_PING_TIME) < time(NULL))) {
     1265        if ((ldap_state->ldap_struct != NULL) && ((ldap_state->last_ping + SMBLDAP_DONT_PING_TIME) < time_mono(NULL))) {
    11941266
    11951267#ifdef HAVE_UNIXSOCKET
     
    12151287                        ldap_state->last_ping = (time_t)0;
    12161288                } else {
    1217                         ldap_state->last_ping = time(NULL);
     1289                        ldap_state->last_ping = time_mono(NULL);
    12181290                }
    12191291        }
     
    12331305
    12341306
    1235         ldap_state->last_ping = time(NULL);
     1307        ldap_state->last_ping = time_mono(NULL);
    12361308        ldap_state->pid = sys_getpid();
    12371309
     
    12851357                            int *attempts, time_t endtime)
    12861358{
    1287         time_t now = time(NULL);
     1359        time_t now = time_mono(NULL);
    12881360        int open_rc = LDAP_SERVER_DOWN;
    12891361
     
    13581430        int             attempts = 0;
    13591431        char           *utf8_filter;
    1360         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1432        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    13611433        struct          timeval timeout;
    13621434        size_t          converted_size;
     
    13691441        if (ldap_state->last_rebind.tv_sec > 0) {
    13701442                struct timeval  tval;
     1443                struct timespec ts;
    13711444                int64_t tdiff = 0;
    13721445                int             sleep_time = 0;
    13731446
    1374                 ZERO_STRUCT(tval);
    1375                 GetTimeOfDay(&tval);
     1447                clock_gettime_mono(&ts);
     1448                tval = convert_timespec_to_timeval(ts);
    13761449
    13771450                tdiff = usec_time_diff(&tval, &ldap_state->last_rebind);
     
    14071480
    14081481        got_alarm = 0;
    1409         CatchSignal(SIGALRM, SIGNAL_CAST gotalarm_sig);
     1482        CatchSignal(SIGALRM, gotalarm_sig);
    14101483        alarm(lp_ldap_timeout());
    14111484        /* End setup timeout. */
     
    14421515
    14431516        /* Teardown timeout. */
    1444         CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
     1517        CatchSignal(SIGALRM, SIG_IGN);
    14451518        alarm(0);
    14461519
     
    15561629        int             attempts = 0;
    15571630        char           *utf8_dn;
    1558         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1631        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    15591632        size_t          converted_size;
    15601633
     
    16001673        int             attempts = 0;
    16011674        char           *utf8_dn;
    1602         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1675        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    16031676        size_t          converted_size;
    16041677
     
    16441717        int             attempts = 0;
    16451718        char           *utf8_dn;
    1646         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1719        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    16471720        size_t          converted_size;
    16481721
     
    16901763        int             rc = LDAP_SERVER_DOWN;
    16911764        int             attempts = 0;
    1692         time_t          endtime = time(NULL)+lp_ldap_timeout();
     1765        time_t          endtime = time_mono(NULL)+lp_ldap_timeout();
    16931766
    16941767        if (!ldap_state)
     
    17371810static void smbldap_idle_fn(struct event_context *event_ctx,
    17381811                            struct timed_event *te,
    1739                             struct timeval now,
     1812                            struct timeval now_abs,
    17401813                            void *private_data)
    17411814{
     
    17491822        }
    17501823
    1751         if ((state->last_use+SMBLDAP_IDLE_TIME) > now.tv_sec) {
     1824        if ((state->last_use+SMBLDAP_IDLE_TIME) > time_mono(NULL)) {
    17521825                DEBUG(10,("ldap connection not idle...\n"));
    17531826
     1827                /* this needs to be made monotonic clock aware inside tevent: */
    17541828                state->idle_event = event_add_timed(
    17551829                        event_ctx, state,
    1756                         timeval_add(&now, SMBLDAP_IDLE_TIME, 0),
     1830                        timeval_add(&now_abs, SMBLDAP_IDLE_TIME, 0),
    17571831                        smbldap_idle_fn,
    17581832                        private_data);
Note: See TracChangeset for help on using the changeset viewer.