IRC Services Technical Reference Manual

9. The database conversion tool

9-1. Purpose and usage
9-2. Structure
    9-2-1. The main program
    9-2-2. Format handlers
9-2. Supported database formats
    9-3-1. convert-cygnus.c (Cygnus)
    9-3-2. convert-epona.c (Epona, Anope)
    9-3-3. convert-hybserv.c (HybServ)
    9-3-4. convert-magick.c (Magick, Wrecked)
    9-3-5. convert-ptlink.c (PTlink)
    9-3-6. convert-sirv.c (Sirv, Auspice, Bolivia)
    9-3-7. convert-trircd.c (trircd)
    9-3-8. convert-ver8.c (Daylight, IRCS)


9-1. Purpose and usage

The database conversion tool convert-db is designed to allow users of other Services-like programs to migrate data stored with the other program into Services. This program serves as an adjunct to the main ircservices executable, reading in database files produced by foreign programs and writing out an XML file that can then be imported into Services with the misc/xml-import module (see section 8-4-2).

More information (from a user's point of view) can be found in section 5-3 of the user's manual.

As a historical note, this tool was introduced in version 4.1 of Services as import-db, and overwrote the existing Services databases with the imported data. This behavior was changed for version 5.0, both to dissociate the tool from the particular database format used by Services (which was still limited to the old binary format at the time, though implementation of a new format was planned) and to allow merging of data rather than simple overwriting. The tool's name was also changed to convert-db at this time to reflect the fact that it no longer performed the actual importing.


9-2. Structure

The convert-db tool can be divided into two main parts: the main program, which calls out to individual formats' probe and load routines, sanity-checks the loaded data, and writes out the XML data; and the format handlers, which process data produced by particular programs.

All source code for convert-db, with the exception of code borrowed from the main program, is located in the tools directory.

9-2-1. The main program

The overall database conversion processing is performed in the convert-db.c source file. The main() routine performs the following functions:

convert-db.c also links in compat.c and misc.c from the core code, making all of their functions available to format handlers, and implements several other utility functions, including simple versions of some core functions:

The nickname, channel, and other databases themselves are implemented as simple linked lists, since efficiency is not seen to be a significant concern for convert-db. Also, since the program exits immediately after writing out the converted data, no special effort is made to keep track of or free allocated memory; it is assumed that the operating system or library cleanup code will take care of freeing resources.

9-2-2. Format handlers

Format handlers perform the bulk of the conversion work. Each format is defined by a DBTypeInfo structure containing an identifying string for the format (used to match against the +program-name command-line option), a check() routine which determines whether a given directory contains databases in the format, and a load() routine which loads databases from a given directory. The list of available formats is hard-coded as a list of external structure variable names in convert-db.h, which is used in convert-db.c to initialize an array of formats. The structures and routine implementations themselves are stored in separate source files (see section 9-3 below).

The check() routine takes a single parameters, const char *dir, the path to the directory to be checked. The routine should check to see if a database in a recognized format is contained in that directory; if so, the routine should return a string describing the database format (usually the name, and version if known, of the program that created it), which will then be displayed to the user. If no recognized database is found, the routine should return NULL.

The load() routine takes four parameters:

The command-line option array is passed in addition to the source directory and verbosity flag to allow individual database loaders to implement their own options. For example, the Cygnus database takes advantage of this to add options for timezone handling.

The load() routine is assumed to succeed; if an error occurs that prevents the data from being loaded properly, the routine should simply call exit(1) to abort the program.

Additionally, the file read/write utilities from modules/database/fileutil.c (see section 6-5-1) are linked into convert-db and can be used by the check() and load() routines.


9-3. Supported database formats

convert-db supports loading data from a total of 13 different programs. The data loading code is in the various convert-*.c files, one file for each distinct format (several programs use similar database formats and therefore share code). Each of these files is discussed below.

In general, each format's load() routine is implemented as a function which calls subfunctions for each file to be loaded. Since most of the programs are based on old versions of Services, the contents of the files correspond fairly well with Services itself.

Where binary database files include fixed-length buffers, the lengths of those buffers are assumed to be the same as those in the distributed source code, with no changes to any configuration settings. For example, most IRC service programs default to a nickname buffer size of 32 bytes, and convert-db assumes that that value has not been changed by the user.

9-3-1. convert-cygnus.c (Cygnus)

Cygnus is an IRC service program based on an old version of Services; development seems to have stopped as of the writing of this manual. Unlike the other programs supported by convert-db, Cygnus stores its databases in plain text files, with each line containing a two-character field identifier and one or more values, all separated by spaces. As such, the data processing is somewhat more complex than for other databse formats, particularly for numeric values, which must be checked for syntactic validity as well as range. The following utility routines and macros are used by the various loading functions:

Cygnus also supports storing time zone information with each nickname, like NickServ SET TIMEZONE in Services; however, rather than storing the actual time offset, Cygnus stores an index into a table whose contents are controlled by a configuration file. The default list of time zone offsets is included in the default_timezones[] array, but since users may have modified the time zone configuration, the command-line option -tzfile=filename is checked for by the load() function, allowing the user to specify their configuration file, which is then loaded and used in place of the default list; -no-timezones (which causes all time zone data to be discarded) is also supported as a fallback in case time zone importing results in incorrect data.

Cygnus does not have a "default" value, like MEMOMAX_DEFAULT in Services, for the memo limit field, but instead stores the actual value of the default limit at the time the nickname is registered. As a result, these values will remain constant in Services even if the MSMaxMemos configuration setting is changed. To work around this, the -reset-memo-limits command-line option is checked for, and if present, all memo limits are reset to MEMOMAX_DEFAULT.

The data files are as follows:

9-3-2. convert-epona.c (Epona, Anope)

Epona IRC Services is an IRC service program based on Services 4.3.3; development has been intermittent since the release of Epona 1.4 in 2001. Anope Services was forked from Epona 1.4.14, and has been developed more actively. Both use a database format similar to the Services 4.3 format; however, rather than a single format version number for all files, individual version numbers are used for each file. (As noted in the user manual, versions of Anope since 1.7.11 also support storing databases in a MySQL database; access to such databases is not supported by the convert-db tool.)

Epona and Anope use a "nick core plus nick aliases" concept for registered nicknames, in which most nickname data is stored with a single "core" nick and other nicknames can "aliased" to the same settings (the redesigned nickname linking system in Services 5.0 was based on this concept). Other data is structured similarly to Services, and conversion is fairly straightforward.

Anope supports a number of IRC servers; unfortunately, the flag values used in the channel mode lock fields stored in the database vary between IRC servers (though given the vast range of channel modes present in various servers, this is probably unavoidable). In order to interpret the mode flags correctly, the converter allows a "-ircd=" option to be passed on the command line. The parameter to this option selects the IRC server type to be used for interpreting channel modes. If no -ircd option is given, the converter only converts the eight basic channel modes (i, k, l, m, n, p, s, t), which share the same flag values across all IRC server types.

Since Anope 1.7.18, administrators can select one of several encryption modules, similar to how encryption was handled in Services 5.0. This method shares the same shortcoming present in Services 5.0, however, which is that a particular password's encryption status cannot be determined from the data itself. To work around this problem, the converter accepts a command-line option "-encryption=" to select the type of encryption used for passwords in the databases. If this option is given, the "encrypted" flag on nickname cores and channels is ignored, and all passwords are assumed to use the given encryption type; otherwise, the "encrypted" flag selects between MD5 encryption and no encryption. (For forward compatilibity, sha1 is accepted to indicate SHA-1 encryption, but Services will not be able to check such passwords without a third-party module implementing the SHA-1 hash.)

The Epona/Anope database files are:

9-3-3. convert-hybserv.c (HybServ)

HybServ is an IRC service program designed from scratch for networks using the IRCD-Hybrid IRC server. After version 1.6, development changed hands and the program was renamed HybServ2, but as they share a common codebase, "HybServ" is used to refer to both in this documentation. Several modified versions of HybServ have also been seen.

Like Cygnus, HybServ writes its databases to text files. The format is similar to IRC commands, with a record or field identifier followed by an arbitrary number of space-separated parameters, and with a leading colon indicating a parameter that continues to the end of the line (including spaces). The first line of each file begins with "; Hybserv", which is used by the check() routine to check for the existence of HybServ databases.

HybServ allows passwords to be encrypted, using the Unix crypt() function; however, encryption status is not stored in the databases themselves, so the command-line option -crypt must be given to convert-db to make it treat passwords as encrypted.

9-3-4. convert-magick.c (Magick, Wrecked)

Magick IRC Services is an IRC service program based on a very old version of Services, and WreckedNet IRC Services is a modified version of Magick; both seem to be defunct as of the writing of this manual.

The databases used by these programs are similar to the format used by Services before machine-independence was introduced in version 4.0: rather than writing each variable in a consistent way, they simply dump the structures to disk as is. As such, convert-db assumes that the databases are being loaded on the same machine that produced them; attempting to read the databases on a different architecture (and in some cases, on the same architecture using a different compiler) will likely fail.

Magick and Wrecked support nickname and channel suspensions via flags, but do not record any other suspension information, so default values are filled in. These programs also support a hierarchical system of nickname links, and these are resolved into nickname groups after all nicknames are read in.

The data files used by Magick and Wrecked are as follows:

9-3-5. convert-ptlink.c (PTlink)

PTlink Services is an IRC service program designed specifically for the PTlink IRC server. It appears to be based on a fairly old version of Services, and uses a similar data file format. (Another, apparently separately developed, program called PTlink IRC Services has recently appeared; it uses MySQL for database storage, and is not supported by convert-db.)

PTlink stores the encryption method used for passwords with the corresponding nickname or channel, a significant improvement over Services' method (at the time) of using a single method for the entire database. convert-db reads the encryption method and includes it in the XML output; however, the "JP2" method used in PTlink is not available in Services, and any passwords encrypted with this method, or with an unknown method, are reset to the corresponding nick or channel name with no encryption (a warning is printed in this case).

PTlink also stores record counts in the nickname and channel databases, similar to Cygnus, for the purpose of ensuring that the data is loaded correctly; however, there have apparently been bugs in some versions of PTlink that caused valid databases to have a mismatch between this value and the number of records actually recorded. convert-db still checks the value, but the warning message on mismatch includes a note about this issue.

The following data files are used by PTlink (some only by more recent versions):

9-3-6. convert-sirv.c (Sirv, Auspice, Bolivia)

SirvNET Services is an IRC service program designed for use on SirvNET. Earlier versions were based on an old version of Services; version 3.0.0 was a complete rewrite, and development is actively continuing. Since version 3.0.0, Sirv requires a MySQL database to operate, and apparently has no way to export its data to ordinary files; thus, Sirv databases are only supported through version 2.9.0.

Auspice is an IRC service program that appears to have been based on an old version of Sirv, and was designed for UnrealIRCd networks. Development status is unclear.

Bolivia IRC Services is an IRC service program that also appears to have been based on Sirv, and developed for a particular network. The program appears to be defunct as of the writing of this manual.

All three of these programs share the same overall file format, so they have been grouped in the same file despite fairly significant differences in the details to avoid code repetition. The base format seems to be that from Services 3.x, before machine-independence was introduced.

The database files are as follows:

9-3-7. convert-trircd.c (trircd)

trircd IRC Services is a fork of Services 4.5.36 developed for the tr-ircd IRC server, and has been discontinued since support for tr-ircd was added to Services. The data files are essentially the same as those in Services 4.5.36, with the addition of the following data files:

9-3-8. convert-ver8.c (Daylight, IRCS)

Daylight is a fork of Services 4.3.3 developed for the UnrealIRCd IRC server, and has been discontinued since support for Unreal was added to Services. IRCS is a fork of Services 4.0.5 developed for Undernet (ircu) IRC servers, and appears to be defunct as of the writing of this manual. Both use a data format essentially unchanged from that in the original Services versions; the data file format at that time was version 8, hence the source file name "convert-ver8.c".

The Daylight database format is almost completely unchanged from the original version 8, with the exception of an extra channel flag CI_XMANAGEMENT which is ignored.

The IRCS database format uses a channel name buffer size of 204 bytes and a password size of 16 bytes. Services defaults to a maximum channel name buffer size of 64 bytes, and will truncate (with a warning) any channel name that is too long to fit in the buffer. IRCS also uses five OperServ privilege levels instead of two, and users on the extra lists ("senior", "junior", and "helper") are moved onto either the admin or the oper list depending on appropriate privileges.

IRCS adds one data file to the base Services set: gline.db, containing "G-line" (autokill) data.