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