'ulong' in LDAP code makes build under FreeBSD break

Charles Owens owensc at enc.edu
Thu Aug 12 12:37:15 GMT 1999


The LDAP code in about six spots makes use of a 'ulong' cast that makes compilation under
FreeBSD fail (and probably some other OSes as well).

I'd found that changing every 'ulong' to simply 'long' got around the problem.  Luke
Leighton suggested that I try removing the 'ulong' cast altogether.  This allows
compilation to succeed, but produces warnings (see below).

So, the question is, in place of the (ulong) casts, how _should_ this be written that
would be the most platform-neutral and compile-warning free?  It appears in source in
these two formats (this taken from passdb/ldap.c):

    return (SMB_BIG_UINT)((ulong)ldap_entry);

    ldap_entry = (LDAPMessage *)((ulong)tok);

Appended below is my discussion with Luke to date.

Thanks!

Charles Owens wrote:

> Okay... I've simply removed every occurance of "(ulong)".  It at least compiles now,
> but not having some kind of cast there makes each spot that I've editted now produce
> a compile warning like this:
>
> groupdb/groupldap.c: In function `ldapgroup_getdbpos':
> groupdb/groupldap.c:201: warning: cast from pointer to integer of different size
>
> It's going to take me probably until tomorrow to know if this latest build still
> works (LDAP-wise, that is)... in the mean-time... it there something more
> platform-neutral that should be in there instead of the (ulong) cast that would quiet
> these warnings?
>
> Sorry about my C-greenness.  Haven't done much with it since getting bit by the Perl
> thing...  ;-)
>
> The diff is below.
>
> Thanks,
>
> Chuck
>
> diff -x bin -x *.o -uNr source.orig/groupdb/aliasldap.c source/groupdb/aliasldap.c
> --- source.orig/groupdb/aliasldap.c     Wed Aug 11 15:41:12 1999
> +++ source/groupdb/aliasldap.c  Wed Aug 11 15:44:28 1999
> @@ -189,12 +189,12 @@
>
>  static SMB_BIG_UINT ldapalias_getdbpos(void *vp)
>  {
> -       return (SMB_BIG_UINT)((ulong)ldap_entry);
> +       return (SMB_BIG_UINT)(ldap_entry);
>  }
>
>  static BOOL ldapalias_setdbpos(void *vp, SMB_BIG_UINT tok)
>  {
> -       ldap_entry = (LDAPMessage *)((ulong)tok);
> +       ldap_entry = (LDAPMessage *)(tok);
>         return (True);
>  }
>
> diff -x bin -x *.o -uNr source.orig/groupdb/builtinldap.c source/groupdb/builtinldap.c
> --- source.orig/groupdb/builtinldap.c   Wed Aug 11 15:41:12 1999
> +++ source/groupdb/builtinldap.c        Wed Aug 11 15:44:39 1999
> @@ -190,12 +190,12 @@
>
>  static SMB_BIG_UINT ldapbuiltin_getdbpos(void *vp)
>  {
> -       return (SMB_BIG_UINT)((ulong)ldap_entry);
> +       return (SMB_BIG_UINT)(ldap_entry);
>  }
>
>  static BOOL ldapbuiltin_setdbpos(void *vp, SMB_BIG_UINT tok)
>  {
> -       ldap_entry = (LDAPMessage *)((ulong)tok);
> +       ldap_entry = (LDAPMessage *)(tok);
>         return (True);
>  }
>
> diff -x bin -x *.o -uNr source.orig/groupdb/groupldap.c source/groupdb/groupldap.c
> --- source.orig/groupdb/groupldap.c     Wed Aug 11 15:41:12 1999
> +++ source/groupdb/groupldap.c  Wed Aug 11 15:44:55 1999
> @@ -198,12 +198,12 @@
>
>  static SMB_BIG_UINT ldapgroup_getdbpos(void *vp)
>  {
> -       return (SMB_BIG_UINT)((ulong)ldap_entry);
> +       return (SMB_BIG_UINT)(ldap_entry);
>  }
>
>  static BOOL ldapgroup_setdbpos(void *vp, SMB_BIG_UINT tok)
>  {
> -       ldap_entry = (LDAPMessage *)((ulong)tok);
> +       ldap_entry = (LDAPMessage *)(tok);
>         return (True);
>  }
>
> diff -x bin -x *.o -uNr source.orig/passdb/ldap.c source/passdb/ldap.c
> --- source.orig/passdb/ldap.c   Wed Aug 11 15:41:08 1999
> +++ source/passdb/ldap.c        Wed Aug 11 15:42:55 1999
> @@ -436,12 +436,12 @@
>
>  static SMB_BIG_UINT ldap_getdbpos(void *vp)
>  {
> -       return (SMB_BIG_UINT)((ulong)ldap_entry);
> +       return (SMB_BIG_UINT)(ldap_entry);
>  }
>
>  static BOOL ldap_setdbpos(void *vp, SMB_BIG_UINT tok)
>  {
> -       ldap_entry = (LDAPMessage *)((ulong)tok);
> +       ldap_entry = (LDAPMessage *)(tok);
>         return (True);
>  }
>
> diff -x bin -x *.o -uNr source.orig/passdb/passgrpldap.c source/passdb/passgrpldap.c
> --- source.orig/passdb/passgrpldap.c    Wed Aug 11 15:41:08 1999
> +++ source/passdb/passgrpldap.c Wed Aug 11 15:43:13 1999
> @@ -86,12 +86,12 @@
>
>  static SMB_BIG_UINT ldappassgrp_getdbpos(void *vp)
>  {
> -       return (SMB_BIG_UINT)((ulong)ldap_entry);
> +       return (SMB_BIG_UINT)(ldap_entry);
>  }
>
>  static BOOL ldappassgrp_setdbpos(void *vp, SMB_BIG_UINT tok)
>  {
> -       ldap_entry = (LDAPMessage *)((ulong)tok);
> +       ldap_entry = (LDAPMessage *)(tok);
>         return (True);
>  }
>
> diff -x bin -x *.o -uNr source.orig/passdb/sampassldap.c source/passdb/sampassldap.c
> --- source.orig/passdb/sampassldap.c    Wed Aug 11 15:41:08 1999
> +++ source/passdb/sampassldap.c Wed Aug 11 15:43:27 1999
> @@ -283,12 +283,12 @@
>
>  static SMB_BIG_UINT ldapsam_getdbpos(void *vp)
>  {
> -       return (SMB_BIG_UINT)((ulong)ldap_entry);
> +       return (SMB_BIG_UINT)(ldap_entry);
>  }
>
>  static BOOL ldapsam_setdbpos(void *vp, SMB_BIG_UINT tok)
>  {
> -       ldap_entry = (LDAPMessage *)((ulong)tok);
> +       ldap_entry = (LDAPMessage *)(tok);
>         return (True);
>  }
>
> Luke Kenneth Casson Leighton wrote:
>
> > On Wed, 11 Aug 1999, Charles Owens wrote:
> >
> > > How does SMB_BIG_UINT sound?
> >
> > good.
> >
> > > Below I list all occurances of ulong (I think).  Note the two stages of casting
> > > going on.  (first to ulong, then to something else... sometimes SMB_BIG_UINT).
> >
> > well if you look at passdb/smbpass.c getsmbfilepwpos() then jump to
> > lib/util_file.c getfilepwpos() you see that the ulong cast isn't there:
> > the return result is cast direct to SMB_BIG_UINT.
> >
> > please try this out then send me a diff -u patch.
> >
> > thx!
> >
> > > How _should_ this be written (and will someone please check the fix into the
> > > CVS repositiory)?  I'm not enough of a C guy to know what's appropriate here
> > > (or even if I'm interpreting the current code).
> > >
> > > Note that under FreeBSD, simply changing every 'ulong' to 'long' at least gets
> > > to code to build... and it seems to work well enough.
> > >
> > >
> > > noah# pwd
> > > .../samba/source/passdb
> > > noah# grep ulong *
> > > ldap.c: return (SMB_BIG_UINT)((ulong)ldap_entry);
> > > ldap.c: ldap_entry = (LDAPMessage *)((ulong)tok);
> > > passgrpldap.c:  return (SMB_BIG_UINT)((ulong)ldap_entry);
> > > passgrpldap.c:  ldap_entry = (LDAPMessage *)((ulong)tok);
> > > sampassldap.c:  return (SMB_BIG_UINT)((ulong)ldap_entry);
> > > sampassldap.c:  ldap_entry = (LDAPMessage *)((ulong)tok);
> > >
> > > noah# cd ../groupdb
> > > noah# grep ulong *
> > > aliasldap.c:    return (SMB_BIG_UINT)((ulong)ldap_entry);
> > > aliasldap.c:    ldap_entry = (LDAPMessage *)((ulong)tok);
> > > builtinldap.c:  return (SMB_BIG_UINT)((ulong)ldap_entry);
> > > builtinldap.c:  ldap_entry = (LDAPMessage *)((ulong)tok);
> > > groupldap.c:    return (SMB_BIG_UINT)((ulong)ldap_entry);
> > > groupldap.c:    ldap_entry = (LDAPMessage *)((ulong)tok);
> > >
> > > Thanks!
> > >
> > > Luke Kenneth Casson Leighton wrote:
> > >
> > > > charles,
> > > >
> > > > we shouldn't be using ulong, strictly speaking, as it's variable length
> > > > (platform dependent).  should be using uint32 instead.  urm....
> > > > ldapsam_getdbpos?  check smbpasswd code, should be using SMB_BIGINT or
> > > > something like that, not a ulong.
> > > >
> > > > luke
> > > >
> > > > On Wed, 11 Aug 1999, Charles Owens wrote:
> > > >
> > > > > For example...
> > > > >
> > > > > Compiling passdb/sampass.c
> > > > > Compiling passdb/sampassldap.c
> > > > > passdb/sampassldap.c: In function `ldapsam_getdbpos':
> > > > > passdb/sampassldap.c:286: `ulong' undeclared (first use this function)
> > > > > passdb/sampassldap.c:286: (Each undeclared identifier is reported only
> > > > > once
> > > > > passdb/sampassldap.c:286: for each function it appears in.)
> > > > > passdb/sampassldap.c:286: parse error before `ldap_entry'
> > > > > passdb/sampassldap.c: In function `ldapsam_setdbpos':
> > > > > passdb/sampassldap.c:291: `ulong' undeclared (first use this function)
> > > > > passdb/sampassldap.c:291: parse error before `tok'
> > > > > *** Error code 1
> > > > >
> > > > > Stop.
> > > > >
> > > > >
> > > > > I've been able to get around this by changing every occurrance of
> > > > > 'ulong' to 'long' (in this file and several other LDAP-related)...
> > > > > but... is it kosher for me to do this?  What would be the correct way to
> > > > > get this to build under FreeBSD?  The hope is, of course, that the fix
> > > > > for this will eventually make it into the soures...
> > > > >
> > > > > ..some kind of conditional in a header file that defines 'ulong' if the
> > > > > OS is FreeBSD?
> > > > >
> > > > > BTW, I've hit this problem with using FreeBSD 3.1-stable and 3.2-stable.
> > > > >
> > > > >  Thanks much,
> > > > > ---
> > > > > -------------------------------------------------------------------------
> > > > >
> > > > >   Charles N. Owens                               Email:  owensc at enc.edu
> > > > >                                             http://www.enc.edu/~owensc
> > > > >   Network & Systems Administrator
> > > > >   Information Technology Services  "Outside of a dog, a book is a man's
> > > > >   Eastern Nazarene College         best friend.  Inside of a dog it's
> > > > >                                    too dark to read." - Groucho Marx
> > > > > -------------------------------------------------------------------------
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > > <a href="mailto:lkcl at samba.org"   > Luke Kenneth Casson Leighton    </a>
> > > > <a href="http://www.cb1.com/~lkcl"> Samba and Network Development   </a>
> > > > <a href="http://samba.org"        > Samba Web site                  </a>
> > > > <a href="http://www.iss.net"      > Internet Security Systems, Inc. </a>
> > >
> > > --
> > > ---
> > > -------------------------------------------------------------------------
> > >   Charles N. Owens                               Email:  owensc at enc.edu
> > >                                             http://www.enc.edu/~owensc
> > >   Network & Systems Administrator
> > >   Information Technology Services  "Outside of a dog, a book is a man's
> > >   Eastern Nazarene College         best friend.  Inside of a dog it's
> > >                                    too dark to read." - Groucho Marx
> > > -------------------------------------------------------------------------
> > >
> > >
> > >
> >
> > <a href="mailto:lkcl at samba.org"   > Luke Kenneth Casson Leighton    </a>
> > <a href="http://www.cb1.com/~lkcl"> Samba and Network Development   </a>
> > <a href="http://samba.org"        > Samba Web site                  </a>
> > <a href="http://www.iss.net"      > Internet Security Systems, Inc. </a>
>
> --
> ---
> -------------------------------------------------------------------------
>   Charles N. Owens                               Email:  owensc at enc.edu
>                                              http://www.enc.edu/~owensc
>   Network & Systems Administrator
>   Information Technology Services  "Outside of a dog, a book is a man's
>   Eastern Nazarene College         best friend.  Inside of a dog it's
>                                    too dark to read." - Groucho Marx
> -------------------------------------------------------------------------

--
---
-------------------------------------------------------------------------
  Charles N. Owens                               Email:  owensc at enc.edu
                                             http://www.enc.edu/~owensc
  Network & Systems Administrator
  Information Technology Services  "Outside of a dog, a book is a man's
  Eastern Nazarene College         best friend.  Inside of a dog it's
                                   too dark to read." - Groucho Marx
-------------------------------------------------------------------------




More information about the samba-technical mailing list