Back to index

openldap  2.4.31
alias.c
Go to the documentation of this file.
00001 /* alias.c - mail alias lookup routines */
00002 /* $OpenLDAP$ */
00003 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 
00004  *
00005  * Copyright 2008-2012 The OpenLDAP Foundation.
00006  * Portions Copyright 2008 by Howard Chu, Symas Corp.
00007  * All rights reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted only as authorized by the OpenLDAP
00011  * Public License.
00012  *
00013  * A copy of this license is available in the file LICENSE in the
00014  * top-level directory of the distribution or, alternatively, at
00015  * <http://www.OpenLDAP.org/license.html>.
00016  */
00017 /* ACKNOWLEDGEMENTS:
00018  * This code references portions of the nss-ldapd package
00019  * written by Arthur de Jong. The nss-ldapd code was forked
00020  * from the nss-ldap library written by Luke Howard.
00021  */
00022 
00023 #include "nssov.h"
00024 
00025 /* Vendor-specific attributes and object classes.
00026  * (Mainly from Sun.)
00027  * ( 1.3.6.1.4.1.42.2.27.1.2.5 NAME 'nisMailAlias' SUP top STRUCTURAL
00028  *   DESC 'NIS mail alias'
00029  *   MUST cn
00030  *   MAY rfc822MailMember )
00031  */
00032 
00033 /* the basic search filter for searches */
00034 static struct berval alias_filter = BER_BVC("(objectClass=nisMailAlias)");
00035 
00036 /* the attributes to request with searches */
00037 static struct berval alias_keys[] = {
00038        BER_BVC("cn"),
00039        BER_BVC("rfc822MailMember"),
00040        BER_BVNULL
00041 };
00042 
00043 NSSOV_INIT(alias)
00044 
00045 NSSOV_CBPRIV(alias,
00046        struct berval name;
00047        char buf[256];);
00048 
00049 static int write_alias(nssov_alias_cbp *cbp,Entry *entry)
00050 {
00051        int32_t tmpint32,tmp2int32,tmp3int32;
00052        struct berval tmparr[2], empty;
00053        struct berval *names, *members;
00054        Attribute *a;
00055        int i;
00056 
00057        /* get the name of the alias */
00058        if (BER_BVISNULL(&cbp->name))
00059        {
00060               a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[0].an_desc);
00061               if ( !a )
00062               {
00063                      Debug(LDAP_DEBUG_ANY,"alias entry %s does not contain %s value\n",
00064                             entry->e_name.bv_val,cbp->mi->mi_attrs[0].an_desc->ad_cname.bv_val,0 );
00065                      return 0;
00066               }
00067               names = a->a_vals;
00068        }
00069        else
00070        {
00071               names=tmparr;
00072               names[0]=cbp->name;
00073               BER_BVZERO(&names[1]);
00074        }
00075        /* get the members of the alias */
00076        a = attr_find(entry->e_attrs, cbp->mi->mi_attrs[1].an_desc);
00077        if ( !a ) {
00078               BER_BVZERO( &empty );
00079               members = &empty;
00080        } else {
00081               members = a->a_vals;
00082        }
00083        /* for each name, write an entry */
00084        for (i=0;!BER_BVISNULL(&names[i]);i++)
00085        {
00086               WRITE_INT32(cbp->fp,NSLCD_RESULT_BEGIN);
00087               WRITE_BERVAL(cbp->fp,&names[i]);
00088               WRITE_BVARRAY(cbp->fp,members);
00089        }
00090        return 0;
00091 }
00092 
00093 NSSOV_CB(alias)
00094 
00095 NSSOV_HANDLE(
00096        alias,byname,
00097        char fbuf[1024];
00098        struct berval filter = {sizeof(fbuf)};
00099        filter.bv_val = fbuf;
00100        READ_STRING(fp,cbp.buf);
00101        cbp.name.bv_len = tmpint32;
00102        cbp.name.bv_val = cbp.buf;,
00103        Debug(LDAP_DEBUG_TRACE,"nssov_alias_byname(%s)\n",cbp.name.bv_val,0,0);,
00104        NSLCD_ACTION_ALIAS_BYNAME,
00105        nssov_filter_byname(cbp.mi,0,&cbp.name,&filter)
00106 )
00107 
00108 NSSOV_HANDLE(
00109        alias,all,
00110        struct berval filter;
00111        /* no parameters to read */
00112        BER_BVZERO(&cbp.name);,
00113        Debug(LDAP_DEBUG,"nssov_alias_all()\n",0,0,0);,
00114        NSLCD_ACTION_ALIAS_ALL,
00115        (filter=cbp.mi->mi_filter,0)
00116 )