1 /* netgroup.c - netgroup lookup routines */
4 * Copyright 2008 by Howard Chu, Symas Corp.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This code references portions of the nss-ldapd package
17 * written by Arthur de Jong. The nss-ldapd code was forked
18 * from the nss-ldap library written by Luke Howard.
24 /* ( nisSchema.2.8 NAME 'nisNetgroup' SUP top STRUCTURAL
25 * DESC 'Abstraction of a netgroup. May refer to other netgroups'
27 * MAY ( nisNetgroupTriple $ memberNisNetgroup $ description ) )
30 /* the basic search filter for searches */
31 static struct berval netgroup_filter = BER_BVC("(objectClass=nisNetgroup)");
33 /* the attributes to request with searches */
34 static struct berval netgroup_keys[] = {
36 BER_BVC("nisNetgroupTriple"),
37 BER_BVC("memberNisNetgroup"),
43 NSSOV_CBPRIV(netgroup,
47 static int write_string_stripspace_len(TFILE *fp,const char *str,int len)
51 DEBUG_PRINT("WRITE_STRING: var="__STRING(str)" string=\"%s\"",str);
58 /* skip leading spaces */
59 for (i=0;(str[i]!='\0')&&(isspace(str[i]));i++)
60 /* nothing else to do */ ;
61 /* skip trailing spaces */
62 for (j=len;(j>i)&&(isspace(str[j-1]));j--)
63 /* nothing else to do */ ;
64 /* write length of string */
66 /* write string itself */
76 #define WRITE_STRING_STRIPSPACE_LEN(fp,str,len) \
77 if (write_string_stripspace_len(fp,str,len)) \
80 #define WRITE_STRING_STRIPSPACE(fp,str) \
81 WRITE_STRING_STRIPSPACE_LEN(fp,str,strlen(str))
83 static int write_netgroup_triple(TFILE *fp,const char *triple)
87 int hostb,hoste,userb,usere,domainb,domaine;
88 /* skip leading spaces */
89 for (i=0;(triple[i]!='\0')&&(isspace(triple[i]));i++)
90 /* nothing else to do */ ;
91 /* we should have a bracket now */
94 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): entry does not begin with '(' (entry skipped)",0,0,0);
99 /* find comma (end of host string) */
100 for (;(triple[i]!='\0')&&(triple[i]!=',');i++)
101 /* nothing else to do */ ;
104 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ',' (entry skipped)",0,0,0);
110 /* find comma (end of user string) */
111 for (;(triple[i]!='\0')&&(triple[i]!=',');i++)
112 /* nothing else to do */ ;
115 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ',' (entry skipped)",0,0,0);
121 /* find closing bracket (end of domain string) */
122 for (;(triple[i]!='\0')&&(triple[i]!=')');i++)
123 /* nothing else to do */ ;
126 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): missing ')' (entry skipped)",0,0,0);
131 /* skip trailing spaces */
132 for (;(triple[i]!='\0')&&(isspace(triple[i]));i++)
133 /* nothing else to do */ ;
134 /* if anything is left in the string we have a problem */
137 Debug(LDAP_DEBUG_ANY,"write_netgroup_triple(): string contains trailing data (entry skipped)",0,0,0);
141 WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
142 WRITE_INT32(fp,NETGROUP_TYPE_TRIPLE);
143 WRITE_STRING_STRIPSPACE_LEN(fp,triple+hostb,hoste-hostb)
144 WRITE_STRING_STRIPSPACE_LEN(fp,triple+userb,usere-userb)
145 WRITE_STRING_STRIPSPACE_LEN(fp,triple+domainb,domaine-domainb)
150 static int write_netgroup(nssov_netgroup_cbp *cbp,Entry *entry)
156 /* get the netgroup triples and member */
157 a = attr_find(entry->e_attrs,cbp->mi->mi_attrs[1].an_desc);
159 /* write the netgroup triples */
160 for (i=0;i<a->a_numvals;i++)
162 if (write_netgroup_triple(cbp->fp, a->a_vals[i].bv_val))
166 a = attr_find(entry->e_attrs,cbp->mi->mi_attrs[2].an_desc);
168 /* write netgroup members */
169 for (i=0;i<a->a_numvals;i++)
171 /* write the result code */
172 WRITE_INT32(cbp->fp,NSLCD_RESULT_SUCCESS);
173 /* write triple indicator */
174 WRITE_INT32(cbp->fp,NETGROUP_TYPE_NETGROUP);
175 /* write netgroup name */
176 if (write_string_stripspace_len(cbp->fp,a->a_vals[i].bv_val,a->a_vals[i].bv_len))
189 struct berval filter = {sizeof(fbuf)};
190 filter.bv_val = fbuf;
191 READ_STRING_BUF2(fp,cbp.buf,sizeof(cbp.buf));,
192 cbp.name.bv_len = tmpint32;
193 cbp.name.bv_val = cbp.buf;
194 Debug(LDAP_DEBUG_TRACE,"nssov_netgroup_byname(%s)",cbp.name.bv_val,0,0);,
195 NSLCD_ACTION_NETGROUP_BYNAME,
196 nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)