Added support for a passphrase in the url string.
[libpwmd.git] / doc / libpwmd.3
blob48e6c9fe715e7376ea470d151f7e795f62a1a5da
1 .TH "libpwmd.h" 3 "9 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_connect_url\fP (\fBpwm_t\fP *pwm, const char *url)"
186 .ti -1c
187 .RI "gpg_error_t \fBpwmd_connect_url_async\fP (\fBpwm_t\fP *pwm, const char *url)"
189 .ti -1c
190 .RI "gpg_error_t \fBpwmd_get_hostkey\fP (\fBpwm_t\fP *pwm, const char *host, int port, char **result)"
192 .ti -1c
193 .RI "gpg_error_t \fBpwmd_get_hostkey_async\fP (\fBpwm_t\fP *pwm, const char *host, int port)"
195 .ti -1c
196 .RI "gpg_error_t \fBpwmd_get_fds\fP (\fBpwm_t\fP *pwm, pwmd_fd_t *fds, int *n_fds)"
198 .ti -1c
199 .RI "gpg_error_t \fBpwmd_pending_line\fP (\fBpwm_t\fP *pwm)"
201 .ti -1c
202 .RI "gpg_error_t \fBpwmd_setopt\fP (\fBpwm_t\fP *pwm, \fBpwmd_option_t\fP opt,...)"
204 .ti -1c
205 .RI "gpg_error_t \fBpwmd_open\fP (\fBpwm_t\fP *pwm, const char *filename)"
207 .ti -1c
208 .RI "gpg_error_t \fBpwmd_open2\fP (\fBpwm_t\fP *pwm, const char *filename)"
210 .ti -1c
211 .RI "gpg_error_t \fBpwmd_open_async2\fP (\fBpwm_t\fP *pwm, const char *filename)"
213 .ti -1c
214 .RI "gpg_error_t \fBpwmd_open_async\fP (\fBpwm_t\fP *pwm, const char *filename)"
216 .ti -1c
217 .RI "\fBpwmd_async_t\fP \fBpwmd_process\fP (\fBpwm_t\fP *pwm, gpg_error_t *rc, char **result)"
219 .ti -1c
220 .RI "gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm)"
222 .ti -1c
223 .RI "gpg_error_t \fBpwmd_save2\fP (\fBpwm_t\fP *pwm)"
225 .ti -1c
226 .RI "gpg_error_t \fBpwmd_save_async2\fP (\fBpwm_t\fP *pwm)"
228 .ti -1c
229 .RI "gpg_error_t \fBpwmd_save_async\fP (\fBpwm_t\fP *pwm)"
231 .ti -1c
232 .RI "gpg_error_t \fBpwmd_command\fP (\fBpwm_t\fP *pwm, char **result, const char *cmd,...)"
234 .ti -1c
235 .RI "gpg_error_t \fBpwmd_command_ap\fP (\fBpwm_t\fP *pwm, char **result, const char *cmd, va_list ap)"
237 .ti -1c
238 .RI "gpg_error_t \fBpwmd_inquire\fP (\fBpwm_t\fP *pwm, const char *cmd, \fBpwmd_inquire_cb_t\fP func, void *user)"
240 .ti -1c
241 .RI "void \fBpwmd_close\fP (\fBpwm_t\fP *pwm)"
243 .ti -1c
244 .RI "void \fBpwmd_free\fP (void *ptr)"
246 .ti -1c
247 .RI "void * \fBpwmd_malloc\fP (size_t size)"
249 .ti -1c
250 .RI "void * \fBpwmd_calloc\fP (size_t nmemb, size_t size)"
252 .ti -1c
253 .RI "void * \fBpwmd_realloc\fP (void *ptr, size_t size)"
255 .ti -1c
256 .RI "char * \fBpwmd_strdup\fP (const char *str)"
258 .ti -1c
259 .RI "char * \fBpwmd_strdup_printf\fP (const char *fmt,...)"
261 .ti -1c
262 .RI "const char * \fBpwmd_strerror\fP (gpg_error_t code)"
264 .ti -1c
265 .RI "int \fBpwmd_strerror_r\fP (gpg_error_t code, char *buf, size_t size)"
267 .in -1c
268 .SH "Define Documentation"
269 .PP 
270 .SS "#define EPWMD_ERROR"
272 A general pwmd error with no suitable description. 
273 .SS "#define EPWMD_FILE_MODIFIED"
275 The data file was modified either externally or by another another client while trying to process a command. 
276 .SS "#define EPWMD_LIBXML_ERROR"
278 An XML parse or other libxml2 error occurred. 
279 .SS "#define EPWMD_LOOP"
281 A recursion loop was detected while processing a 'target' attribute. 
282 .SS "#define EPWMD_MAX_SLOTS"
284 The maximum number of cache slots has been reached. There is no available slot for a new file. 
285 .SS "#define EPWMD_NO_FILE"
287 A command required an open file, but no file has yet been opened. 
288 .SS "#define LIBPWMD_VERSION"
290 The version of this library. 
291 .SS "#define PWMD_FD_READABLE"
293 Set when the file descriptor is readable. 
294 .SS "#define PWMD_FD_WRITABLE"
296 Set when the file descriptor is writable. 
297 .SH "Typedef Documentation"
298 .PP 
299 .SS "\fBpwm_t\fP"
301 When a handle is mentioned in this documentation it is a pointer of this type. A new handle is created with \fBpwmd_new()\fP. 
302 .SS "\fBpwmd_inquire_cb_t\fP"
304 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.
306 \fBParameters:\fP
307 .RS 4
308 \fIuser\fP The user data pointer passed to \fBpwmd_inquire()\fP. 
310 \fIcmd\fP The same as the \fIcmd\fP argument to \fBpwmd_inquire()\fP. 
312 \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. 
314 \fIdata\fP The next chunk of data to send or NULL. 
316 \fIlen\fP The length of \fIdata\fP or 0.
319 \fBReturn values:\fP
320 .RS 4
321 \fI0\fP There is more data to be sent. 
323 \fIGPG_ERR_EOF\fP No need to call this function again, the current \fIline\fP is the last to send. 
325 \fIcode\fP Any other error code which will terminate the INQUIRE.
328 \fBNote:\fP
329 .RS 4
330 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. 
334 .SS "\fBpwmd_passphrase_cb_t\fP"
336 The value of the option \fBPWMD_OPTION_PASSPHRASE_CB\fP which is set with \fBpwmd_setopt()\fP.
338 \fBParameters:\fP
339 .RS 4
340 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_PASSPHRASE_DATA\fP. 
342 \fIpassphrase\fP The passphrase which may be an empty string or NULL. 
345 \fBReturns:\fP
346 .RS 4
347 0 on success or an error code which will cause a command to fail. 
351 .SS "\fBpwmd_status_cb_t\fP"
353 The value of the option \fBPWMD_OPTION_STATUS_CB\fP which is set with \fBpwmd_setopt()\fP.
355 \fBParameters:\fP
356 .RS 4
357 \fIuser\fP A user data pointer which is set with \fBPWMD_OPTION_STATUS_DATA\fP. 
359 \fIline\fP The status message line. 
362 \fBReturns:\fP
363 .RS 4
364 0 on success or an error code which will cause a command to fail. 
368 .SH "Enumeration Type Documentation"
369 .PP 
370 .SS "enum \fBpwmd_async_t\fP"
372 The return code of \fBpwmd_process()\fP which is used for all asynchronous commands. 
374 \fBEnumerator: \fP
375 .in +1c
377 \fB\fIASYNC_INIT \fP\fP
379 \fBFor internal use only.\fP
380 .RS 4
385 \fB\fIASYNC_PROCESS \fP\fP
386 \fBpwmd_process()\fP should be called again. 
388 \fB\fIASYNC_DONE \fP\fP
389 The command has completed. The result code should be checked for an error. 
390 .SS "enum \fBpwmd_ip_version_t\fP"
392 The value of the option \fBPWMD_OPTION_IP_VERSION\fP which is set with \fBpwmd_setopt()\fP. 
394 \fBEnumerator: \fP
395 .in +1c
397 \fB\fIPWMD_IP_ANY \fP\fP
398 Try both IPv6 and IPv4 addresses. Note that IPv6 is tried first. 
400 \fB\fIPWMD_IPV4 \fP\fP
401 Only try IPv4. 
403 \fB\fIPWMD_IPV6 \fP\fP
404 Only try IPv6. 
405 .SS "enum \fBpwmd_option_t\fP"
407 libpwmd options which are set with \fBpwmd_setopt()\fP. 
409 \fBEnumerator: \fP
410 .in +1c
412 \fB\fIPWMD_OPTION_PASSPHRASE_CB \fP\fP
413 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. 
415 \fB\fIPWMD_OPTION_PASSPHRASE_DATA \fP\fP
416 User supplied data which is passed to the custom password function. 
418 \fB\fIPWMD_OPTION_PASSPHRASE \fP\fP
419 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. 
421 \fB\fIPWMD_OPTION_PINENTRY_TRIES \fP\fP
422 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.
424 \fBNote:\fP
425 .RS 4
426 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. 
431 \fB\fIPWMD_OPTION_PINENTRY_PATH \fP\fP
432 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.
434 \fBSee also:\fP
435 .RS 4
436 \fBPinentry Details\fP 
441 \fB\fIPWMD_OPTION_PINENTRY_TTY \fP\fP
442 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.
444 \fBSee also:\fP
445 .RS 4
446 \fBPinentry Details\fP 
451 \fB\fIPWMD_OPTION_PINENTRY_TERM \fP\fP
452 A value which specifies the terminal type (e.g., vt100) that \fBpinentry(1)\fP will use when no X11 display is available.
454 \fBSee also:\fP
455 .RS 4
456 \fBPinentry Details\fP 
461 \fB\fIPWMD_OPTION_PINENTRY_DISPLAY \fP\fP
462 A value which specifies the X11 display that \fBpinentry(1)\fP will use.
464 \fBSee also:\fP
465 .RS 4
466 \fBPinentry Details\fP 
471 \fB\fIPWMD_OPTION_PINENTRY_TITLE \fP\fP
472 A character string that \fBpinentry(1)\fP will use in it's dialog window. 
474 \fB\fIPWMD_OPTION_PINENTRY_PROMPT \fP\fP
475 A character string that \fBpinentry(1)\fP will use in it's dialog window.  
477 \fB\fIPWMD_OPTION_PINENTRY_DESC \fP\fP
478 A character string that \fBpinentry(1)\fP will use in it's dialog window.  
480 \fB\fIPWMD_OPTION_PINENTRY_LC_CTYPE \fP\fP
481 For \fBpinentry(1)\fP localization. 
483 \fB\fIPWMD_OPTION_PINENTRY_LC_MESSAGES \fP\fP
484 For \fBpinentry(1)\fP localization.  
486 \fB\fIPWMD_OPTION_PINENTRY_TIMEOUT \fP\fP
487 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. 
489 \fB\fIPWMD_OPTION_STATUS_CB \fP\fP
490 A function pointer of type \fBpwmd_status_cb_t\fP that will process status messages received from the pwmd server. 
492 \fB\fIPWMD_OPTION_STATUS_DATA \fP\fP
493 A user data pointer which is passed to the status message function. 
495 \fB\fIPWMD_OPTION_IP_VERSION \fP\fP
496 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.
498 \fBNote:\fP
499 .RS 4
500 This option must be set before a connection is made when not the default. 
504 .SH "Function Documentation"
505 .PP 
506 .SS "void* pwmd_calloc (size_t nmemb, size_t size)"
508 A wrapper around calloc(). 
510 Like calloc(), but lets libpwmd keep track of the pointer.
512 \fBParameters:\fP
513 .RS 4
514 \fInmemb\fP The number of bytes to allocate. 
516 \fIsize\fP The number of bytes to allocate. 
519 \fBReturns:\fP
520 .RS 4
521 A newly allocated pointer or NULL if there wasn't enough memory. 
524 \fBSee also:\fP
525 .RS 4
526 calloc(3), \fBpwmd_free()\fP 
530 .SS "void pwmd_close (\fBpwm_t\fP * pwm)"
532 Close a handle. 
534 This will close the connection to a pwmd server and free any resources associated with it.
536 \fBParameters:\fP
537 .RS 4
538 \fIpwm\fP A handle. 
541 \fBReturns:\fP
542 .RS 4
543 Nothing. 
547 .SS "gpg_error_t pwmd_command (\fBpwm_t\fP * pwm, char ** result, const char * cmd,  ...)"
549 Send a command to the pwmd server. 
551 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.
553 \fBParameters:\fP
554 .RS 4
555 \fIpwm\fP A handle. 
557 \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. 
559 \fIcmd\fP The command to send. 
561 \fI...\fP The arguments to \fIcmd\fP. 
564 \fBReturns:\fP
565 .RS 4
566 0 on success or an error code. 
570 .SS "gpg_error_t pwmd_command_ap (\fBpwm_t\fP * pwm, char ** result, const char * cmd, va_list ap)"
572 Send a command to the pwmd server. 
574 Like \fBpwmd_command()\fP but uses an argument pointer instead.
576 \fBParameters:\fP
577 .RS 4
578 \fIpwm\fP A handle. 
580 \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. 
582 \fIcmd\fP The command to send. 
584 \fIap\fP The arguments to \fIcmd\fP. 
587 \fBReturns:\fP
588 .RS 4
589 0 on success or an error code. 
593 .SS "gpg_error_t pwmd_connect (\fBpwm_t\fP * pwm, const char * path)"
595 Connect to a local pwmd server. 
597 Connects to a local unix domain socket.
599 \fBParameters:\fP
600 .RS 4
601 \fIpwm\fP A handle. 
603 \fIpath\fP The socket path to connect to. If NULL, then a default of \fI'~/.pwmd/socket'\fP will be used. 
606 \fBReturns:\fP
607 .RS 4
608 0 on success or an error code. 
611 \fBSee also:\fP
612 .RS 4
613 \fBpwmd_ssh_connect()\fP, \fBpwmd_ssh_connect_async()\fP 
617 .SS "gpg_error_t pwmd_connect_url (\fBpwm_t\fP * pwm, const char * url)"
619 Establish a connection by parsing a URL. 
621 This allows for connecting to a pwmd server by parsing the given URL string. Whether the connection is to a remote or local server depends on the contents: 
624  socket://[path/to/local/socket]
626  or
628  ssh[46]://[username[:passphrase]@]hostname[:port],identity,known_hosts
633 The parameters in square brackets are optional and if not specified the defaults will be used.
635 \fBParameters:\fP
636 .RS 4
637 \fIpwm\fP A handle. 
639 \fIurl\fP The string to parse. 
642 \fBReturns:\fP
643 .RS 4
644 0 on success or an error code. 
648 .SS "gpg_error_t pwmd_connect_url_async (\fBpwm_t\fP * pwm, const char * url)"
650 Establish a connection asynchronously by parsing a URL. 
652 This allows for connecting to a pwmd server by parsing the given URL string. Whether the connection is to a remote or local server depends on the contents: 
655  socket://[path/to/local/socket]
657  or
659  ssh[46]://[username[:passphrase]@]hostname[:port],identity,known_hosts
664 The parameters in square brackets are optional and if not specified the defaults will be used.
666 \fBpwmd_process()\fP should be called until the command completes.
668 \fBParameters:\fP
669 .RS 4
670 \fIpwm\fP A handle. 
672 \fIurl\fP The string to parse. 
675 \fBReturns:\fP
676 .RS 4
677 0 on success or an error code. 
681 .SS "void pwmd_free (void * ptr)"
683 Free a previously allocated pointer. 
685 Use this function to free resources allocated by the other libpwmd memory functions. Do not use it to free your own allocations.
687 The difference between the standard free() and this function is that this one will zero out the contents of the pointer before freeing it.
689 \fBParameters:\fP
690 .RS 4
691 \fIptr\fP The pointer to deallocate. 
694 \fBReturns:\fP
695 .RS 4
696 Nothing. 
699 \fBSee also:\fP
700 .RS 4
701 \fBpwmd_malloc()\fP, \fBpwmd_calloc()\fP, \fBpwmd_realloc()\fP, \fBpwmd_strdup()\fP, \fBpwmd_process()\fP, \fBpwmd_command()\fP 
705 .SS "gpg_error_t pwmd_get_fds (\fBpwm_t\fP * pwm, pwmd_fd_t * fds, int * n_fds)"
707 Get the associated file descriptor(s) for a handle. 
709 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.
711 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.
713 \fBParameters:\fP
714 .RS 4
715 \fIpwm\fP A handle. 
717 \fIfds\fP Set to the file descriptor(s) of the associated handle. 
719 \fIn_fds\fP Initially the size of \fIfds\fP then updated to the number of available file descriptors which are stored in \fIfds\fP. 
722 \fBReturn values:\fP
723 .RS 4
724 \fI0\fP on success or an error code. 
726 \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. 
729 \fBSee also:\fP
730 .RS 4
731 \fBpwmd_process()\fP 
735 .SS "gpg_error_t pwmd_get_hostkey (\fBpwm_t\fP * pwm, const char * host, int port, char ** result)"
737 Retrieve a remote SSH host key. 
739 This key is needed for host verification of the remote pwmd server.
741 \fBParameters:\fP
742 .RS 4
743 \fIpwm\fP A handle. 
745 \fIhost\fP The hostname to connect to. 
747 \fIport\fP The port. 
749 \fIresult\fP The server host key which must be freed with \fBpwmd_free()\fP. 
752 \fBReturns:\fP
753 .RS 4
754 0 on success or an error code. 
757 \fBSee also:\fP
758 .RS 4
759 \fBpwmd_get_hostkey_async()\fP, \fBSSH Details\fP 
763 .SS "gpg_error_t pwmd_get_hostkey_async (\fBpwm_t\fP * pwm, const char * host, int port)"
765 Retrieve a remote SSH host key asynchronously. 
767 This key is needed for host verification of the remote pwmd server.
769 \fBpwmd_process()\fP should be called until the command completes.
771 \fBParameters:\fP
772 .RS 4
773 \fIpwm\fP A handle. 
775 \fIhost\fP The hostname to connect to. 
777 \fIport\fP The port or a default if set to -1. 
780 \fBReturns:\fP
781 .RS 4
782 0 on success or an error code. 
785 \fBSee also:\fP
786 .RS 4
787 \fBpwmd_get_hostkey()\fP, \fBpwmd_process()\fP, \fBSSH Details\fP 
791 .SS "gpg_error_t pwmd_init (void)"
793 Initialize the library. 
795 This function must be the first function called in the library before any others. It sets up internationalization among other things.
797 \fBReturns:\fP
798 .RS 4
799 0 Success. 
803 .SS "gpg_error_t pwmd_inquire (\fBpwm_t\fP * pwm, const char * cmd, \fBpwmd_inquire_cb_t\fP func, void * user)"
805 Send data to a pwmd server. 
807 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.
809 \fBParameters:\fP
810 .RS 4
811 \fIpwm\fP A handle. 
813 \fIcmd\fP The command to send that uses an INQUIRE. 
815 \fIfunc\fP A callback function which sets the data to be sent. 
817 \fIuser\fP A user data pointer passed to the callback function \fIfunc\fP. 
820 \fBReturns:\fP
821 .RS 4
822 0 on success or an error code.
825 \fBSee also:\fP
826 .RS 4
827 \fBpwmd_inquire_cb_t\fP 
831 .SS "void* pwmd_malloc (size_t size)"
833 A wrapper around malloc. 
835 Like malloc(), but lets libpwmd keep track of the pointer.
837 \fBParameters:\fP
838 .RS 4
839 \fIsize\fP The number of bytes to allocate. 
842 \fBReturns:\fP
843 .RS 4
844 A newly allocated pointer or NULL if there wasn't enough memory. 
847 \fBSee also:\fP
848 .RS 4
849 malloc(3), \fBpwmd_free()\fP 
853 .SS "\fBpwm_t\fP* pwmd_new (const char * name)"
855 Creates a new handle. 
857 Creates a new handle for use with the other functions.
859 \fBParameters:\fP
860 .RS 4
861 \fIname\fP If not NULL, the name of the application. The application name is sent to the pwmd server after successfully connecting.
863 \fIname\fP The application name or NULL. 
866 \fBReturns:\fP
867 .RS 4
868 a new handle or NULL if there was not enough memory. 
872 .SS "gpg_error_t pwmd_open (\fBpwm_t\fP * pwm, const char * filename)"
874 Open a file on the pwmd server. 
876 This will send the OPEN command to the server.
878 \fBParameters:\fP
879 .RS 4
880 \fIpwm\fP A handle. 
882 \fIfilename\fP The filename to open. 
885 \fBReturns:\fP
886 .RS 4
887 0 on success or an error code. 
890 \fBSee also:\fP
891 .RS 4
892 \fBPinentry Details\fP 
896 .SS "gpg_error_t pwmd_open2 (\fBpwm_t\fP * pwm, const char * filename)"
898 Open a file on the pwmd server using a local pinentry. 
900 This will send the OPEN command to the server like \fBpwmd_open()\fP but will use the local pinentry and not pwmd's pinentry.
902 \fBNote:\fP
903 .RS 4
904 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.
907 \fBParameters:\fP
908 .RS 4
909 \fIpwm\fP A handle. 
911 \fIfilename\fP The filename to open. 
914 \fBReturns:\fP
915 .RS 4
916 0 on success or an error code. 
919 \fBSee also:\fP
920 .RS 4
921 \fBPinentry Details\fP 
925 .SS "gpg_error_t pwmd_open_async (\fBpwm_t\fP * pwm, const char * filename)"
927 Open a file on the pwmd server asynchronously. 
929 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.
931 \fBpwmd_process()\fP should be called until the command completes.
933 \fBParameters:\fP
934 .RS 4
935 \fIpwm\fP A handle. 
937 \fIfilename\fP The filename to open. 
940 \fBReturns:\fP
941 .RS 4
942 0 on success or an error code. 
945 \fBSee also:\fP
946 .RS 4
947 \fBpwmd_process()\fP, \fBPinentry Details\fP 
951 .SS "gpg_error_t pwmd_open_async2 (\fBpwm_t\fP * pwm, const char * filename)"
953 Open a file on the pwmd server asynchronously (fork method). 
955 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.
957 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.
959 \fBpwmd_process()\fP should be called until the command completes.
961 \fBNote:\fP
962 .RS 4
963 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.
966 \fBParameters:\fP
967 .RS 4
968 \fIpwm\fP A handle. 
970 \fIfilename\fP The filename to open. 
973 \fBReturns:\fP
974 .RS 4
975 0 on success or an error code. 
978 \fBSee also:\fP
979 .RS 4
980 \fBpwmd_process()\fP, \fBPinentry Details\fP 
984 .SS "gpg_error_t pwmd_pending_line (\fBpwm_t\fP * pwm)"
986 Check for a unparsed buffered line. 
988 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.
990 \fBParameters:\fP
991 .RS 4
992 \fIpwm\fP A handle. 
995 \fBReturn values:\fP
996 .RS 4
997 \fI0\fP if there is pending data. 
999 \fIGPG_ERR_NO_DATA\fP if there is no pending data. 
1002 \fBSee also:\fP
1003 .RS 4
1004 \fBpwmd_process()\fP 
1008 .SS "\fBpwmd_async_t\fP pwmd_process (\fBpwm_t\fP * pwm, gpg_error_t * rc, char ** result)"
1010 Process an asynchronous function. 
1012 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.
1014 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.
1016 \fBParameters:\fP
1017 .RS 4
1018 \fIpwm\fP A handle. 
1020 \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. 
1022 \fIresult\fP Set to the result of the command when \fIrc\fP is 0. Note that not all commands return a result. 
1025 \fBReturn values:\fP
1026 .RS 4
1027 \fIASYNC_DONE\fP The command has completed. \fIrc\fP should be checked to determine if the command was successful or not. 
1029 \fIASYNC_PROCESS\fP The command is still running and this function should be called again. 
1032 \fBSee also:\fP
1033 .RS 4
1034 \fBpwmd_get_fds()\fP, \fBpwmd_pending_line()\fP 
1038 .SS "void* pwmd_realloc (void * ptr, size_t size)"
1040 A wrapper around realloc(). 
1042 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.
1044 \fBParameters:\fP
1045 .RS 4
1046 \fIptr\fP The pointer to reallocate. 
1048 \fIsize\fP The new number of bytes to allocate. 
1051 \fBReturns:\fP
1052 .RS 4
1053 A newly allocated pointer or NULL if there wasn't enough memory. 
1056 \fBSee also:\fP
1057 .RS 4
1058 realloc(3), \fBpwmd_free()\fP 
1062 .SS "gpg_error_t pwmd_save (\fBpwm_t\fP * pwm)"
1064 Save a file on the pwmd server. 
1066 This will send the SAVE command.
1068 \fBParameters:\fP
1069 .RS 4
1070 \fIpwm\fP A handle. 
1073 \fBReturns:\fP
1074 .RS 4
1075 0 on success or an error code. 
1078 \fBSee also:\fP
1079 .RS 4
1080 \fBPinentry Details\fP 
1084 .SS "gpg_error_t pwmd_save2 (\fBpwm_t\fP * pwm)"
1086 Save a file on the pwmd server using the local pinentry. 
1088 This will send the SAVE command like \fBpwmd_save()\fP but will use a local pinentry and not pwmd's pinentry.
1090 \fBParameters:\fP
1091 .RS 4
1092 \fIpwm\fP A handle. 
1095 \fBReturns:\fP
1096 .RS 4
1097 0 on success or an error code. 
1100 \fBSee also:\fP
1101 .RS 4
1102 \fBPinentry Details\fP 
1106 .SS "gpg_error_t pwmd_save_async (\fBpwm_t\fP * pwm)"
1108 Save changes to a file on the pwmd server asynchronously. 
1110 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.
1112 \fBpwmd_process()\fP should be called until the command completes.
1114 \fBParameters:\fP
1115 .RS 4
1116 \fIpwm\fP A handle. 
1119 \fBReturns:\fP
1120 .RS 4
1121 0 on success or an error code. 
1124 \fBSee also:\fP
1125 .RS 4
1126 \fBpwmd_process()\fP, \fBPinentry Details\fP 
1130 .SS "gpg_error_t pwmd_save_async2 (\fBpwm_t\fP * pwm)"
1132 Save a file on the pwmd server asynchronously (fork method). 
1134 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.
1136 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.
1138 \fBpwmd_process()\fP should be called until the command completes.
1140 \fBParameters:\fP
1141 .RS 4
1142 \fIpwm\fP A handle. 
1145 \fBReturns:\fP
1146 .RS 4
1147 0 on success or an error code. 
1150 \fBSee also:\fP
1151 .RS 4
1152 \fBpwmd_process()\fP, \fBPinentry Details\fP 
1156 .SS "gpg_error_t pwmd_setopt (\fBpwm_t\fP * pwm, \fBpwmd_option_t\fP opt,  ...)"
1158 Set library options. 
1160 See \fBpwmd_option_t\fP for option specific details.
1162 \fBParameters:\fP
1163 .RS 4
1164 \fIpwm\fP A handle. 
1166 \fIopt\fP The option. 
1168 \fI...\fP The option value. 
1171 \fBReturns:\fP
1172 .RS 4
1173 0 on success or an error code. 
1177 .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)"
1179 Establish a remote connection to a pwmd server. 
1181 Connects to a pwmd server over an SSH channel.
1183 \fBParameters:\fP
1184 .RS 4
1185 \fIpwm\fP A handle. 
1187 \fIhost\fP The hostname to connect to. 
1189 \fIport\fP The port or -1 for the default. 
1191 \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. 
1193 \fIuser\fP The username on the SSH server to login as. If NULL then invoking user will be used. 
1195 \fIknown_hosts\fP A file containing the public SSH server key hash in SHA1 format. 
1198 \fBReturns:\fP
1199 .RS 4
1200 0 on success or an error code. 
1203 \fBSee also:\fP
1204 .RS 4
1205 \fBpwmd_ssh_connect_async()\fP, \fBpwmd_process()\fP, \fBSSH Details\fP 
1209 .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)"
1211 Establish a remote connection to a pwmd server asynchronously. 
1213 This is a variant of \fBpwmd_ssh_connect()\fP that will not block while doing DNS lookups or while connecting.
1215 \fBpwmd_process()\fP should be called until the command completes.
1217 \fBParameters:\fP
1218 .RS 4
1219 \fIpwm\fP A handle. 
1221 \fIhost\fP The hostname to connect to. 
1223 \fIport\fP The port or -1 for the default. 
1225 \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. 
1227 \fIuser\fP The username on the SSH server to login as. If NULL, the invoking username will be used. 
1229 \fIknown_hosts\fP A file containing the public SSH server key hash in SHA1 format. 
1232 \fBReturns:\fP
1233 .RS 4
1234 0 on success or an error code. 
1237 \fBSee also:\fP
1238 .RS 4
1239 \fBpwmd_process()\fP, \fBSSH Details\fP 
1243 .SS "char* pwmd_strdup (const char * str)"
1245 A wrapper around strdup(). 
1247 Like strdup(), but lets libpwmd keep track of the pointer.
1249 \fBParameters:\fP
1250 .RS 4
1251 \fIstr\fP The string to duplicate. 
1254 \fBReturns:\fP
1255 .RS 4
1256 A newly allocated character pointer or NULL if there wasn't enough memory. 
1259 \fBSee also:\fP
1260 .RS 4
1261 strdup(3), \fBpwmd_free()\fP 
1265 .SS "char* pwmd_strdup_printf (const char * fmt,  ...)"
1267 Duplicate a formatted string. 
1269 Like sprintf() but returns an allocated string.
1271 \fBParameters:\fP
1272 .RS 4
1273 \fIfmt\fP The formatted string. 
1275 \fI...\fP Any format arguments to the string. 
1278 \fBReturns:\fP
1279 .RS 4
1280 A newly allocated character pointer or NULL if there wasn't enough memory. 
1283 \fBSee also:\fP
1284 .RS 4
1285 \fBpwmd_free()\fP 
1289 .SS "const char* pwmd_strerror (gpg_error_t code)"
1291 Return a description of an error code. 
1293 \fBParameters:\fP
1294 .RS 4
1295 \fIcode\fP The error code to describe. 
1298 \fBReturns:\fP
1299 .RS 4
1300 A character description of the error code. 
1303 \fBSee also:\fP
1304 .RS 4
1305 \fBpwmd_strerror_r()\fP 
1309 .SS "int pwmd_strerror_r (gpg_error_t code, char * buf, size_t size)"
1311 Return a description of an error code (thread-safe). 
1313 This is a thread-safe version of \fBpwmd_strerror()\fP.
1315 \fBParameters:\fP
1316 .RS 4
1317 \fIcode\fP The error code to describe. 
1319 \fIbuf\fP An allocated buffer to hold the error description. 
1321 \fIsize\fP The size of the allocated buffer \fIbuf\fP.
1324 \fBReturn values:\fP
1325 .RS 4
1326 \fI0\fP Success. 
1328 \fIERANGE\fP \fIsize\fP was not large enough to hold the entire description and \fIbuf\fP is set to the truncated error string. 
1332 .SH "Author"
1333 .PP 
1334 Generated automatically by Doxygen for libpwmd from the source code.