Re: Validating sqlhosts and services
Posted in 2005
Topics: Networking & sqlhosts Configuration
On 15 Dec 2005 19:59:43 -0800, david@smooth1.co.uk <david@smooth1.co.uk> wrote: > Does anyone know how I could write code to check the services past of > sqlhosts? > > Something that checks a servicename is valid on the current machine? > What calls does IDS use to check? > > Same for the hostname? Can someone give us code to parse sqlhosts and > check? > Preferably in C that compiles also with gcc so it is portable and I can > build binaries for people? > > Something I have anyways wanted to do but never had time to code! > > Even if people cannot contribute code can they give me an idea for how > to check > for valid hostname (what DNS calls?) and service names (what > system/library calls??). It is complex. You'd want to validate that the dbservername column (column 1) contains unique names. For each possible value in column 2 - you have to do different checking of columns 3 and 4. The 'ol' and 'on' prefixes are synonymous and refer to IDS; 'se' refers to Standard Engine. You have a variety of continuations. 'ipcshm', 'ipcpip', 'tlitcp', 'soctcp', 'ipcstr', nominally 'tlispx', 'ipcnmp' on Windows, the MaxConnect protocols 'tliimc' and 'socimc', plus 'sqlmux'. Exactly which functions are best used to validate the host name entry is debatable. The entry can be an IPv4 or IPv6 host address (though both are strongly discouraged), or a host name, possibly with some domain-name qualifications (eg the FQDN - fully qualified domain name). The wonderful thing about standards is the number of options to choose from (no, that's not an original observation). Note that many of the protocols make no sense if the host name is not referring to the local machine - you get what you get. Try gethostbyname(). Assuming the host name is sufficiently valid, then you can think about looking at the 4th column. For example, for seipcpip, the fourth column is the name of an executable - located under $INFORMIXDIR/lib if there is no (absolute?) path, but in the stated directory if there is an absolute path. I'm not absolutely sure what happens if you give a relative path. For ipcshm, the name in the fourth column needs to be unique amongst all the names in the column for the local machine. (Note that you can only have one ipcshm connection per server; the error messages you get are not singularly informative if you try to configure two of them.) For the networking connections, the name in the fourth column identifies a service name, as exemplified by the /etc/services file on Unix, but usually augmented by any of a number of possible networked service lookup facilities - LDAP and NIS/NIS+ being some of the better known ones. The ipcstr connection names also need to be unique per machine. There is some information in /INFORMIXTMP that is used to gain access to local IDS instances. Yes - some of this info is woolly; I don't have a write-up of the details, nor am I at a machine where I can verify the details. Note that if the client's sqlhosts file says the olipcshm service is x but the server's says it is y, the two will not be able to connect. Why not use a Perl script instead of C? It is probably more portable, certainly smaller, a lot more legible, and ... just better? -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2005.02 -- http://dbi.perl.org/ sending to informix-list
Errm.. What if people do not have perl installed? With C I can provide binaries that have no external dependencies. I just want to validate ontlitcp or onsoctcp connections with this tool.
David, I have just knocked up the Shell/Awk solution below. I think this will do most of what you want, and is more legible than Perl! Cheers, Doug www.douglawry.webhop.org ________________ __| check_sqlhosts |______________________________________ # Validates an Informix "sqlhosts" file # Windows registry is not supported # To do: non-TCP service names, options # See also Administrator's Guide # Doug Lawry, 19/12/2005 awk ' BEGIN { products = "dr ol on se" interfaces = "ipc soc tli" protocols = "imc nmp shm spx str tcp" tcp_ip = "imc tcp" while (getline < "/etc/services") if ($1 ~ "^[A-Za-z]") service[$1] = "OK" } $1 ~ "^[A-Za-z]" { if (NF < 4) { print $1 ": < 4 fields" next } if (server[$1] == "used") print $1 ": duplicate server name" if ($2 == "group") next if (index(products, substr($2,1,2)) == 0 \\ || index(interfaces, substr($2,3,3)) == 0 \\ || index(protocols, substr($2,6,3)) == 0 \\ ) { print $1 ": invalid connection type", $2 next } if (system("ping " $3 " -n 1 > /dev/null") != 0) print $1 ": cannot ping " $3 if (index(tcp_ip, substr($2,6,3)) != 0) if ($4 * 1 == 0) # not port number if (service[$4] != "OK") print $1 ": unknown service " $4 server[$1] = "used" } ' ${INFORMIXSQLHOSTS:=$INFORMIXDIR/etc/sqlhosts}
Related threads
- the longer you surf, the MORE $$$ you earn !!
- Store procedure
- emulation for Vt100
- extent size questions again ...