Saturday, October 11, 2014

ODBC - [08001][unixODBC]Could not connect to the server; Could not connect to remote socket immedaitely [ISQL]ERROR: Could not SQLConnect

If you encounter the following error when you test odbc connection with isql

[08001][unixODBC]Could not connect to the server;
Could not connect to remote socket immedaitely
[ISQL]ERROR: Could not SQLConnect

You may have an error in your odbc.ini file. To be specific, you could be using a wrong "key" name for the server or port in your odbc.ini.

Some background. odbc.ini define DSN information in a key-value pair format and the key is vendor specific. Below is an erratic odbc.ini file entry

 [MSSQL2005]
Driver = ODBC Driver 11 for SQL Server
Description = Microsoft SQL ODBC Driver
Server = your_mssql_server_host
Port = 1433
Database =
[POSTGRESQL9] Driver = PostgreSQL9 Driver
Description = Postgresql ODBC Driver
Server = your_postgresql_server_host
Port = 5432
Database = your_database

With the above entry, MSSQL2005 DSN will work but POSTGRESQL9 DSN will fail.

unixODBC isql will return the following if you try to query POSTGRESQL9 DSN

[shell]$ isql -v POSTGRESQL9 your_user your_password
[08001][unixODBC]Could not connect to the server;
Could not connect to remote socket immedaitely
[ISQL]ERROR: Could not SQLConnect

The problem is.... PostgreSQL does not understand

Server = your_postgresql_server_host

The correct syntax is

Servername = your_postgresql_server_host

So, to fix the error, the correct odbc.ini entry is

 [MSQL2005]
Driver = ODBC Driver 11 for SQL Server
Description = Microsoft SQL ODBC Driver
Server = your_mssql_server_host
Port = 1433
Database =
[POSTGRESQL9] Driver = PostgreSQL9 Driver
Description = Postgresql ODBC Driver
Servername = your_postgresql_server_host
Port = 5432
Database = your_database

Sunday, September 21, 2014

ODBC - Testing odbc.ini in Linux

It is always best to test the ODBC configuration in the odbc.ini externally before doing real work with the database. Before putting the commands right away, below is a brief description about ODBC

ODBC, Open Database Connectivity, objective is to provide a standard API for accessing DBMS. It has 2 parts, the driver manager and the driver.

Driver Manager

It is a layer between the application and the actual driver. It actual functions include resolving DSN (Data Source Name) through the odbc.ini, loading and unloading the actual driver and pass application database calls to the driver.

The common ODBC Driver Manager are

Windows -  Microsoft Windows ODBC Driver Manager (odbc32.dll).

Unix - 2 commons Unix Driver Manager are

unixODBC Driver Manager for Unix (libodbc.so). See http://www.unixodbc.org, for more information.

iODBC Driver Manager for Unix (libiodbc.so). See http://www.iodbc.org, for more information.

Driver

It is vendor specific. When the Driver Manager passes the standard database call from the application, it translate to DBMS specific functions and commands to query the designated DBMS.

You could download the driver from the specific database vendor or you can use Easysoft or Datadirect which support large number of databases.

Testing ODBC Connectivity

After creating the DSN entry in your odbc.ini (either in /etc/odbc.ini which need root privilege or user .odbc.ini), you can use the following commands to test the odbc.ini file, assuming that you are using unixODBC driver

isql -v my_dsn myusername mypassword

Saturday, August 30, 2014

Unicode - Unicode vs UTF-8


Well, they can't be compare. Because unicode is a single character set that match a number for every character in the world written system. UTF-8, in another hand, is an encoding algorithm to store the unicode number on disk. There are many encoding algorithm beside UTF-8, ie ASCII, EBCDIC, etc.., but, there is only one Unicode system for all these encoding algorithm.

I really like the following posts that tell us about Unicode and UTF-8

http://rrn.dk/the-difference-between-utf-8-and-unicode

http://www.joelonsoftware.com/articles/Unicode.html

Some list of unicode code page

http://unicode-table.com/en/
http://en.wikipedia.org/wiki/List_of_Unicode_characters

Monday, July 28, 2014

LDAP - Configuring OpenLDAP

In previous post LDAP - Installing OpenLDAP, I listed down the steps to install OpenLDAP. In this post, I will list down the step to add LDAP entry for OpenLDAP

I will use LDIF and ldapadd to add LDAP entry into OpenLDAP database.

The LDAP Data Interchange Format (LDIF) is used to represent LDAP entries in a simple text format. And ldapadd is a utility which shipped with OpenLDAP to add LDAP entry

