Make safe_strncat() available to modules.
[userinfo.git] / doc / README.modules
blob33151d602bbd491e8e0c2ea4b167a7e5fd71570d
1 Writing Userinfo Modules
2 ------------------------
4 This document describes how to write your own modules for use with the
5 userinfo utility.
6     
7 Here are the available functions for modules:
9     void (ui_module_init)(int *chainable);
10         Setup any defaults or anything that needs to be initialized for your
11         module here. The only parameter is a pointer to an integer which
12         should be set to 1 if the module is chainable and 0 if not. Chainable
13         means the previous module was passed the -x or -X option and this
14         module is at the middle or end of the module chain.
16     void (ui_module_exit)(void);
17         Your module should free any resources allocated and close any files
18         here. This is called just before the main program exits.
20     void *(ui_module_help)(void);
21         This displays help on the command line. Put a bunch of printf()'s in
22         here to show available command-line options for your module. Try to
23         keep the help output consistant with other modules (see -h).
25     char *(ui_module_options_init)(char **defaults);
26         This function should return an option string which is compatible with
27         getopt(3) for any options your module may take. The "defaults"
28         argument should be the default options you'd want specified (only
29         options without option arguments are supported) if none are specified
30         for this module on the command line or in the configuration file. If
31         your module takes no options then return NULL; this will bypass any
32         ui_module_options() calls (see below). If you do not want to set any
33         default options, then set "defaults" to NULL.
35     int (ui_module_options)(int argc, char **argv);
36         This function should parse your module command-line options via
37         getopt(3). It takes two arguments which are the argument count and
38         argument list as if passed to the main() function.
39         
40     int (ui_module_exec)(char ***, const struct passwd *, const int, const int,
41             char *);
42         This is the main module function. It takes a few arguments:
43             1 - A pointer to an array of character pointers holding strings
44                 which will be output in the order they have been added. If
45                 this parameter is initialized (not NULL), then chaining has
46                 been requested for this module (either -x or -X from the
47                 command-line, or '>' or '-' from the configuration file).
49             2 - A password structure for the current username.
51             3 - A character which separates multi-string values. This can be
52                 specified on the command line (-m). For example, the password
53                 module can output all groups a user belongs to. These groups
54                 are separated by a comma (by default) rather than the field
55                 deliminator (-F).
57             4 - Whether the -v option was passed on the command line
58                 (verbose). Useful if you want to limit the display unless
59                 otherwise needed.
61             5 - The strftime() time format. This is either the default or the
62                 value of the -t command line option. If you have any values
63                 that contain seconds-from-epoch, you should pass this format
64                 string to strftime() to maintain output consistency.
66         This function should return an integer 0 on success or 1 on general
67         failure. Note that this affects the program exit status.
69         The output for fields which contain static information should be
70         consistant with the hardcoded values in the main userinfo utility.
71         Type 'ui -h' and look for "Output Key" and assign values for the
72         static fields from this key.
74 Note that the order of output is dependent on the order of module loading and
75 the order of module options.
77 There are three other functions that are built into the userinfo utility which
78 can be used in your module. The first is a function to add a character string
79 to an array of character pointers:
81     void add_string(char ***dest, const char *string);
83 The first argument is the destination buffer and the second is the string to
84 add. 
86 The second function is a time format conversion function. It looks like this:
88     char *stamp(time_t epoch, const char *format);
90 If you have any information arguments that are time strings, you should try
91 and convert them to seconds-since-epoch then run them through the above
92 function. This keeps the time format consistant with other modules (-t command
93 line option).
95 Finally, a safer version of strncat(3) that will always nul-terminate the
96 destination buffer by treating the size N as N-1. Both the dst and src strings
97 must be nul terminated:
99     char *safe_strncat(char *dst, const char *src, size_t n);
101 If you have any questions, feel free to send them to the address below.
103 Ben Kibbey <bjk@luxsci.net>