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