Adding an Organization Role

1. Create a LDIF file, ie, organization_roles.ldif
2. Add the following into organization_roles.ldif

# Organization for Example Corporation
dn: dc=example,dc=com
objectClass: dcObject
objectClass: organization
dc: example
o: Example Corporation
description: The Example Corporation

# Organizational Role for Directory Manager
dn: cn=Manager,dc=example,dc=com
objectClass: organizationalRole
cn: Manager
description: Directory Manager

The above create a organization role "Manager" in example.com LDAP directory.

3. Use ldapadd command to add the entry

Assuming that slapd.conf has the following entry

rootdn "cn=Manager,dc=example,dc=com"
rootpw secret

Then, you can use the following command to add a LDAP entry

ldapadd -f organization_roles.ldif -x -D "cn=Manager,dc=example,dc=com" -w secret

where
-f    # file name which contains the entry
-x   # Use simple authentication instead of SASL
-D   # Use the Distinguished Name binddn to bind to the LDAP directory. (Username, usually rootdn)
-w   # the password for simple authentication (password for rootpw)

4. On successful adding, you should see the following on the stdout

adding new entry "dc=example,dc=com"

adding new entry "cn=Manager,dc=example,dc=com"

Adding Multiple Users

1. Create a LDIF file, ie, users.ldif
2. Add the following into users.ldif

# Admin's Entry
dn: cn=Admin,dc=example,dc=com
cn: Administrator
objectClass: person
sn: Admin

# User1's Entry
dn: cn=User1,dc=example,dc=com
cn: User1
objectClass: person
sn: User1

# Eric Simpson's Entry
dn: cn=Eric Simpson,dc=example,dc=com
cn: Eric Simpson
cn: Eric Robert Simpson
objectClass: person
sn: Simpson

3. Use ldapadd command to add the entry 

ldapadd -f users.ldif -x -D "cn=Manager,dc=example,dc=com" -w secret

where
-f    # file name which contains the entry
-x   # Use simple authentication instead of SASL
-D   # Use the Distinguished Name binddn to bind to the LDAP directory. (Username, usually rootdn)
-w   # the password for simple authentication (password for rootpw)

4. Verify your entry with ldapsearch

ldapsearch -x -b 'dc=example,dc=com' '(objectclass=*)'

where

-x    # Use simple authentication instead of SASL
-b   # the starting point for the search
(objectclass=*)    # It is the filter to be applied for the search. In this case, any objectClass

Reference:

1. http://www.openldap.org/doc/admin24/dbtools.html
2. http://www.openldap.org/software/man.cgi?query=ldapadd&apropos=0&sektion=0&manpath=OpenLDAP+2.0-Release&format=html

Monday, June 30, 2014

LDAP - Installing OpenLDAP

Now, I need to play with LDAP. So, what is LDAP?

LDAP (Lightweight Directory Access Protocol) is an industry standard application protocol for accessing and maintaining distributed directory information server over an Network

Then, what is OpenLDAP? Well, it is an open-source implementation of LDAP.

