Question on LDAP samba.schema
Stefan (metze) Metzmacher
metze at metzemix.de
Fri Feb 8 03:07:02 GMT 2002
At 20:58 06.02.2002 +1100, Andrew Bartlett wrote:
>"Stefan (metze) Metzmacher" wrote:
> >
> > I have a question on the LDAP samba.schema:
> >
> > - why is the userWorkstation attribute single valued, I think there
> should be more then one Workstaion a user can login to!
>
>The attribute is a list of workstations, seperated by ','. This is the
>format that NT uses and how samba stores it internally. I'm sure the
>'proper' way to store this is as a mulit-valued attribute - that would
>be a matter of changing a few things inside pdb_ldap.c I presume.
I prefer to add 2 new functions:
get_attribute_values - create a ',' seperated list of all attribute values
make_a_mod_from_list - store a ',' seperated list as multi-valued attribute.
metze
______________________________________________________________
/*******************************************************************
search an attribute and return a ',' seperated list of values found.
******************************************************************/
static BOOL get_attribute_values (LDAP * ldap_struct, LDAPMessage * entry,
char *attribute, char *value)
{
char **values,*temp;
int i;
if ((values = ldap_get_values (ldap_struct, entry, attribute)) ==
NULL) {
value = NULL;
DEBUG (2, ("get_attribute_values: [%s] = [<does not
exist>]\n", attribute));
return False;
}
temp = strdup(values[0]);
for(i=1;i<ldap_count_values(values);i++)
{
temp = (char *) Realloc (temp, strlen(temp)+strlen(values[i]) );
sprintf(temp,"%s,%s",temp,values[i]);
DEBUG (4, ("get_attribute_values: [%s] = [%s]\n", attribute,
values[i]));
}
pstrcpy(value, temp);
ldap_value_free(values);
DEBUG (2, ("get_attribute_values: [%s] = [%s]\n", attribute, value));
return True;
}
/************************************************************************
Routine to manage the LDAPMod structure array
manage memory used by the array, by each struct, and values
value could be a ',' seperated list
************************************************************************/
static void make_a_mod_from_list (LDAPMod *** modlist, int modop, const
char *attribute, const char *value)
{
LDAPMod **mods;
int i;
int j,values_count=0;
char *temp,*val;
mods = *modlist;
if (attribute == NULL || *attribute == '\0')
return;
if (value == NULL || *value == '\0')
return;
if (mods == NULL)
{
mods = (LDAPMod **) malloc(sizeof(LDAPMod *));
if (mods == NULL)
{
DEBUG(0, ("make_a_mod_from_list: out of memory!\n"));
return;
}
mods[0] = NULL;
}
for (i = 0; mods[i] != NULL; ++i) {
if (mods[i]->mod_op == modop &&
!strcasecmp(mods[i]->mod_type, attribute))
break;
}
if (mods[i] == NULL)
{
mods = (LDAPMod **) Realloc (mods, (i + 2) * sizeof (LDAPMod
*));
if (mods == NULL)
{
DEBUG(0, ("make_a_mod_from_list: out of memory!\n"));
return;
}
mods[i] = (LDAPMod *) malloc(sizeof(LDAPMod));
if (mods[i] == NULL)
{
DEBUG(0, ("make_a_mod_from_list: out of memory!\n"));
return;
}
mods[i]->mod_op = modop;
mods[i]->mod_values = NULL;
mods[i]->mod_type = strdup(attribute);
mods[i + 1] = NULL;
}
if (value != NULL)
{
j = 0;
if (mods[i]->mod_values != NULL) {
for (; mods[i]->mod_values[j] != NULL; j++);
}
do
{
value_count++;
p = strchr(value,',');
}while (p!=NULL)
value_count = value_count + j;
mods[i]->mod_values = (char **)Realloc(mods[i]->mod_values,
( values_count +1 ) * sizeof
(char *));
if (mods[i]->mod_values == NULL) {
DEBUG (0, ("make_a_mod_from_list: Memory allocation
failure!\n"));
return;
}
temp = strdup(value);
for(;j<=value_count;j++)
{
val = strsep(temp,',');
if(val)
mods[i]->mod_values[j] = strdup(val);
}
mods[i]->mod_values[j] = strdup(temp);
mods[i]->mod_values[j + 1] = NULL;
}
*modlist = mods;
}
____________________________________________________________
metze
-----------------------------------------------------------------------------
Stefan "metze" Metzmacher <metze at metzemix.de>
More information about the samba-technical
mailing list