The 'changelog' target now only generates changes from v5.0.x to
[libpwmd.git] / doc / libpwmd.3
blobaa082e3c35efea46439a0c053f81f4c465f994dd
1 .TH "libpwmd.h" 3 "5 Apr 2009" "Version 6.0.0" "libpwmd" \" -*- nroff -*-
2 .ad l
3 .nh
4 .SH NAME
5 libpwmd.h \- 
6 .SH "Detailed Description"
7 .PP 
8 libpwmd is a library making it easy for applications to use the pwmd server.
9 .SH "SSH Details"
10 .PP
11 A remote connection to a pwmd server is possible by using an SSH channel which spawns a shell and executes a proxy server that connects to the pwmd local unix domain socket. Authenication is done by using SSH public key (see \fBssh-keygen(1)\fP) authentication and verifying the host key against a local file containing SHA1 hashes of known hosts. It's alot like how the standard OpenSSH does things only the known_hosts file is in a different format.
12 .PP
13 The server hash can be had by using \fBpwmd_get_hostkey()\fP and storing the result in a file. This file is then used as the \fIknown_hosts\fP argument to the SSH connection functions.
14 .PP
15 Here's an example \fBauthorized_keys(5)\fP entry. The hash portion should be the same as the contents of the \fIidentity.pub\fP file which is passed as a parameter to the SSH connection functions:
16 .PP
17 .PP
18 .nf
19  command='socat gopen:$HOME/.pwmd/socket -' <hash> ...
20 .fi
21 .PP
22 .PP
23 \fBTodo\fP
24 .RS 4
25 X11 port forwarding so a remote pinentry can use the local display. 
26 .RE
27 .PP
28 .SH "Pinentry Details"
29 .PP
30 \fBpinentry(1)\fP is a program that prompts the user for input which is normally a passphrase or a confirmation. libpwmd can use this program either locally (the connection is to a remote server not on this host) or have the pwmd server use it's pinentry to retrieve a passphrase when needed.
31 .PP
32 There are a few options that tell pinentry how and where to prompt for a passphrase. See the \fBpwmd_option_t\fP section for details. These options are not sent (when using pwmd's pinentry) until the pinentry is needed.
33 .PP
34 If using a local pinentry by calling \fBpwmd_open2()\fP, \fBpwmd_save2()\fP, \fBpwmd_open_async2()\fP or \fBpwmd_save_async2()\fP, libpwmd will send the command 'OPTION PINENTRY=0' to the server. This is needed for pinentry retries (passphrase or confirmation failure). So if you need to change pinentry methods, then set this option as needed.
35 .PP
36 Some pinentry options can also be specified in a local configuration file \fI'~/.pwmd/pinentry.conf'\fP. These options are initial values for each invokation and may be changed by setting the appropriate \fBpwmd_option_t\fP. Each option and value is separated with a '=' on a single line. Unrecognized options are ignored. Here are the recognized options:
37 .PP
38 \fBParameters:\fP
39 .RS 4
40 \fIPATH\fP The full path to the location of the pinentry binary. 
41 .br
42 \fIDISPLAY\fP The X11 display to use. 
43 .br
44 \fITTYNAME\fP The full path to the tty that pinentry should prompt on. 
45 .br
46 \fITTYTYPE\fP The terminal type of the tty which is required if DISPLAY is not set.
47 .RE
48 .PP
49 \fBSee also:\fP
50 .RS 4
51 \fBSSH Details\fP
52 .RE
53 .PP
54 .SH "Example Client"
55 .PP
56 The following example will list the element tree of the data file specified in the first command line argument.
57 .PP
58 .PP
59 .nf
60  #include <stdio.h>
61  #include <libpwmd.h>
63  int main()
64  {
65      pwm_t *pwm = pwmd_new(NULL);
66      gpg_error_t rc = pwmd_connect(pwm, NULL);
67      char *result;
68      
69      if (!rc) {
70          rc = pwmd_open(pwm, argv[1]);
72          if (!rc) {
73              rc = pwmd_command(pwm, &result, '%s', 'LIST');
75              if (!rc) {
76                  printf('%s', result);
77                  pwmd_free(result);
78              }
79          }
80      }
82      pwmd_close(pwm);
83      
84      if (rc)
85          fprintf(stderr, 'ERR: %s\n', pwmd_strerror(rc));
87      exit(rc ? 1 : 0);
88  }
89 .fi
90 .PP
92 .SH SYNOPSIS
93 .br
94 .PP
95 .SS "Data Structures"
97 .in +1c
98 .ti -1c
99 .RI "struct \fBpwmd_fd_t\fP"
101 .in -1c
102 .SS "Defines"
104 .in +1c
105 .ti -1c
106 .RI "#define \fBLIBPWMD_VERSION\fP"
108 .ti -1c
109 .RI "#define \fBPWMD_FD_READABLE\fP"
111 .ti -1c
112 .RI "#define \fBPWMD_FD_WRITABLE\fP"
114 .ti -1c
115 .RI "#define \fBEPWMD_ERROR\fP"
117 .ti -1c
118 .RI "#define \fBEPWMD_MAX_SLOTS\fP"
120 .ti -1c
121 .RI "#define \fBEPWMD_LOOP\fP"
123 .ti -1c
124 .RI "#define \fBEPWMD_NO_FILE\fP"
126 .ti -1c
127 .RI "#define \fBEPWMD_LIBXML_ERROR\fP"
129 .ti -1c
130 .RI "#define \fBEPWMD_FILE_MODIFIED\fP"
132 .ti -1c
133 .RI "#define \fBEPWMD_MAX\fP"
135 .in -1c
136 .SS "Typedefs"
138 .in +1c
139 .ti -1c
140 .RI "typedef struct pwm_s \fBpwm_t\fP"
142 .ti -1c
143 .RI "typedef gpg_error_t(* \fBpwmd_passphrase_cb_t\fP )(void *user, char **passphrase)"
145 .ti -1c
146 .RI "typedef int(* \fBpwmd_status_cb_t\fP )(void *user, const char *line)"
148 .ti -1c
149 .RI "typedef gpg_error_t(* \fBpwmd_inquire_cb_t\fP )(void *user, const char *cmd, gpg_error_t rc, char **data, size_t *len)"
151 .in -1c
152 .SS "Enumerations"
154 .in +1c
155 .ti -1c
156 .RI "enum \fBpwmd_async_t\fP { \fBASYNC_INIT\fP, \fBASYNC_PROCESS\fP, \fBASYNC_DONE\fP }"
158 .ti -1c
159 .RI "enum \fBpwmd_ip_version_t\fP { \fBPWMD_IP_ANY\fP, \fBPWMD_IPV4\fP, \fBPWMD_IPV6\fP }"
161 .ti -1c
162 .RI "enum \fBpwmd_option_t\fP { \fBPWMD_OPTION_PASSPHRASE_CB\fP, \fBPWMD_OPTION_PASSPHRASE_DATA\fP, \fBPWMD_OPTION_PASSPHRASE\fP, \fBPWMD_OPTION_PINENTRY_TRIES\fP, \fBPWMD_OPTION_PINENTRY_PATH\fP, \fBPWMD_OPTION_PINENTRY_TTY\fP, \fBPWMD_OPTION_PINENTRY_TERM\fP, \fBPWMD_OPTION_PINENTRY_DISPLAY\fP, \fBPWMD_OPTION_PINENTRY_TITLE\fP, \fBPWMD_OPTION_PINENTRY_PROMPT\fP, \fBPWMD_OPTION_PINENTRY_DESC\fP, \fBPWMD_OPTION_PINENTRY_LC_CTYPE\fP, \fBPWMD_OPTION_PINENTRY_LC_MESSAGES\fP, \fBPWMD_OPTION_PINENTRY_TIMEOUT\fP, \fBPWMD_OPTION_STATUS_CB\fP, \fBPWMD_OPTION_STATUS_DATA\fP, \fBPWMD_OPTION_IP_VERSION\fP }"
164 .in -1c
165 .SS "Functions"
167 .in +1c
168 .ti -1c
169 .RI "gpg_error_t \fBpwmd_init\fP (void)"
171 .ti -1c
172 .RI "\fBpwm_t\fP * \fBpwmd_new\fP (const char *name)"
174 .ti -1c
175 .RI "gpg_error_t \fBpwmd_connect\fP (\fBpwm_t\fP *pwm, const char *path)"
177 .ti -1c
178 .RI "gpg_error_t \fBpwmd_ssh_connect\fP (\fBpwm_t\fP *pwm, const char *host, int port, const char *identity, const char *user, const char *known_hosts)"
180 .ti -1c
181 .RI "gpg_error_t \fBpwmd_ssh_connect_async\fP (\fBpwm_t\fP *pwm, const char *host, int port, const char *identity, const char *user, const char *known_hosts)"
183 .ti -1c
184 .RI "gpg_error_t \fBpwmd_get_hostkey\fP (\fBpwm_t\fP *pwm, const char *host, int port, char **result)"
186 .ti -1c
187 .RI "gpg_error_t \fBpwmd_get_hostkey_async\fP (\fBpwm_t\fP *pwm, const char *host, int port)"
189 .ti -1c
190 .RI "gpg_error_t \fBpwmd_get_fds\fP (\fBpwm_t\fP *pwm, pwmd_fd_t *fds, int *n_fds)"
192 .ti -1c
193 .RI "gpg_error_t \fBpwmd_pending_line\fP (\fBpwm_t\fP *pwm)"
195 .ti -1c
196 .RI "gpg_error_t \fBpwmd_setopt\fP (\fBpwm_t\fP *pwm, \fBpwmd_option_t\fP opt,...)"
198 .ti -1c
199 .RI "gpg_error_t \fBpwmd_open\fP (\fBpwm_t\fP *pwm, const char *filename)"
201 .ti -1c
202 .RI "gpg_error_t \fBpwmd_open2\fP (\fBpwm_t\fP *pwm, const char *filename)"
204 .ti -1c
205 .RI "gpg_error_t \fBpwmd_open_async2\fP (\fBpwm_t\fP *pwm, const char *filename)"
207 .ti -1c
208 .RI "gpg_error_t \fBpwmd_open_async\fP (\fBpwm_t\fP *pwm, const char *filename)"
210 .ti -1c
211 .RI "\fBpwmd_async_t\fP \fBpwmd_process\fP (\fBpwm_t\fP *pwm, gpg_error_t *rc, char **result)"
213 .ti -1c
214 .RI "gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm)"
216 .ti -1c
217 .RI "gpg_error_t \fBpwmd_save2\fP (\fBpwm_t\fP *pwm)"
219 .ti -1c
220 .RI "gpg_error_t \fBpwmd_save_async2\fP (\fBpwm_t\fP *pwm)"
222 .ti -1c
223 .RI "gpg_error_t \fBpwmd_save_async\fP (\fBpwm_t\fP *pwm)"
225 .ti -1c
226 .RI "gpg_error_t \fBpwmd_command\fP (\fBpwm_t\fP *pwm, char **result, const char *cmd,...)"
228 .ti -1c
229 .RI "gpg_error_t \fBpwmd_command_ap\fP (\fBpwm_t\fP *pwm, char **result, const char *cmd, va_list ap)"
231 .ti -1c
232 .RI "gpg_error_t \fBpwmd_inquire\fP (\fBpwm_t\fP *pwm, const char *cmd, \fBpwmd_inquire_cb_t\fP func, void *user)"
234 .ti -1c
235 .RI "void \fBpwmd_close\fP (\fBpwm_t\fP *pwm)"
237 .ti -1c
238 .RI "void \fBpwmd_free\fP (void *ptr)"
240 .ti -1c
241 .RI "void * \fBpwmd_malloc\fP (size_t size)"
243 .ti -1c
244 .RI "void * \fBpwmd_calloc\fP (size_t nmemb, size_t size)"
246 .ti -1c
247 .RI "void * \fBpwmd_realloc\fP (void *ptr, size_t size)"
249 .ti -1c
250 .RI "char * \fBpwmd_strdup\fP (const char *str)"
252 .ti -1c
253 .RI "char * \fBpwmd_strdup_printf\fP (const char *fmt,...)"
255 .ti -1c
256 .RI "const char * \fBpwmd_strerror\fP (gpg_error_t code)"
258 .ti -1c
259 .RI "int \fBpwmd_strerror_r\fP (gpg_error_t code, char *buf, size_t size)"
261 .in -1c
262 .SH "Define Documentation"
263 .PP 
264 .SS "#define EPWMD_ERROR"
266 A general pwmd error with no suitable description. 
267 .SS "#define EPWMD_FILE_MODIFIED"
269 The data file was modified either externally or by another another client while trying to process a command. 
270 .SS "#define EPWMD_LIBXML_ERROR"
272 An XML parse or other libxml2 error occurred. 
273 .SS "#define EPWMD_LOOP"
275 A recursion loop was detected while processing a 'target' attribute. 
276 .SS "#define EPWMD_MAX_SLOTS"
278 The maximum number of cache slots has been reached. There is no available slot for a new file. 
279 .SS "#define EPWMD_NO_FILE"
281 A command required an open file, but no file has yet been opened. 
282 .SS "#define LIBPWMD_VERSION"
284 The version of this library. 
285 .SS "#define PWMD_FD_READABLE"
287 Set when the file descriptor is readable. 
288 .SS "#define PWMD_FD_WRITABLE"
290 Set when the file descriptor is writable. 
291 .SH "Typedef Documentation"
292 .PP 
293 .SS "\fBpwm_t\fP"
295 When a handle is mentioned in this documentation it is a pointer of this type. A new handle is created with \fBpwmd_new()\fP. 
296 .SS "\fBpwmd_inquire_cb_t\fP"
298 This is a callback function that gets passed to \fBpwmd_inquire()\fP. It is used for sending data to the server for commands that return an INQUIRE response (STORE and IMPORT). The reason for this callback is to let the client send as many bytes as it wants rather than the entire chunk at once. It gets called during \fBassuan_transact()\fP from an internal inquire callback function which in turn calls this function by looping over its return value.
300 \fBParameters:\fP
301 .RS 4
302 \fIuser\fP The user data pointer passed to \fBpwmd_inquire()\fP. 
304 \fIcmd\fP The same as the \fIcmd\fP argument to \fBpwmd_inquire()\fP. 
306 \fIrc\fP The result of the last internal call to \fBassuan_send_data()\fP which did the sending of the data to the pwmd server. On the first call to this callback it will always be 0 because no data has been sent yet. 
308 \fIdata\fP The next chunk of data to send or NULL. 
310 \fIlen\fP The length of \fIdata\fP or 0.
313 \fBReturn values:\fP
314 .RS 4
315 \fI0\fP There is more data to be sent. 
317 \fIGPG_ERR_EOF\fP No need to call this function again, the current \fIline\fP is the last to send. 
319 \fIcode\fP Any other error code which will terminate the INQUIRE.
322 \fBNote:\fP
323 .RS 4
324 The sent data is processed line-per-line. The line is either newline terminated or is buffered until ASSUAN_LINELENGTH bytes have been allocated. Any remaining bytes are sent after the INQUIRE has finished. 
328 .SS "\fBpwmd_passphrase_cb_t\fP"
330 The value of the option \fBPWMD_OPTION_PASSPHRASE_CB\fP which is set with \fBpwmd_setopt()\fP.
332 \fBParameters:\fP
333 .RS 4
334 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_PASSPHRASE_DATA\fP. 
336 \fIpassphrase\fP The passphrase which may be an empty string or NULL. 
339 \fBReturns:\fP
340 .RS 4
341 0 on success or an error code which will cause a command to fail. 
345 .SS "\fBpwmd_status_cb_t\fP"
347 The value of the option \fBPWMD_OPTION_STATUS_CB\fP which is set with \fBpwmd_setopt()\fP.
349 \fBParameters:\fP
350 .RS 4
351 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_STATUS_DATA\fP. 
353 \fIline\fP The status message line. 
356 \fBReturns:\fP
357 .RS 4
358 0 on success or an error code which will cause a command to fail. 
362 .SH "Enumeration Type Documentation"
363 .PP 
364 .SS "enum \fBpwmd_async_t\fP"
366 The return code of \fBpwmd_process()\fP which is used for all asynchronous commands. 
368 \fBEnumerator: \fP
369 .in +1c
371 \fB\fIASYNC_INIT \fP\fP
373 \fBFor internal use only.\fP
374 .RS 4
379 \fB\fIASYNC_PROCESS \fP\fP
380 \fBpwmd_process()\fP should be called again. 
382 \fB\fIASYNC_DONE \fP\fP
383 The command has completed. The result code should be checked for an error. 
384 .SS "enum \fBpwmd_ip_version_t\fP"
386 The value of the option \fBPWMD_OPTION_IP_VERSION\fP which is set with \fBpwmd_setopt()\fP. 
388 \fBEnumerator: \fP
389 .in +1c
391 \fB\fIPWMD_IP_ANY \fP\fP
392 Try both IPv6 and IPv4 addresses. Note that IPv6 is tried first. 
394 \fB\fIPWMD_IPV4 \fP\fP
395 Only try IPv4. 
397 \fB\fIPWMD_IPV6 \fP\fP
398 Only try IPv6. 
399 .SS "enum \fBpwmd_option_t\fP"
401 libpwmd options which are set with \fBpwmd_setopt()\fP. 
403 \fBEnumerator: \fP
404 .in +1c
406 \fB\fIPWMD_OPTION_PASSPHRASE_CB \fP\fP
407 A custom passphrase retrieval function which, when set, will be used instead of \fBpinentry(1)\fP. This function will not be used when the passphrase is cached on the server or the file is a new one. The value of this option should be a \fBpwmd_passphrase_cb_t\fP function pointer. 
409 \fB\fIPWMD_OPTION_PASSPHRASE_DATA \fP\fP
410 User supplied data which is passed to the custom password function. 
412 \fB\fIPWMD_OPTION_PASSPHRASE \fP\fP
413 A string to use as the passphrase when doing an open or save. When not NULL, this option has precedence over \fBPWMD_OPTION_PASSPHRASE_CB\fP. 
415 \fB\fIPWMD_OPTION_PINENTRY_TRIES \fP\fP
416 An integer value that specifies the specified the number of tries before \fBpinentry(1)\fP will give up when opening a file with the wrong supplied passphrase. The default is 3.
418 \fBNote:\fP
419 .RS 4
420 This option has no effect when trying to save a file. The user must either cancel the pinentry causing the save to fail or enter the correct passphrase during passphrase confirmation. 
425 \fB\fIPWMD_OPTION_PINENTRY_PATH \fP\fP
426 A character string value which specifies the full path of the \fBpinentry(1)\fP binary. For the local \fBpinentry(1)\fP method, the default is specified at compile time.
428 \fBSee also:\fP
429 .RS 4
430 \fBPinentry Details\fP 
435 \fB\fIPWMD_OPTION_PINENTRY_TTY \fP\fP
436 A value which specifies the full path to the tty that \fBpinentry(1)\fP will use. When set and no DISPLAY is available, \fBPWMD_OPTION_PINENTRY_TERM\fP must also be set.
438 \fBSee also:\fP
439 .RS 4
440 \fBPinentry Details\fP 
445 \fB\fIPWMD_OPTION_PINENTRY_TERM \fP\fP
446 A value which specifies the terminal type (e.g., vt100) that \fBpinentry(1)\fP will use when no X11 display is available.
448 \fBSee also:\fP
449 .RS 4
450 \fBPinentry Details\fP 
455 \fB\fIPWMD_OPTION_PINENTRY_DISPLAY \fP\fP
456 A value which specifies the X11 display that \fBpinentry(1)\fP will use.
458 \fBSee also:\fP
459 .RS 4
460 \fBPinentry Details\fP 
465 \fB\fIPWMD_OPTION_PINENTRY_TITLE \fP\fP
466 A character string that \fBpinentry(1)\fP will use in it's dialog window. 
468 \fB\fIPWMD_OPTION_PINENTRY_PROMPT \fP\fP
469 A character string that \fBpinentry(1)\fP will use in it's dialog window.  
471 \fB\fIPWMD_OPTION_PINENTRY_DESC \fP\fP
472 A character string that \fBpinentry(1)\fP will use in it's dialog window.  
474 \fB\fIPWMD_OPTION_PINENTRY_LC_CTYPE \fP\fP
475 For \fBpinentry(1)\fP localization. 
477 \fB\fIPWMD_OPTION_PINENTRY_LC_MESSAGES \fP\fP
478 For \fBpinentry(1)\fP localization.  
480 \fB\fIPWMD_OPTION_PINENTRY_TIMEOUT \fP\fP
481 An integer value that specifies the number of seconds \fBpinentry(1)\fP will wait for input before timing out and aborting the current command. If 0, then no timeout will be used. The default is 30. 
483 \fB\fIPWMD_OPTION_STATUS_CB \fP\fP
484 A function pointer of type \fBpwmd_status_cb_t\fP that will process status messages received from the pwmd server. 
486 \fB\fIPWMD_OPTION_STATUS_DATA \fP\fP
487 A user data pointer which is passed to the status message function. 
489 \fB\fIPWMD_OPTION_IP_VERSION \fP\fP
490 The IP version of type \fBpwmd_ip_version_t\fP that \fBpwmd_ssh_connect()\fP and \fBpwmd_ssh_connect_async()\fP will use when connecting to the remote pwmd server.
492 \fBNote:\fP
493 .RS 4
494 This option must be set before a connection is made when not the default. 
498 .SH "Function Documentation"
499 .PP 
500 .SS "void* pwmd_calloc (size_t nmemb, size_t size)"
502 A wrapper around calloc(). 
504 Like calloc(), but lets libpwmd keep track of the pointer.
506 \fBParameters:\fP
507 .RS 4
508 \fInmemb\fP The number of bytes to allocate. 
510 \fIsize\fP The number of bytes to allocate. 
513 \fBReturns:\fP
514 .RS 4
515 A newly allocated pointer or NULL if there wasn't enough memory. 
518 \fBSee also:\fP
519 .RS 4
520 calloc(3), \fBpwmd_free()\fP 
524 .SS "void pwmd_close (\fBpwm_t\fP * pwm)"
526 Close a handle. 
528 This will close the connection to a pwmd server and free any resources associated with it.
530 \fBParameters:\fP
531 .RS 4
532 \fIpwm\fP A handle. 
535 \fBReturns:\fP
536 .RS 4
537 Nothing. 
541 .SS "gpg_error_t pwmd_command (\fBpwm_t\fP * pwm, char ** result, const char * cmd,  ...)"
543 Send a command to the pwmd server. 
545 Sends a command to the pwmd server. You should avoid sending the BYE command here because the assuan context will be freed and bad things will happen. Use \fBpwmd_close()\fP instead. For commands that use an INQUIRE to send data to the server (STORE and IMPORT), \fBpwmd_inquire()\fP should be used and not this function.
547 \fBParameters:\fP
548 .RS 4
549 \fIpwm\fP A handle. 
551 \fIresult\fP The result of the command when successful and which must be freed with \fBpwmd_free()\fP. Note that not all commands return a result. 
553 \fIcmd\fP The command to send. 
555 \fI...\fP The arguments to \fIcmd\fP. 
558 \fBReturns:\fP
559 .RS 4
560 0 on success or an error code. 
564 .SS "gpg_error_t pwmd_command_ap (\fBpwm_t\fP * pwm, char ** result, const char * cmd, va_list ap)"
566 Send a command to the pwmd server. 
568 Like \fBpwmd_command()\fP but uses an argument pointer instead.
570 \fBParameters:\fP
571 .RS 4
572 \fIpwm\fP A handle. 
574 \fIresult\fP The result of the command when successful which must be freed with \fBpwmd_free()\fP. Note that not all commands return a result. 
576 \fIcmd\fP The command to send. 
578 \fIap\fP The arguments to \fIcmd\fP. 
581 \fBReturns:\fP
582 .RS 4
583 0 on success or an error code. 
587 .SS "gpg_error_t pwmd_connect (\fBpwm_t\fP * pwm, const char * path)"
589 Connect to a local pwmd server. 
591 Connects to a local unix domain socket.
593 \fBParameters:\fP
594 .RS 4
595 \fIpwm\fP A handle. 
597 \fIpath\fP The socket path to connect to. If NULL, then a default of \fI'~/.pwmd/socket'\fP will be used. 
600 \fBReturns:\fP
601 .RS 4
602 0 on success or an error code. 
605 \fBSee also:\fP
606 .RS 4
607 \fBpwmd_ssh_connect()\fP, \fBpwmd_ssh_connect_async()\fP 
611 .SS "void pwmd_free (void * ptr)"
613 Free a previously allocated pointer. 
615 Use this function to free resources allocated by the other libpwmd memory functions. Do not use it to free your own allocations.
617 The difference between the standard free() and this function is that this one will zero out the contents of the pointer before freeing it.
619 \fBParameters:\fP
620 .RS 4
621 \fIptr\fP The pointer to deallocate. 
624 \fBReturns:\fP
625 .RS 4
626 Nothing. 
629 \fBSee also:\fP
630 .RS 4
631 \fBpwmd_malloc()\fP, \fBpwmd_calloc()\fP, \fBpwmd_realloc()\fP, \fBpwmd_strdup()\fP, \fBpwmd_process()\fP, \fBpwmd_command()\fP 
635 .SS "gpg_error_t pwmd_get_fds (\fBpwm_t\fP * pwm, pwmd_fd_t * fds, int * n_fds)"
637 Get the associated file descriptor(s) for a handle. 
639 This function lets the application poll the available file descriptors for the specified handle. It should be called after each asynchronous function and after each call to \fBpwmd_process()\fP since the polled file descriptors may have been closed since the last call. It should also be called periodically to determine when to call \fBpwmd_process()\fP to parse any pending status messages.
641 After returning, \fIn_fds\fP is set to the number of available file descriptors which are stored in \fIfds\fP. The .flags member of \fBpwmd_fd_t\fP specifies what can be monitored and is a bitmask of \fBPWMD_FD_READABLE\fP and \fBPWMD_FD_WRITABLE\fP. When ready, \fBpwmd_process()\fP should be called.
643 \fBParameters:\fP
644 .RS 4
645 \fIpwm\fP A handle. 
647 \fIfds\fP Set to the file descriptor(s) of the associated handle. 
649 \fIn_fds\fP Initially the size of \fIfds\fP then updated to the number of available file descriptors which are stored in \fIfds\fP. 
652 \fBReturn values:\fP
653 .RS 4
654 \fI0\fP on success or an error code. 
656 \fIGPG_ERR_ERANGE\fP There are more file descriptors than the amount specified in \fIn_fds\fP. \fIfds\fP and \fIn_fds\fP are still usable though. 
659 \fBSee also:\fP
660 .RS 4
661 \fBpwmd_process()\fP 
665 .SS "gpg_error_t pwmd_get_hostkey (\fBpwm_t\fP * pwm, const char * host, int port, char ** result)"
667 Retrieve a remote SSH host key. 
669 This key is needed for host verification of the remote pwmd server.
671 \fBParameters:\fP
672 .RS 4
673 \fIpwm\fP A handle. 
675 \fIhost\fP The hostname to connect to. 
677 \fIport\fP The port. 
679 \fIresult\fP The server host key which must be freed with \fBpwmd_free()\fP. 
682 \fBReturns:\fP
683 .RS 4
684 0 on success or an error code. 
687 \fBSee also:\fP
688 .RS 4
689 \fBpwmd_get_hostkey_async()\fP, \fBSSH Details\fP 
693 .SS "gpg_error_t pwmd_get_hostkey_async (\fBpwm_t\fP * pwm, const char * host, int port)"
695 Retrieve a remote SSH host key asynchronously. 
697 This key is needed for host verification of the remote pwmd server.
699 \fBpwmd_process()\fP should be called until the command completes.
701 \fBParameters:\fP
702 .RS 4
703 \fIpwm\fP A handle. 
705 \fIhost\fP The hostname to connect to. 
707 \fIport\fP The port or a default if set to -1. 
710 \fBReturns:\fP
711 .RS 4
712 0 on success or an error code. 
715 \fBSee also:\fP
716 .RS 4
717 \fBpwmd_get_hostkey()\fP, \fBpwmd_process()\fP, \fBSSH Details\fP 
721 .SS "gpg_error_t pwmd_init (void)"
723 Initialize the library. 
725 This function must be the first function called in the library before any others. It sets up internationalization among other things.
727 \fBReturns:\fP
728 .RS 4
729 0 Success. 
733 .SS "gpg_error_t pwmd_inquire (\fBpwm_t\fP * pwm, const char * cmd, \fBpwmd_inquire_cb_t\fP func, void * user)"
735 Send data to a pwmd server. 
737 This lets commands that use an INQUIRE (STORE and IMPORT) send the data to the server. Use this function rather than \fBpwmd_command()\fP for these commands.
739 \fBParameters:\fP
740 .RS 4
741 \fIpwm\fP A handle. 
743 \fIcmd\fP The command to send that uses an INQUIRE. 
745 \fIfunc\fP A callback function which sets the data to be sent. 
747 \fIuser\fP A user data pointer passed to the callback function \fIfunc\fP. 
750 \fBReturns:\fP
751 .RS 4
752 0 on success or an error code.
755 \fBSee also:\fP
756 .RS 4
757 \fBpwmd_inquire_cb_t\fP 
761 .SS "void* pwmd_malloc (size_t size)"
763 A wrapper around malloc. 
765 Like malloc(), but lets libpwmd keep track of the pointer.
767 \fBParameters:\fP
768 .RS 4
769 \fIsize\fP The number of bytes to allocate. 
772 \fBReturns:\fP
773 .RS 4
774 A newly allocated pointer or NULL if there wasn't enough memory. 
777 \fBSee also:\fP
778 .RS 4
779 malloc(3), \fBpwmd_free()\fP 
783 .SS "\fBpwm_t\fP* pwmd_new (const char * name)"
785 Creates a new handle. 
787 Creates a new handle for use with the other functions.
789 \fBParameters:\fP
790 .RS 4
791 \fIname\fP If not NULL, the name of the application. The application name is sent to the pwmd server after successfully connecting.
793 \fIname\fP The application name or NULL. 
796 \fBReturns:\fP
797 .RS 4
798 a new handle or NULL if there was not enough memory. 
802 .SS "gpg_error_t pwmd_open (\fBpwm_t\fP * pwm, const char * filename)"
804 Open a file on the pwmd server. 
806 This will send the OPEN command to the server.
808 \fBParameters:\fP
809 .RS 4
810 \fIpwm\fP A handle. 
812 \fIfilename\fP The filename to open. 
815 \fBReturns:\fP
816 .RS 4
817 0 on success or an error code. 
820 \fBSee also:\fP
821 .RS 4
822 \fBPinentry Details\fP 
826 .SS "gpg_error_t pwmd_open2 (\fBpwm_t\fP * pwm, const char * filename)"
828 Open a file on the pwmd server using a local pinentry. 
830 This will send the OPEN command to the server like \fBpwmd_open()\fP but will use the local pinentry and not pwmd's pinentry.
832 \fBNote:\fP
833 .RS 4
834 This function will catch SIGALRM during the lifetime of the pinentry process and set it to SIG_DFL when finished. This is needed for pinentry timeouts.
837 \fBParameters:\fP
838 .RS 4
839 \fIpwm\fP A handle. 
841 \fIfilename\fP The filename to open. 
844 \fBReturns:\fP
845 .RS 4
846 0 on success or an error code. 
849 \fBSee also:\fP
850 .RS 4
851 \fBPinentry Details\fP 
855 .SS "gpg_error_t pwmd_open_async (\fBpwm_t\fP * pwm, const char * filename)"
857 Open a file on the pwmd server asynchronously. 
859 This will send the OPEN command to the pwmd server. The difference from \fBpwmd_open()\fP is that it will not block if a pinentry is needed for passphrase input.
861 \fBpwmd_process()\fP should be called until the command completes.
863 \fBParameters:\fP
864 .RS 4
865 \fIpwm\fP A handle. 
867 \fIfilename\fP The filename to open. 
870 \fBReturns:\fP
871 .RS 4
872 0 on success or an error code. 
875 \fBSee also:\fP
876 .RS 4
877 \fBpwmd_process()\fP, \fBPinentry Details\fP 
881 .SS "gpg_error_t pwmd_open_async2 (\fBpwm_t\fP * pwm, const char * filename)"
883 Open a file on the pwmd server asynchronously (fork method). 
885 This will send the OPEN command to the pwmd server. The difference from \fBpwmd_open()\fP is that it will not block if a pinentry is needed for passphrase input.
887 The difference from \fBpwmd_open_async()\fP is that libpwmd will \fBfork()\fP a pinentry process rather than have pwmd use it's pinentry method. This may be useful if the passphrase isn't cached on a remote pwmd server and a remote \fBpinentry(1)\fP is not possible.
889 \fBpwmd_process()\fP should be called until the command completes.
891 \fBNote:\fP
892 .RS 4
893 This function will catch SIGALRM during the lifetime of the pinentry process and set it to SIG_DFL when finished. This is needed for pinentry timeouts.
896 \fBParameters:\fP
897 .RS 4
898 \fIpwm\fP A handle. 
900 \fIfilename\fP The filename to open. 
903 \fBReturns:\fP
904 .RS 4
905 0 on success or an error code. 
908 \fBSee also:\fP
909 .RS 4
910 \fBpwmd_process()\fP, \fBPinentry Details\fP 
914 .SS "gpg_error_t pwmd_pending_line (\fBpwm_t\fP * pwm)"
916 Check for a unparsed buffered line. 
918 A buffered line is a line that was read from the server but was not processed. This function determines if there is such a line.
920 \fBParameters:\fP
921 .RS 4
922 \fIpwm\fP A handle. 
925 \fBReturn values:\fP
926 .RS 4
927 \fI0\fP if there is pending data. 
929 \fIGPG_ERR_NO_DATA\fP if there is no pending data. 
932 \fBSee also:\fP
933 .RS 4
934 \fBpwmd_process()\fP 
938 .SS "\fBpwmd_async_t\fP pwmd_process (\fBpwm_t\fP * pwm, gpg_error_t * rc, char ** result)"
940 Process an asynchronous function. 
942 After an asynchronous function has been called and has returned successfully, this function must be called to process the command to retrieve the result or return value.
944 This function may also be called when not in a command to check for pending status messages sent from the server or to process a pending line.
946 \fBParameters:\fP
947 .RS 4
948 \fIpwm\fP A handle. 
950 \fIrc\fP Set to the return code of the command after ASYNC_DONE is returned. This value must be checked to determine if the command succeeded. 
952 \fIresult\fP Set to the result of the command when \fIrc\fP is 0. Note that not all commands return a result. 
955 \fBReturn values:\fP
956 .RS 4
957 \fIASYNC_DONE\fP The command has completed. \fIrc\fP should be checked to determine if the command was successful or not. 
959 \fIASYNC_PROCESS\fP The command is still running and this function should be called again. 
962 \fBSee also:\fP
963 .RS 4
964 \fBpwmd_get_fds()\fP, \fBpwmd_pending_line()\fP 
968 .SS "void* pwmd_realloc (void * ptr, size_t size)"
970 A wrapper around realloc(). 
972 Like realloc(), but lets libpwmd keep track of the pointer. Note that this function will try and allocate the entire \fIsize\fP before freeing the original pointer and returning the new one.
974 \fBParameters:\fP
975 .RS 4
976 \fIptr\fP The pointer to reallocate. 
978 \fIsize\fP The new number of bytes to allocate. 
981 \fBReturns:\fP
982 .RS 4
983 A newly allocated pointer or NULL if there wasn't enough memory. 
986 \fBSee also:\fP
987 .RS 4
988 realloc(3), \fBpwmd_free()\fP 
992 .SS "gpg_error_t pwmd_save (\fBpwm_t\fP * pwm)"
994 Save a file on the pwmd server. 
996 This will send the SAVE command.
998 \fBParameters:\fP
999 .RS 4
1000 \fIpwm\fP A handle. 
1003 \fBReturns:\fP
1004 .RS 4
1005 0 on success or an error code. 
1008 \fBSee also:\fP
1009 .RS 4
1010 \fBPinentry Details\fP 
1014 .SS "gpg_error_t pwmd_save2 (\fBpwm_t\fP * pwm)"
1016 Save a file on the pwmd server using the local pinentry. 
1018 This will send the SAVE command like \fBpwmd_save()\fP but will use a local pinentry and not pwmd's pinentry.
1020 \fBParameters:\fP
1021 .RS 4
1022 \fIpwm\fP A handle. 
1025 \fBReturns:\fP
1026 .RS 4
1027 0 on success or an error code. 
1030 \fBSee also:\fP
1031 .RS 4
1032 \fBPinentry Details\fP 
1036 .SS "gpg_error_t pwmd_save_async (\fBpwm_t\fP * pwm)"
1038 Save changes to a file on the pwmd server asynchronously. 
1040 This will send the SAVE command to the pwmd server. The difference from \fBpwmd_save()\fP is that it will not block if a pinentry is needed for passphrase input.
1042 \fBpwmd_process()\fP should be called until the command completes.
1044 \fBParameters:\fP
1045 .RS 4
1046 \fIpwm\fP A handle. 
1049 \fBReturns:\fP
1050 .RS 4
1051 0 on success or an error code. 
1054 \fBSee also:\fP
1055 .RS 4
1056 \fBpwmd_process()\fP, \fBPinentry Details\fP 
1060 .SS "gpg_error_t pwmd_save_async2 (\fBpwm_t\fP * pwm)"
1062 Save a file on the pwmd server asynchronously (fork method). 
1064 This will send the SAVE command to the pwmd server. The difference from \fBpwmd_save()\fP is that it will not block if a pinentry is needed for passphrase input.
1066 The difference from \fBpwmd_save_async()\fP is that libpwmd will \fBfork()\fP a pinentry process rather than have pwmd use it's pinentry method. This may be useful if the passphrase isn't cached on a remote pwmd server and a remote \fBpinentry(1)\fP is not possible.
1068 \fBpwmd_process()\fP should be called until the command completes.
1070 \fBParameters:\fP
1071 .RS 4
1072 \fIpwm\fP A handle. 
1075 \fBReturns:\fP
1076 .RS 4
1077 0 on success or an error code. 
1080 \fBSee also:\fP
1081 .RS 4
1082 \fBpwmd_process()\fP, \fBPinentry Details\fP 
1086 .SS "gpg_error_t pwmd_setopt (\fBpwm_t\fP * pwm, \fBpwmd_option_t\fP opt,  ...)"
1088 Set library options. 
1090 See \fBpwmd_option_t\fP for option specific details.
1092 \fBParameters:\fP
1093 .RS 4
1094 \fIpwm\fP A handle. 
1096 \fIopt\fP The option. 
1098 \fI...\fP The option value. 
1101 \fBReturns:\fP
1102 .RS 4
1103 0 on success or an error code. 
1107 .SS "gpg_error_t pwmd_ssh_connect (\fBpwm_t\fP * pwm, const char * host, int port, const char * identity, const char * user, const char * known_hosts)"
1109 Establish a remote connection to a pwmd server. 
1111 Connects to a pwmd server over an SSH channel.
1113 \fBParameters:\fP
1114 .RS 4
1115 \fIpwm\fP A handle. 
1117 \fIhost\fP The hostname to connect to. 
1119 \fIport\fP The port or -1 for the default. 
1121 \fIidentity\fP The SSH identity file to use for authentication. This should specify the private key. The public key is assumed to be \fIidentity.pub\fP. 
1123 \fIuser\fP The username on the SSH server to login as. If NULL then invoking user will be used. 
1125 \fIknown_hosts\fP A file containing the public SSH server key hash in SHA1 format. 
1128 \fBReturns:\fP
1129 .RS 4
1130 0 on success or an error code. 
1133 \fBSee also:\fP
1134 .RS 4
1135 \fBpwmd_ssh_connect_async()\fP, \fBpwmd_process()\fP, \fBSSH Details\fP 
1139 .SS "gpg_error_t pwmd_ssh_connect_async (\fBpwm_t\fP * pwm, const char * host, int port, const char * identity, const char * user, const char * known_hosts)"
1141 Establish a remote connection to a pwmd server asynchronously. 
1143 This is a variant of \fBpwmd_ssh_connect()\fP that will not block while doing DNS lookups or while connecting.
1145 \fBpwmd_process()\fP should be called until the command completes.
1147 \fBParameters:\fP
1148 .RS 4
1149 \fIpwm\fP A handle. 
1151 \fIhost\fP The hostname to connect to. 
1153 \fIport\fP The port or -1 for the default. 
1155 \fIidentity\fP The SSH identity file to use for authentication. This should specify the private key. The public key is assumed to be \fIidentity.pub\fP. 
1157 \fIuser\fP The username on the SSH server to login as. If NULL, the invoking username will be used. 
1159 \fIknown_hosts\fP A file containing the public SSH server key hash in SHA1 format. 
1162 \fBReturns:\fP
1163 .RS 4
1164 0 on success or an error code. 
1167 \fBSee also:\fP
1168 .RS 4
1169 \fBpwmd_process()\fP, \fBSSH Details\fP 
1173 .SS "char* pwmd_strdup (const char * str)"
1175 A wrapper around strdup(). 
1177 Like strdup(), but lets libpwmd keep track of the pointer.
1179 \fBParameters:\fP
1180 .RS 4
1181 \fIstr\fP The string to duplicate. 
1184 \fBReturns:\fP
1185 .RS 4
1186 A newly allocated character pointer or NULL if there wasn't enough memory. 
1189 \fBSee also:\fP
1190 .RS 4
1191 strdup(3), \fBpwmd_free()\fP 
1195 .SS "char* pwmd_strdup_printf (const char * fmt,  ...)"
1197 Duplicate a formatted string. 
1199 Like sprintf() but returns an allocated string.
1201 \fBParameters:\fP
1202 .RS 4
1203 \fIfmt\fP The formatted string. 
1205 \fI...\fP Any format arguments to the string. 
1208 \fBReturns:\fP
1209 .RS 4
1210 A newly allocated character pointer or NULL if there wasn't enough memory. 
1213 \fBSee also:\fP
1214 .RS 4
1215 \fBpwmd_free()\fP 
1219 .SS "const char* pwmd_strerror (gpg_error_t code)"
1221 Return a description of an error code. 
1223 \fBParameters:\fP
1224 .RS 4
1225 \fIcode\fP The error code to describe. 
1228 \fBReturns:\fP
1229 .RS 4
1230 A character description of the error code. 
1233 \fBSee also:\fP
1234 .RS 4
1235 \fBpwmd_strerror_r()\fP 
1239 .SS "int pwmd_strerror_r (gpg_error_t code, char * buf, size_t size)"
1241 Return a description of an error code (thread-safe). 
1243 This is a thread-safe version of \fBpwmd_strerror()\fP.
1245 \fBParameters:\fP
1246 .RS 4
1247 \fIcode\fP The error code to describe. 
1249 \fIbuf\fP An allocated buffer to hold the error description. 
1251 \fIsize\fP The size of the allocated buffer \fIbuf\fP.
1254 \fBReturn values:\fP
1255 .RS 4
1256 \fI0\fP Success. 
1258 \fIERANGE\fP \fIsize\fP was not large enough to hold the entire description and \fIbuf\fP is set to the truncated error string. 
1262 .SH "Author"
1263 .PP 
1264 Generated automatically by Doxygen for libpwmd from the source code.