For some reason, their default downloading mirroring sites are either timing me out or not valid. So, it will be easier to download OpenLDAP from their FTP over HTTP site (http://www.openldap.org/software/download/OpenLDAP/)

This notes will only be a high level guide on the steps (which I had tried) to install OpenLDAP. It will also highlight the problems and solutions during the installation

Prerequisites

OpenLDAP has the following prerequisites

1. Require Transport Layer Security services. I would suggest to use OpenSSL. By default, during the configuration, it will detect whether any TLS library is available. If you want to check whether your system support OpenSSL, you can try
openssl version
to check the currently install OpenSSL version

2. Require Cyrus SASL libraries to provide Simple Authentication and Security Layer services. To check if SASL is installed, you can use
ls -al /usr/lib/sasl2
to check whether the library exist

3. Install MIT Kerberos if you need Kerberos support from OpenSSL

4. Require Oracle Berkeley Database. BDB and HDB is the primary database backends for OpenLDAP

Now, during configuration, if you encounter the following error

checking for Berkeley DB major version in db.h... 4
checking for Berkeley DB minor version in db.h... 3
checking if Berkeley DB version supported by BDB/HDB backends... no
configure: error: BerkeleyDB version incompatible with BDB/HDB backends
This means that you need to upgrade your Berkeley Database because OpenLDAP support database version >= 4.4. You can do the following to upgrade your Berkeley Database

Installing the latest Berkeley Database

You can get the latest installer from http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html

For some reason, although Oracle said that the download is Berkeley DB X.X.XX.tar.gz, the downloaded file is call db-X.X.XX.gz (X.X.XX is the current version number). So assuming that X.X.XX is 6.0.30, all you need to do is to change db-6.0.30.gz to db-6.0.30.tar.gz and use tar -zxvf db-6.0.30.tar.gz to extract the installation file.

Now, you can follow these instruction to install latest Berkeley Database http://docs.oracle.com/cd/E17076_03/html/installation/build_unix.html

Export Paths before performing ./configure

You need to export the following (assuming that the downloaded version is 6.0.30)

export LD_LIBRARY_PATH="/usr/local/BerkeleyDB.6.0/lib"
export CPPFLAGS="-I/usr/local/BerkeleyDB.6.0/include"
export LDFLAGS="-L/usr/local/BerkeleyDB.6.0/lib"   

The above will tell ./configure to look for the latest Berkeley Database for library linkage

Installation

Below are the summary steps for installation

1. Get the installation package. The current version is openldap-2.4.39.tgz. and I will use this as an example
2. Unpack the installation
gunzip -c openldap-2.4.39.tgz | tar xvfB -
3. Navigate to the OpenLDAP installation directory
cd openldap-2.4.39
4. Run configure
./configure
5. Build the software
./make depend
./make
6. Test the build
./make test
7. Install OpenLDAP. Usually, it will installed in /usr/local
su root -c 'make install'
or
sudo make install
8. Edit the configuration file at /usr/local/etc/openldap/slapd.conf as root

Add the following (using example.com as example)
database bdb
suffix "dc=example,dc=com"
rootdn "cn=Manager,dc=example,dc=com"
rootpw secret
directory /usr/local/var/openldap-data
9. Start slapd (Standalone LDAP Daemon)
su root -c /usr/local/libexec/slapd
or
sudo /usr/local/libexec/slapd
Note: 

If you encounter the following error
/usr/local/libexec/slapd: error while loading shared libraries: libdb-6.0.so: cannot open shared object file: No such file or director
It means that you had not set up the shared library for Berkeley Database 6.0 correctly. You can use the following steps to fix it.

a. Create a file at /etc/ld.so.conf.d/db-6.conf 
b. Add /usr/local/BerkeleyDB.6.0/lib in the above file
c. Then, update library cache with sudo ldconfig
d. Run sudo /usr/local/libexec/slapd to test the setting

To check to see if the server is running and configured correctly, you can run the following command
ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts
It should display (using example.com as example)
dn:
namingContexts: dc=example,dc=com
The above should help you to set OpenLDAP up and running. If you want to know the details about the setup, see http://www.openldap.org/doc/admin24/quickstart.html for full installation details.

References:

1) http://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol

Monday, May 19, 2014

EMACS - Commands Compliation

This list is for my own easy reference for EMACS commands

Open EMACS as a standalone process

emacs "filename" &

Editing Commands

C-a   # Go to beginning of line 
C-k   # Delete line from current point

Buffers Commands

C-x b   # Switch between buffers
C-x C-s   # Save current buffer
C-x C-c    # Close current buffer

Windows Commands

C-x 4 b "buffer name"   # Open buffer in another window

C-x 4 f "filename"    # Open file in another window

C-x 0    # Close the currently selected window.

C-x 1    # Close all windows except the selected one.

C-x o    # Select another window.

Shell Commands

A-! "command"    # Execute shell command

A-x shell       # launch a interactive subshell

Wednesday, May 14, 2014

Malware - Removing Trovi

For some reason, which I still not sure why, I am hit by Trovi. Trovi is a browser hijacker which is capable of taking over the homepage of your browser. It has no simple way to remove it.

A search on Google has numbers of hit. Personally, I tried MalwareTips (http://malwaretips.com/blogs/trovi-search-removal/) advise and works.

Below are the general steps provide by MalwareTips

STEP 1: Remove Trovi Search browser hijacker from your computer with AdwCleaner (Complete scan in 15 min)
STEP 2: Remove Trovi Search from Internet Explore, Firefox and Google Chrome with Junkware Removal Tool (Complete scan in 10 min)
STEP 3: Remove Trovi Search malicious files with Malwarebytes Anti-Malware Free (Complete scan in 30 min)
STEP 4: Double-check for the Trovi Search infection with HitmanPro (Complete scan in 30 min, however, you need to manual remove those resulting hits as it is not a freeware)
(OPTIONAL) STEP 5: Reset your browser settings to remove Trovi Search from Internet Explorer, Firefox and Google Chrome

Details screenshots and step by step guild can be found at http://malwaretips.com/blogs/trovi-search-removal/