1 /* netgroup.c - netgroup lookup routines */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2008-2014 The OpenLDAP Foundation.
6 * Portions Copyright 2008 by Howard Chu, Symas Corp.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This code references portions of the nss-ldapd package
19 * written by Arthur de Jong. The nss-ldapd code was forked
20 * from the nss-ldap library written by Luke Howard.
26 /* ( nisSchema.2.8 NAME 'nisNetgroup' SUP top STRUCTURAL
27 * DESC 'Abstraction of a netgroup. May refer to other netgroups'
29 * MAY ( nisNetgroupTriple $ memberNisNetgroup $ description ) )
32 /* the basic search filter for searches */
33 static struct berval netgroup_filter = BER_BVC("(objectClass=nisNetgroup)");
35 /* the attributes to request with searches */
36 static struct berval netgroup_keys[] = {
38 BER_BVC("nisNetgroupTriple"),
39 BER_BVC("memberNisNetgroup"),
45 NSSOV_CBPRIV(netgroup,
49 static int write_string_stripspace_len(TFILE *fp,const char *str,int len)
53 DEBUG_PRINT("WRITE_STRING: var="__STRING(str)" string=\"%s\"",str);
60 /* skip leading spaces */
61 for (i=0;(str[i]!='\0')&&(isspace(str[i]));i++)
62 /* nothing else to do */ ;
63 /* skip trailing spaces */
64 for (j=len;(j>i)&&(isspace(str[j-1]));j--)
65 /* nothing else to do */ ;
66 /* write length of string */
68 /* write string itself */
78 #define WRITE_STRING_STRIPSPACE_LEN(fp,str,len) \
79 if (write_string_stripspace_len(fp,str,len)) \
82 #define WRITE_STRING_STRIPSPACE(fp,str) \
83 WRITE_STRING_STRIPSPACE_LEN(fp,str,strlen(str))
85 static int write_netgroup_triple(TFILE *fp,const char *triple)
89 int hostb,hoste,userb,usere,domainb,domaine;
90 /* skip leading spaces */
91 for (i=0;(triple[i]!='\0')&&(isspace(triple[i]));i++)
92 /* nothing else to do */ ;
93 /* we should have a bracket now */
96 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): entry does not begin with '(' (entry skipped)\n",0,0,0);
101 /* find comma (end of host string) */
102 for (;(triple[i]!='\0')&&(triple[i]!=',');i++)
103 /* nothing else to do */ ;
106 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ',' (entry skipped)\n",0,0,0);
112 /* find comma (end of user string) */
113 for (;(triple[i]!='\0')&&(triple[i]!=',');i++)
114 /* nothing else to do */ ;
117 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ',' (entry skipped)\n",0,0,0);
123 /* find closing bracket (end of domain string) */
124 for (;(triple[i]!='\0')&&(triple[i]!=')');i++)
125 /* nothing else to do */ ;
128 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ')' (entry skipped)\n",0,0,0);
133 /* skip trailing spaces */
134 for (;(triple[i]!='\0')&&(isspace(triple[i]));i++)
135 /* nothing else to do */ ;
136 /* if anything is left in the string we have a problem */
139 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): string contains trailing data (entry skipped)\n",0,0,0);
143 WRITE_INT32(fp,NSLCD_RESULT_BEGIN);
144 WRITE_INT32(fp,NSLCD_NETGROUP_TYPE_TRIPLE);
145 WRITE_STRING_STRIPSPACE_LEN(fp,triple+hostb,hoste-hostb)
146 WRITE_STRING_STRIPSPACE_LEN(fp,triple+userb,usere-userb)
147 WRITE_STRING_STRIPSPACE_LEN(fp,triple+domainb,domaine-domainb)
152 static int write_netgroup(nssov_netgroup_cbp *cbp,Entry *entry)
158 /* get the netgroup triples and member */
159 a = attr_find(entry->e_attrs,cbp->mi->mi_attrs[1].an_desc);
161 /* write the netgroup triples */
162 for (i=0;i<a->a_numvals;i++)
164 if (write_netgroup_triple(cbp->fp, a->a_vals[i].bv_val))
168 a = attr_find(entry->e_attrs,cbp->mi->mi_attrs[2].an_desc);
170 /* write netgroup members */
171 for (i=0;i<a->a_numvals;i++)
173 /* write the result code */
174 WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
175 /* write triple indicator */
176 WRITE_INT32(cbp->fp,NSLCD_NETGROUP_TYPE_NETGROUP);
177 /* write netgroup name */
178 if (write_string_stripspace_len(cbp->fp,a->a_vals[i].bv_val,a->a_vals[i].bv_len))
191 struct berval filter = {sizeof(fbuf)};
192 filter.bv_val = fbuf;
193 READ_STRING(fp,cbp.buf);,
194 cbp.name.bv_len = tmpint32;
195 cbp.name.bv_val = cbp.buf;
196 Debug(LDAP_DEBUG_TRACE,"nssov_netgroup_byname(%s)\n",cbp.name.bv_val,0,0);,
197 NSLCD_ACTION_NETGROUP_BYNAME,
198 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)