/tnsutil

Utilities for TNS entries, to and from LDAP. based on the idea from Mark J Bobak tns2ldif.c (see http://markjbobak.wordpress.com/2013/10/11/openldap-care-and-feeding-of-your-ldap-server for more information)

Primary LanguageC++BSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

TNS2LDIF is a set of command line utilities for managing TNS entry data locally
and through LDAP
--------------------------------------------------------------------------------



Background
--------------------------------------------------------------------------------

These utilities are based on the idea from Mark J Bobak tns2ldif.c (see below)
(see http://markjbobak.wordpress.com/2013/10/11/openldap-care-and-feeding-of-your-ldap-server
for more information), but is a complete rewrite (not using anything from Bobak,
except the idea behind the need).



Utilities
--------------------------------------------------------------------------------

tns2ldif - convert a tnsnames.ora file to an LDIF file that can be loaded
           into an LDAP store

ldif2tns - convert an LDIF file (output from ldapsearch -L) into a tnsnames.ora
           file

tns2ldap - load a tnsnames.ora file into an LDAP store which is compliant with
           Oracle's EUS repository requirements

ldap2tns - create a tnsnames.ora from a Oracle EUS compliant repository, which
           can be used locally



Copyright
--------------------------------------------------------------------------------

Copyright (c) 2004-2014, Metasystems Technologies Inc. (MTI)
All rights reserved.



License
--------------------------------------------------------------------------------

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of tns2ldif nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Original tns2ldif.c source code from
https://docs.google.com/a/mtihq.com/file/d/0B2t_l1d1imCbM3p6WDNNWTB2TWc/edit
--------------------------------------------------------------------------------
    /*  tns2ldif.c -- filter to convert tnsnames.ora entries to LDIF for      */
    /*                import to OpenLDAP                                      */
    /*  Written by Mark J. Bobak, mark@bobak.net, mark.bobak@proquest.com     */
    /*  Copyright 2013, ProQuest Company                                      */
    /*  This program is free software: you can redistribute it and/or modify  */
    /*  it under the terms of the GNU General Public License as published by  */
    /*  the Free Software Foundation, either version 3 of the License, or     */
    /*  (at your option) any later version.                                   */
    /*                                                                        */
    /*  This program is distributed in the hope that it will be useful,       */
    /*  but WITHOUT ANY WARRANTY; without even the implied warranty of        */
    /*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
    /*  GNU General Public License for more details.                          */
    /*                                                                        */
    /*  You should have received a copy of the GNU General Public License     */
    /*  along with this program.  If not, see <http://www.gnu.org/licenses/>. */
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #define MAX_LINE_LENGTH 1024
    #define MAX_TNS_LENGTH 256
    #define MAX_ALIASES 32
    #define MAX_DOMAIN_LENGTH 255
    #define DEFAULT_DOMAIN "dc=proquest,dc=com"
    int main(int argc, char *argv[])
    {
        int ret;
        int x;
        int i=0;
        int delim_pos = 0;
        char    tns_entry[MAX_LINE_LENGTH+1];
        char    *tns_line;
        char    tns_name[MAX_TNS_LENGTH+1];
        char    *conn_str;
        int num_aliases;
        char    *alias[MAX_ALIASES];
        char    domain[MAX_DOMAIN_LENGTH+1];
    
        if(argc == 3)
        {
            if(!strcmp(argv[1], "-d"))
                strcpy(domain,argv[2]);
            else
                fprintf(stderr,"%s:  invalid option\n",argv[0]);
        }
        else
            strcpy(domain,DEFAULT_DOMAIN);
    
        while(fgets(tns_entry,MAX_LINE_LENGTH,stdin))
        {
            tns_line = tns_entry;
            while(isblank(tns_line[0]))
                tns_line++;
            if(tns_line[0]!='#')
            {
                for(x=0;x<=strlen(tns_line);x++)
                    if(tns_line[x]== '=')
                    {   
                        delim_pos=x;
                        break;
                    }
                strncpy(tns_name,tns_line,delim_pos);
                tns_name[delim_pos] = '\0';
                for(x=strlen(tns_name);x>0;x--)
                    if(tns_name[x] == ' ')
                        tns_name[x] = '\0';
                num_aliases = 0;
                for(x=strlen(tns_name);x>0;x--)
                    if(tns_name[x] == ',')
                    {
                        alias[num_aliases] = tns_name+x+1;
                        tns_name[x] = '\0';
                        num_aliases++;
                    }
                conn_str = strstr(tns_line, "=");   
                conn_str++;
                conn_str[strlen(conn_str)-1] = '\0';
                fprintf(stdout,"dn: cn=%s,cn=OracleContext,%s\nobjectclass: top\nobjectclass: orclNetService\ncn: %s\norclNetDescString: %s\n\n",tns_name,domain,tns_name,conn_str);
                for(x=0;x<num_aliases;x++)
                    fprintf(stdout,"dn: cn=%s,cn=OracleContext,%s\nobjectclass: orclNetServiceAlias\nobjectclass: top\nobjectclass: alias\ncn: %s\naliasedobjectname: cn=%s,cn=OracleContext,%s\n\n",alias[x],domain,alias[x],tns_name,domain);
            }
            else
                fprintf(stdout,"%s",tns_line);
        }
        return 0;
    }