xref: /netbsd-src/external/bsd/openldap/dist/contrib/slapd-modules/nssov/alias.c (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /* alias.c - mail alias lookup routines */
2 /* $OpenLDAP: pkg/ldap/contrib/slapd-modules/nssov/alias.c,v 1.1.2.1 2008/07/08 18:53:57 quanah Exp $ */
3 /*
4  * Copyright 2008 by Howard Chu, Symas Corp.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted only as authorized by the OpenLDAP
9  * Public License.
10  *
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>.
14  */
15 /*
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.
19  */
20 
21 #include "nssov.h"
22 
23 /* Vendor-specific attributes and object classes.
24  * (Mainly from Sun.)
25  * ( 1.3.6.1.4.1.42.2.27.1.2.5 NAME 'nisMailAlias' SUP top STRUCTURAL
26  *   DESC 'NIS mail alias'
27  *   MUST cn
28  *   MAY rfc822MailMember )
29  */
30 
31 /* the basic search filter for searches */
32 static struct berval alias_filter = BER_BVC("(objectClass=nisMailAlias)");
33 
34 /* the attributes to request with searches */
35 static struct berval alias_keys[] = {
36 	BER_BVC("cn"),
37 	BER_BVC("rfc822MailMember"),
38 	BER_BVNULL
39 };
40 
41 NSSOV_INIT(alias)
42 
43 NSSOV_CBPRIV(alias,
44 	struct berval name;
45 	char buf[256];);
46 
47 static int write_alias(nssov_alias_cbp *cbp,Entry *entry)
48 {
49 	int32_t tmpint32,tmp2int32,tmp3int32;
50 	struct berval tmparr[2], empty;
51 	struct berval *names, *members;
52 	Attribute *a;
53 	int i;
54 
55 	/* get the name of the alias */
56 	if (BER_BVISNULL(&cbp->name))
57 	{
58 		a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[0].an_desc);
59 		if ( !a )
60 		{
61 			Debug(LDAP_DEBUG_ANY,"alias entry %s does not contain %s value",
62 				entry->e_name.bv_val,cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val,0 );
63 			return 0;
64 		}
65 		names = a->a_vals;
66 	}
67 	else
68 	{
69 		names=tmparr;
70 		names[0]=cbp->name;
71 		BER_BVZERO(&names[1]);
72 	}
73 	/* get the members of the alias */
74  	a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[1].an_desc);
75 	if ( !a ) {
76 		BER_BVZERO( &empty );
77 		members = &empty;
78 	} else {
79 		members = a->a_vals;
80 	}
81 	/* for each name, write an entry */
82 	for (i=0;!BER_BVISNULL(&names[i]);i++)
83 	{
84 		WRITE_INT32(cbp->fp,NSLCD_RESULT_SUCCESS);
85 		WRITE_BERVAL(cbp->fp,&names[i]);
86 		WRITE_BVARRAY(cbp->fp,members);
87 	}
88 	return 0;
89 }
90 
91 NSSOV_CB(alias)
92 
93 NSSOV_HANDLE(
94 	alias,byname,
95 	char fbuf[1024];
96 	struct berval filter = {sizeof(fbuf)};
97 	filter.bv_val = fbuf;
98 	READ_STRING_BUF2(fp,cbp.buf,sizeof(cbp.buf));
99 	cbp.name.bv_len = tmpint32;
100 	cbp.name.bv_val = cbp.buf;,
101 	Debug(LDAP_DEBUG_TRACE,"nssov_alias_byname(%s)",cbp.name.bv_val,0,0);,
102 	NSLCD_ACTION_ALIAS_BYNAME,
103 	nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
104 )
105 
106 NSSOV_HANDLE(
107 	alias,all,
108 	struct berval filter;
109 	/* no parameters to read */
110 	BER_BVZERO(&cbp.name);,
111 	Debug(LDAP_DEBUG,"nssov_alias_all()",0,0,0);,
112 	NSLCD_ACTION_ALIAS_ALL,
113 	(filter=cbp.mi->mi_filter,0)
114 )
115