~ubuntu-branches/ubuntu/lucid/openldap/lucid-proposed

« back to all changes in this revision

Viewing changes to libraries/liblutil/utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Steve Langasek, Mathias Gug
  • Date: 2009-02-18 18:44:00 UTC
  • mfrom: (1.1.2 upstream) (0.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20090218184400-zw4mjse9eywt5566
Tags: 2.4.14-0ubuntu1
[ Steve Langasek ]
* New upstream version
  - Fixes a bug with the pcache overlay not returning cached entries
    (closes: #497697)
  - Update evolution-ntlm patch to apply to current Makefiles.
  - (tentatively) drop gnutls-ciphers, since this bug was reported to be
    fixed upstream in 2.4.8.  The fix applied in 2.4.8 didn't match the
    patch from the bug report, so this should be watched for regressions.
* Build against db4.7 instead of db4.2 at last!  Closes: #421946.
* Build with --disable-ndb, to avoid a misbuild when libmysqlclient is
  installed in the build environment.
* New patch, no-crlcheck-for-gnutls, to fix a build failure when using
  --with-tls=gnutls.

[ Mathias Gug ]
* Merge from debian unstable, remaining changes:
  - debian/apparmor-profile: add AppArmor profile
  - debian/slapd.postinst: Reload AA profile on configuration
  - updated debian/slapd.README.Debian for note on AppArmor
  - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6
  - debian/control: Conflicts with apparmor-profiles << 2.1+1075-0ubuntu4
    to make sure that if earlier version of apparmour-profiles gets
    installed it won't overwrite our profile.
  - Modify Maintainer value to match the DebianMaintainerField
    speficication.
  - follow ApparmorProfileMigration and force apparmor compalin mode on 
    some upgrades (LP: #203529)
  - debian/slapd.dirs: add etc/apparmor.d/force-complain
  - debian/slapd.preinst: create symlink for force-complain on pre-feisty
    upgrades, upgrades where apparmor-profiles profile is unchanged (ie
    non-enforcing) and upgrades where apparmor profile does not exist.
  - debian/slapd.postrm: remove symlink in force-complain/ on purge
  - debian/patches/fix-ucred-libc due to changes how newer glibc handle
    the ucred struct now.
  - debian/control:
    - Build-depend on libltdl7-dev rather then libltdl3-dev.
  - debian/patches/autogen.sh:
    - Call libtoolize with the --install option to install config.{guess,sub}
      files.
  - Don't use local statement in config script as it fails if /bin/sh
    points to bash (LP: #286063).
  - Disable the testsuite on hppa. Allows building of packages on this
    architecture again, once this package is in the archive.
    LP: #288908.
  - debian/slapd.postinst, debian/slapd.script-common: set correct ownership
    and permissions on /var/lib/ldap, /etc/ldap/slapd.d (group readable) and
    /var/run/slapd (world readable). (LP: #257667).
  - debian/patches/nssov-build, debian/rules: 
    Build and package the nss overlay.
    debian/schema/misc.ldif: add ldif file for the misc schema, which defines
    rfc822MailMember (required by the nss overlay).
  - debian/{control,rules}: enable PIE hardening
  - Use cn=config as the default configuration backend instead of 
    slapd.conf. Migrate slapd.conf  file to /etc/ldap/slapd.d/ on upgrade
    asking the end user to enter a new password to control the access to the
    cn=config tree.
* debian/patches/corrupt-contextCSN: The contextCSN can get corrupted at
  times. (ITS: #5947)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $OpenLDAP: pkg/ldap/libraries/liblutil/utils.c,v 1.33.2.17 2008/02/11 23:26:42 kurt Exp $ */
 
1
/* $OpenLDAP: pkg/ldap/libraries/liblutil/utils.c,v 1.33.2.23 2009/01/22 00:00:58 kurt Exp $ */
2
2
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3
3
 *
4
 
 * Copyright 1998-2008 The OpenLDAP Foundation.
 
4
 * Copyright 1998-2009 The OpenLDAP Foundation.
5
5
 * All rights reserved.
6
6
 *
7
7
 * Redistribution and use in source and binary forms, with or without
77
77
        LUTIL_SLASHPATH( argv[0] );
78
78
        progname = strrchr ( argv[0], *LDAP_DIRSEP );
79
79
        progname = progname ? &progname[1] : argv[0];
 
80
#ifdef _WIN32
 
81
        {
 
82
                size_t len = strlen( progname );
 
83
                if ( len > 4 && strcasecmp( &progname[len - 4], ".exe" ) == 0 )
 
84
                        progname[len - 4] = '\0';
 
85
        }
 
86
#endif
80
87
        return progname;
81
88
}
82
89
 
296
303
        GetSystemTime( &st );
297
304
        QueryPerformanceCounter( &count );
298
305
 
 
306
        /* It shouldn't ever go backwards, but multiple CPUs might
 
307
         * be able to hit in the same tick.
 
308
         */
 
309
        if ( count.QuadPart <= prevCount.QuadPart ) {
 
310
                subs++;
 
311
        } else {
 
312
                subs = 0;
 
313
                prevCount = count;
 
314
        }
 
315
 
299
316
        /* We assume Windows has at least a vague idea of
300
317
         * when a second begins. So we align our microsecond count
301
318
         * with the Windows millisecond count using this offset.
302
319
         * We retain the submillisecond portion of our own count.
 
320
         *
 
321
         * Note - this also assumes that the relationship between
 
322
         * the PerformanceCouunter and SystemTime stays constant;
 
323
         * that assumption breaks if the SystemTime is adjusted by
 
324
         * an external action.
303
325
         */
304
326
        if ( !cFreq.QuadPart ) {
305
327
                long long t;
306
328
                int usec;
307
329
                QueryPerformanceFrequency( &cFreq );
308
330
 
309
 
                t = count.QuadPart * 1000000;
310
 
                t /= cFreq.QuadPart;
311
 
                usec = t % 10000000;
312
 
                usec /= 1000;
313
 
                offset = ( usec - st.wMilliseconds ) * 1000;
314
 
        }
315
 
 
316
 
        /* It shouldn't ever go backwards, but multiple CPUs might
317
 
         * be able to hit in the same tick.
318
 
         */
319
 
        if ( count.QuadPart <= prevCount.QuadPart ) {
320
 
                subs++;
321
 
        } else {
322
 
                subs = 0;
323
 
                prevCount = count;
 
331
                /* just get sub-second portion of counter */
 
332
                t = count.QuadPart % cFreq.QuadPart;
 
333
 
 
334
                /* convert to microseconds */
 
335
                t *= 1000000;
 
336
                usec = t / cFreq.QuadPart;
 
337
 
 
338
                offset = usec - st.wMilliseconds * 1000;
324
339
        }
325
340
 
326
341
        tm->tm_usub = subs;
327
342
 
328
343
        /* convert to microseconds */
 
344
        count.QuadPart %= cFreq.QuadPart;
329
345
        count.QuadPart *= 1000000;
330
346
        count.QuadPart /= cFreq.QuadPart;
331
347
        count.QuadPart -= offset;
332
348
 
333
349
        tm->tm_usec = count.QuadPart % 1000000;
 
350
        if ( tm->tm_usec < 0 )
 
351
                tm->tm_usec += 1000000;
334
352
 
335
353
        /* any difference larger than microseconds is
336
354
         * already reflected in st
421
439
        return a-1;
422
440
}
423
441
 
 
442
/* memcopy is like memcpy except it returns a pointer to the byte past
 
443
 * the end of the result buffer, set to NULL. This allows fast construction
 
444
 * of catenated buffers.  Provided for API consistency with lutil_str*copy().
 
445
 */
 
446
char *
 
447
lutil_memcopy(
 
448
        char *a,
 
449
        const char *b,
 
450
        size_t n
 
451
)
 
452
{
 
453
        AC_MEMCPY(a, b, n);
 
454
        return a + n;
 
455
}
 
456
 
424
457
#ifndef HAVE_MKSTEMP
425
458
int mkstemp( char * template )
426
459
{
677
710
{
678
711
        char *pin, *pout, ctmp;
679
712
        char *end;
680
 
        long l;
681
713
        int i, chunk, len, rc = 0, hex = 0;
682
714
        if ( !out || !out->bv_val || out->bv_len < in->bv_len )
683
715
                return -1;
700
732
        }
701
733
        if ( hex ) {
702
734
#define HEXMAX  (2 * sizeof(long))
 
735
                unsigned long l;
703
736
                /* Convert a longword at a time, but handle leading
704
737
                 * odd bytes first
705
738
                 */
706
 
                chunk = len & (HEXMAX-1);
 
739
                chunk = len % HEXMAX;
707
740
                if ( !chunk )
708
741
                        chunk = HEXMAX;
709
742
 
710
743
                while ( len ) {
 
744
                        int ochunk;
711
745
                        ctmp = pin[chunk];
712
746
                        pin[chunk] = '\0';
713
747
                        errno = 0;
714
 
                        l = strtol( pin, &end, 16 );
 
748
                        l = strtoul( pin, &end, 16 );
715
749
                        pin[chunk] = ctmp;
716
750
                        if ( errno )
717
751
                                return -1;
718
 
                        chunk++;
719
 
                        chunk >>= 1;
720
 
                        for ( i = chunk; i>=0; i-- ) {
 
752
                        ochunk = (chunk + 1)/2;
 
753
                        for ( i = ochunk - 1; i >= 0; i-- ) {
721
754
                                pout[i] = l & 0xff;
722
755
                                l >>= 8;
723
756
                        }
724
757
                        pin += chunk;
725
 
                        pout += sizeof(long);
 
758
                        pout += ochunk;
726
759
                        len -= chunk;
727
760
                        chunk = HEXMAX;
728
761
                }
729
 
                out->bv_len = pout + len - out->bv_val;
 
762
                out->bv_len = pout - out->bv_val;
730
763
        } else {
731
764
        /* Decimal */
732
765
                char tmpbuf[64], *tmp;
733
766
                lutil_int_decnum num;
734
767
                int neg = 0;
 
768
                long l;
735
769
 
736
770
                len = in->bv_len;
737
771
                pin = in->bv_val;
921
955
                *len = ret;
922
956
        }
923
957
 
924
 
        if ( ret >= bufsize ) {
 
958
        if ( (unsigned) ret >= bufsize ) {
925
959
                if ( next ) {
926
960
                        *next = &buf[ bufsize - 1 ];
927
961
                }