r1810: Patch from Richard Renard <rrenard@idealx.com> to store
authorJeremy Allison <jra@samba.org>
Fri, 13 Aug 2004 18:02:58 +0000 (18:02 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:52:21 +0000 (10:52 -0500)
logon hours attributes in an LDAP database.
Jeremy.
(This used to be commit dac72638fb3a05e805136698e0ad0612620ac8af)

source3/include/smbldap.h
source3/lib/smbldap.c
source3/passdb/passdb.c
source3/passdb/pdb_ldap.c

index 6046af464e6a966aab836d2efa47a3de36878c70..953937fb75d1aead91f2e4cde9a4fcd6bfc173c6 100644 (file)
@@ -96,6 +96,7 @@
 #define LDAP_ATTR_PWD_HISTORY          39
 #define LDAP_ATTR_SID_LIST             40
 #define LDAP_ATTR_MOD_TIMESTAMP                41
+#define LDAP_ATTR_LOGON_HOURS          42
 
 typedef struct _attrib_map_entry {
        int             attrib;
index 0980b763adbc63bb1fd1ce022ca165907c8d2fcb..e66fb3640cfc6601290b981dc10feefeb8aa95fc 100644 (file)
@@ -102,6 +102,7 @@ ATTRIB_MAP_ENTRY attrib_map_v30[] = {
        { LDAP_ATTR_BAD_PASSWORD_TIME,  "sambaBadPasswordTime"  },
        { LDAP_ATTR_PWD_HISTORY,        "sambaPasswordHistory"  },
        { LDAP_ATTR_MOD_TIMESTAMP,      "modifyTimestamp"       },
+       { LDAP_ATTR_LOGON_HOURS,        "sambaLogonHours"       },
        { LDAP_ATTR_LIST_END,           NULL                    }
 };
 
index e404f5af3f9145f3443f59d7fdc8e1098ad3cc7d..0905d8169203b0621f546a0a593d550487f3c071 100644 (file)
@@ -583,6 +583,57 @@ BOOL pdb_gethexpwd(const char *p, unsigned char *pwd)
        return (True);
 }
 
+/*************************************************************
+ Routine to set 42 hex hours characters from a 21 byte array.
+**************************************************************/
+
+void pdb_sethexhours(char *p, const unsigned char *hours)
+{
+       if (hours != NULL) {
+               int i;
+               for (i = 0; i < 21; i++) {
+                       slprintf(&p[i*2], 3, "%02X", hours[i]);
+               }
+       } else {
+               safe_strcpy(p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 43);
+       }
+}
+
+/*************************************************************
+ Routine to get the 42 hex characters and turn them
+ into a 21 byte array.
+**************************************************************/
+
+BOOL pdb_gethexhours(const char *p, unsigned char *hours)
+{
+       int i;
+       unsigned char   lonybble, hinybble;
+       const char      *hexchars = "0123456789ABCDEF";
+       char           *p1, *p2;
+
+       if (!p) {
+               return (False);
+       }
+
+       for (i = 0; i < 42; i += 2) {
+               hinybble = toupper(p[i]);
+               lonybble = toupper(p[i + 1]);
+
+               p1 = strchr(hexchars, hinybble);
+               p2 = strchr(hexchars, lonybble);
+
+               if (!p1 || !p2) {
+                       return (False);
+               }
+
+               hinybble = PTR_DIFF(p1, hexchars);
+               lonybble = PTR_DIFF(p2, hexchars);
+
+               hours[i / 2] = (hinybble << 4) | lonybble;
+       }
+       return (True);
+}
+
 int algorithmic_rid_base(void)
 {
        static int rid_offset = 0;
index 37cc0c79029765bdb260d180f567c8e47bc978bc..9af34705df50c05c74df316d907221db59808588 100644 (file)
@@ -782,7 +782,15 @@ static BOOL init_sam_from_ldap (struct ldapsam_privates *ldap_state,
 
        /* pdb_set_unknown_6(sampass, unknown6, PDB_SET); */
 
-       pdb_set_hours(sampass, hours, PDB_SET);
+       if(!smbldap_get_single_pstring(ldap_state->smbldap_state->ldap_struct, entry,
+               get_userattr_key2string(ldap_state->schema_ver, LDAP_ATTR_LOGON_HOURS), temp)) {
+                       /* leave as default */
+       } else {
+               pdb_gethexhours(temp, hours);
+               memset((char *)temp, '\0', strlen(temp) +1);
+               pdb_set_hours(sampass, hours, PDB_SET);
+               ZERO_STRUCT(hours);
+       }
 
        /* check the timestamp of the cache vs ldap entry */
        if (!(ldap_entry_time = ldapsam_get_entry_timestamp(ldap_state, 
@@ -1065,7 +1073,18 @@ static BOOL init_ldap_from_sam (struct ldapsam_privates *ldap_state,
                }
        }
 
-       /* FIXME: Hours stuff goes in LDAP  */
+       if (need_update(sampass, PDB_HOURS)) {
+               const char *hours = pdb_get_hours(sampass);
+               if (hours) {
+                       pdb_sethexhours(temp, hours);
+                       smbldap_make_mod(ldap_state->smbldap_state->ldap_struct,
+                               existing,
+                               mods,
+                               get_userattr_key2string(ldap_state->schema_ver,
+                                               LDAP_ATTR_LOGON_HOURS),
+                               temp);
+               }
+       }
 
        if (need_update(sampass, PDB_ACCTCTRL))
                smbldap_make_mod(ldap_state->smbldap_state->ldap_struct, existing, mods,