s3-param Use .offset rather than .ptr when defining parameters
authorAndrew Bartlett <abartlet@samba.org>
Wed, 29 Jun 2011 00:49:35 +0000 (10:49 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 29 Jun 2011 03:50:46 +0000 (05:50 +0200)
This change has a number of purposes:

 * It removes the fancy logic around pointers into sDefault for all
   per-share parameters.  Instead, this is always expressed as an
   offset, rather than implicitly via PTR_DIFF macros.

 * It makes struct parm_struct almost identical to that as used in
   source4/param.  This will very shortly allow the loadparm tables
   and most of the 'special' helper functions to be placed in common.

Andrew Bartlett

Autobuild-User: Andrew Bartlett <abartlet@samba.org>
Autobuild-Date: Wed Jun 29 05:50:46 CEST 2011 on sn-devel-104

source3/include/smb.h
source3/param/loadparm.c

index f46a58ef11829fed1081beb5a58d8d0277731f66..25e3bacc729a80117c85f13216b20a0a89ebcf71 100644 (file)
@@ -731,7 +731,7 @@ struct parm_struct {
        const char *label;
        parm_type type;
        parm_class p_class;
-       void *ptr;
+       offset_t offset;
        bool (*special)(int snum, const char *, char **);
        const struct enum_list *enum_list;
        unsigned flags;
index 7da3de393ab41bd7d647f200e88070ff2056b70d..430c2de5ac76f6834d52177004ee83b646e888a8 100644 (file)
@@ -930,9 +930,8 @@ static const struct enum_list enum_kerberos_method[] = {
  *     name first, and all synonyms must follow it with the FLAG_HIDE attribute.
  */
 
-#define GLOBAL_VAR(name) &Globals.name
-#define LOCAL_VAR(name) &sDefault.name
-#define offset ptr
+#define GLOBAL_VAR(name) offsetof(struct loadparm_global, name)
+#define LOCAL_VAR(name) offsetof(struct loadparm_service, name)
 
 static struct parm_struct parm_table[] = {
        {N_("Base Options"), P_SEP, P_SEPARATOR},
@@ -7755,12 +7754,12 @@ void *lp_parm_ptr(struct loadparm_service *service, struct parm_struct *parm)
 {
        if (service == NULL) {
                if (parm->p_class == P_LOCAL)
-                       return parm->ptr;
+                       return (void *)(((char *)&sDefault)+parm->offset);
                else if (parm->p_class == P_GLOBAL)
-                       return parm->ptr;
+                       return (void *)(((char *)&Globals)+parm->offset);
                else return NULL;
        } else {
-               return (void *)(((char *)service) + PTR_DIFF(parm->ptr, &sDefault));
+               return (void *)(((char *)service) + parm->offset);
        }
 }