2 alias.c - alias entry lookup routines
3 Parts of this file were part of the nss_ldap library (as ldap-alias.c)
4 which has been forked into the nss-ldapd library.
6 Copyright (C) 1997-2005 Luke Howard
7 Copyright (C) 2006 West Consulting
8 Copyright (C) 2006, 2007 Arthur de Jong
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
38 /* Vendor-specific attributes and object classes.
40 * ( 1.3.6.1.4.1.42.2.27.1.2.5 NAME 'nisMailAlias' SUP top STRUCTURAL
41 * DESC 'NIS mail alias'
43 * MAY rfc822MailMember )
46 /* the search base for searches */
47 const char *alias_base = NULL;
49 /* the search scope for searches */
50 int alias_scope = LDAP_SCOPE_DEFAULT;
52 /* the basic search filter for searches */
53 const char *alias_filter = "(objectClass=nisMailAlias)";
55 /* the attributes to request with searches */
56 const char *attmap_alias_cn = "cn";
57 const char *attmap_alias_rfc822MailMember = "rfc822MailMember";
59 /* the attribute list to request with searches */
60 static const char *alias_attrs[3];
62 /* create a search filter for searching an alias by name,
63 return -1 on errors */
64 static int mkfilter_alias_byname(const char *name,
65 char *buffer,size_t buflen)
68 /* escape attribute */
69 if (myldap_escape(name,buf2,sizeof(buf2)))
72 return mysnprintf(buffer,buflen,
75 attmap_alias_cn,buf2);
78 static void alias_init(void)
82 alias_base=nslcd_cfg->ldc_base;
84 if (alias_scope==LDAP_SCOPE_DEFAULT)
85 alias_scope=nslcd_cfg->ldc_scope;
86 /* set up attribute list */
87 alias_attrs[0]=attmap_alias_cn;
88 alias_attrs[1]=attmap_alias_rfc822MailMember;
92 static int write_alias(TFILE *fp,MYLDAP_ENTRY *entry,const char *reqalias)
94 int32_t tmpint32,tmp2int32,tmp3int32;
95 const char *tmparr[2];
96 const char **names,**members;
98 /* get the name of the alias */
107 names=myldap_get_values(entry,attmap_alias_cn);
108 if ((names==NULL)||(names[0]==NULL))
110 log_log(LOG_WARNING,"alias entry %s does not contain %s value",
111 myldap_get_dn(entry),attmap_alias_cn);
115 /* get the members of the alias */
116 members=myldap_get_values(entry,attmap_alias_rfc822MailMember);
117 /* for each name, write an entry */
118 for (i=0;names[i]!=NULL;i++)
120 WRITE_INT32(fp,NSLCD_RESULT_SUCCESS);
121 WRITE_STRING(fp,names[i]);
122 WRITE_STRINGLIST(fp,members);
131 READ_STRING_BUF2(fp,name,sizeof(name));,
132 log_log(LOG_DEBUG,"nslcd_alias_byname(%s)",name);,
133 NSLCD_ACTION_ALIAS_BYNAME,
134 mkfilter_alias_byname(name,filter,sizeof(filter)),
135 write_alias(fp,entry,name)
141 /* no parameters to read */,
142 log_log(LOG_DEBUG,"nslcd_alias_all()");,
143 NSLCD_ACTION_ALIAS_ALL,
144 (filter=alias_filter,0),
145 write_alias(fp,entry,NULL)