Changeset 740 for vendor/current/source3/lib/smbldap.c
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source3/lib/smbldap.c
r618 r740 25 25 #include "includes.h" 26 26 #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" 31 29 32 30 /* Try not to hit the up or down server forever */ … … 508 506 ***********************************************************************/ 509 507 510 void smbldap_set_mod (LDAPMod *** modlist, int modop, const char *attribute, const char *value)508 static void smbldap_set_mod_internal(LDAPMod *** modlist, int modop, const char *attribute, const char *value, const DATA_BLOB *blob) 511 509 { 512 510 LDAPMod **mods; … … 559 557 } 560 558 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) { 562 580 char *utf8_value = NULL; 563 581 size_t converted_size; … … 586 604 } 587 605 *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); 588 616 } 589 617 … … 593 621 *********************************************************************/ 594 622 595 void smbldap_make_mod(LDAP *ldap_struct, LDAPMessage *existing, 596 LDAPMod ***mods, 597 const char *attribute, const char *newval) 623 static 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) 598 628 { 599 629 char oldval[2048]; /* current largest allowed value is mungeddial */ 600 630 bool existed; 631 DATA_BLOB oldblob = data_blob_null; 601 632 602 633 if (attribute == NULL) { … … 607 638 608 639 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 } 610 645 } else { 611 646 existed = False; … … 613 648 } 614 649 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 and620 an add at the same time if the values are the621 same... */622 DEBUG(10,("smbldap_make_mod: attribute |%s| not changed.\n", attribute));623 return;624 }625 626 650 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 627 667 /* There has been no value before, so don't delete it. 628 668 * Here's a possible race: We might end up with … … 636 676 * you could add new value */ 637 677 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 } 640 685 } 641 686 … … 644 689 the old value, should it exist. */ 645 690 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); 650 718 } 651 719 … … 745 813 *******************************************************************/ 746 814 747 int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri)815 static int smb_ldap_setup_conn(LDAP **ldap_struct, const char *uri) 748 816 { 749 817 int rc; … … 849 917 *******************************************************************/ 850 918 851 int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version) 919 static int smb_ldap_upgrade_conn(LDAP *ldap_struct, int *new_version) 852 920 { 853 921 int version; … … 962 1030 { 963 1031 struct smbldap_state *ldap_state = arg; 1032 struct timespec ts; 964 1033 965 1034 /** @TODO Should we be doing something to check what servers we rebind to? … … 994 1063 } 995 1064 996 GetTimeOfDay(&ldap_state->last_rebind); 1065 clock_gettime_mono(&ts); 1066 ldap_state->last_rebind = convert_timespec_to_timeval(ts); 997 1067 998 1068 return 0; … … 1014 1084 (struct smbldap_state *)arg; 1015 1085 int rc; 1086 struct timespec ts; 1016 1087 int version; 1017 1088 … … 1046 1117 "setting last_rebind timestamp " 1047 1118 "(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); 1049 1121 break; 1050 1122 default: … … 1179 1251 static void smbldap_idle_fn(struct event_context *event_ctx, 1180 1252 struct timed_event *te, 1181 struct timeval now ,1253 struct timeval now_abs, 1182 1254 void *private_data); 1183 1255 … … 1191 1263 SMB_ASSERT(ldap_state); 1192 1264 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))) { 1194 1266 1195 1267 #ifdef HAVE_UNIXSOCKET … … 1215 1287 ldap_state->last_ping = (time_t)0; 1216 1288 } else { 1217 ldap_state->last_ping = time (NULL);1289 ldap_state->last_ping = time_mono(NULL); 1218 1290 } 1219 1291 } … … 1233 1305 1234 1306 1235 ldap_state->last_ping = time (NULL);1307 ldap_state->last_ping = time_mono(NULL); 1236 1308 ldap_state->pid = sys_getpid(); 1237 1309 … … 1285 1357 int *attempts, time_t endtime) 1286 1358 { 1287 time_t now = time (NULL);1359 time_t now = time_mono(NULL); 1288 1360 int open_rc = LDAP_SERVER_DOWN; 1289 1361 … … 1358 1430 int attempts = 0; 1359 1431 char *utf8_filter; 1360 time_t endtime = time (NULL)+lp_ldap_timeout();1432 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1361 1433 struct timeval timeout; 1362 1434 size_t converted_size; … … 1369 1441 if (ldap_state->last_rebind.tv_sec > 0) { 1370 1442 struct timeval tval; 1443 struct timespec ts; 1371 1444 int64_t tdiff = 0; 1372 1445 int sleep_time = 0; 1373 1446 1374 ZERO_STRUCT(tval);1375 GetTimeOfDay(&tval);1447 clock_gettime_mono(&ts); 1448 tval = convert_timespec_to_timeval(ts); 1376 1449 1377 1450 tdiff = usec_time_diff(&tval, &ldap_state->last_rebind); … … 1407 1480 1408 1481 got_alarm = 0; 1409 CatchSignal(SIGALRM, SIGNAL_CASTgotalarm_sig);1482 CatchSignal(SIGALRM, gotalarm_sig); 1410 1483 alarm(lp_ldap_timeout()); 1411 1484 /* End setup timeout. */ … … 1442 1515 1443 1516 /* Teardown timeout. */ 1444 CatchSignal(SIGALRM, SIG NAL_CAST SIG_IGN);1517 CatchSignal(SIGALRM, SIG_IGN); 1445 1518 alarm(0); 1446 1519 … … 1556 1629 int attempts = 0; 1557 1630 char *utf8_dn; 1558 time_t endtime = time (NULL)+lp_ldap_timeout();1631 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1559 1632 size_t converted_size; 1560 1633 … … 1600 1673 int attempts = 0; 1601 1674 char *utf8_dn; 1602 time_t endtime = time (NULL)+lp_ldap_timeout();1675 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1603 1676 size_t converted_size; 1604 1677 … … 1644 1717 int attempts = 0; 1645 1718 char *utf8_dn; 1646 time_t endtime = time (NULL)+lp_ldap_timeout();1719 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1647 1720 size_t converted_size; 1648 1721 … … 1690 1763 int rc = LDAP_SERVER_DOWN; 1691 1764 int attempts = 0; 1692 time_t endtime = time (NULL)+lp_ldap_timeout();1765 time_t endtime = time_mono(NULL)+lp_ldap_timeout(); 1693 1766 1694 1767 if (!ldap_state) … … 1737 1810 static void smbldap_idle_fn(struct event_context *event_ctx, 1738 1811 struct timed_event *te, 1739 struct timeval now ,1812 struct timeval now_abs, 1740 1813 void *private_data) 1741 1814 { … … 1749 1822 } 1750 1823 1751 if ((state->last_use+SMBLDAP_IDLE_TIME) > now.tv_sec) {1824 if ((state->last_use+SMBLDAP_IDLE_TIME) > time_mono(NULL)) { 1752 1825 DEBUG(10,("ldap connection not idle...\n")); 1753 1826 1827 /* this needs to be made monotonic clock aware inside tevent: */ 1754 1828 state->idle_event = event_add_timed( 1755 1829 event_ctx, state, 1756 timeval_add(&now , SMBLDAP_IDLE_TIME, 0),1830 timeval_add(&now_abs, SMBLDAP_IDLE_TIME, 0), 1757 1831 smbldap_idle_fn, 1758 1832 private_data);
Note:
See TracChangeset
for help on using the changeset viewer.