#include "nssov.h"
#include <ac/ctype.h>
static struct berval netgroup_filter = BER_BVC("(objectClass=nisNetgroup)");
static struct berval netgroup_keys[] = {
BER_BVC("cn"),
BER_BVC("nisNetgroupTriple"),
BER_BVC("memberNisNetgroup"),
BER_BVNULL
};
NSSOV_INIT(netgroup)
NSSOV_CBPRIV(netgroup,
char buf[256];
struct berval name;);
static int write_string_stripspace_len(TFILE *fp,const char *str,int len)
{
int32_t tmpint32;
int i,j;
DEBUG_PRINT("WRITE_STRING: var="__STRING(str)" string=\"%s\"",str);
if (str==NULL)
{
WRITE_INT32(fp,0);
}
else
{
for (i=0;(str[i]!='\0')&&(isspace(str[i]));i++)
;
for (j=len;(j>i)&&(isspace(str[j-1]));j--)
;
WRITE_INT32(fp,j-i);
if (j>i)
{
WRITE(fp,str+i,j-i);
}
}
return 0;
}
#define WRITE_STRING_STRIPSPACE_LEN(fp,str,len) \
if (write_string_stripspace_len(fp,str,len)) \
return -1;
#define WRITE_STRING_STRIPSPACE(fp,str) \
WRITE_STRING_STRIPSPACE_LEN(fp,str,strlen(str))
static int write_netgroup_triple(TFILE *fp,const char *triple)
{
int32_t tmpint32;
int i;
int hostb,hoste,userb,usere,domainb,domaine;
for (i=0;(triple[i]!='\0')&&(isspace(triple[i]));i++)
;
if (triple[i]!='(')
{
Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): entry does not begin with '(' (entry skipped)\n",0,0,0);
return 0;
}
i++;
hostb=i;
for (;(triple[i]!='\0')&&(triple[i]!=',');i++)
;
if (triple[i]!=',')
{
Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ',' (entry skipped)\n",0,0,0);
return 0;
}
hoste=i;
i++;
userb=i;
for (;(triple[i]!='\0')&&(triple[i]!=',');i++)
;
if (triple[i]!=',')
{
Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ',' (entry skipped)\n",0,0,0);
return 0;
}
usere=i;
i++;
domainb=i;
for (;(triple[i]!='\0')&&(triple[i]!=')');i++)
;
if (triple[i]!=')')
{
Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ')' (entry skipped)\n",0,0,0);
return 0;
}
domaine=i;
i++;
for (;(triple[i]!='\0')&&(isspace(triple[i]));i++)
;
if (triple[i]!='\0')
{
Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): string contains trailing data (entry skipped)\n",0,0,0);
return 0;
}
WRITE_INT32(fp,NSLCD_RESULT_BEGIN);
WRITE_INT32(fp,NSLCD_NETGROUP_TYPE_TRIPLE);
WRITE_STRING_STRIPSPACE_LEN(fp,triple+hostb,hoste-hostb)
WRITE_STRING_STRIPSPACE_LEN(fp,triple+userb,usere-userb)
WRITE_STRING_STRIPSPACE_LEN(fp,triple+domainb,domaine-domainb)
return 0;
}
static int write_netgroup(nssov_netgroup_cbp *cbp,Entry *entry)
{
int32_t tmpint32;
int i;
Attribute *a;
a = attr_find(entry->e_attrs,cbp->mi->mi_attrs[1].an_desc);
if ( a ) {
for (i=0;i<a->a_numvals;i++)
{
if (write_netgroup_triple(cbp->fp, a->a_vals[i].bv_val))
return -1;
}
}
a = attr_find(entry->e_attrs,cbp->mi->mi_attrs[2].an_desc);
if ( a ) {
for (i=0;i<a->a_numvals;i++)
{
WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
WRITE_INT32(cbp->fp,NSLCD_NETGROUP_TYPE_NETGROUP);
if (write_string_stripspace_len(cbp->fp,a->a_vals[i].bv_val,a->a_vals[i].bv_len))
return -1;
}
}
return 0;
}
NSSOV_CB(netgroup)
NSSOV_HANDLE(
netgroup,byname,
char fbuf[1024];
struct berval filter = {sizeof(fbuf)};
filter.bv_val = fbuf;
READ_STRING(fp,cbp.buf);,
cbp.name.bv_len = tmpint32;
cbp.name.bv_val = cbp.buf;
Debug(LDAP_DEBUG_TRACE,"nssov_netgroup_byname(%s)\n",cbp.name.bv_val,0,0);,
NSLCD_ACTION_NETGROUP_BYNAME,
nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
)