1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2006-2007 Ben Kibbey <bjk@luxsci.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 PWMD_ERROR
= -1, // file access, memory allocation and other errors
29 PWMD_PERROR
, // protocol error
30 PWMD_AGENT_ERROR
, // gpg-agent error
35 * PWMD_OPTION_USEAGENT
37 * The following argument should be of type int and set to 1 to enable
38 * the use of gpg-agent to retrieve passwords. Setting to 0 will disable
39 * using gpg-agent and the password must be set with PWMD_OPTION_PASSWORD.
44 * PWMD_OPTION_PASSWORD
46 * The following argument should be of type char* which specifies the
47 * password to use when the PWMD_OPEN or PWMD_SAVE commands are issued and
48 * PWMD_OPTION_USEAGENT is 0.
57 * The following argument is of type char* which specifies either the
58 * title, prompt or description in the pinentry program when
59 * PWMD_OPTION_USEAGENT is set.
67 * Valid protocol commands for use with pwmd_command(). The data type for the
68 * result parameter of pwmd_command() (if successful) is described below along
69 * with the argument data types for each command. See pwmd_command() for the
76 * A result of NULL if successful. The only argument is of type char*
77 * which is the filename to open. The password used to open the file is
78 * set with the PWMD_SETOPT command.
85 * Sets library and other options. See pwmd_option above for available
93 * A result of NULL if successful. Takes no arguments. The password is set
94 * using the PWMD_SETOPT command (see above).
101 * A result of char* if successful. Sends a protocol command. The next
102 * argument is of type char* and is the command and any arguments
103 * including the newline character.
110 void *ctx
; // the assuan handle
121 * Connects to the socket specified by 'socket_path'. If socket_path is NULL,
122 * then a default of ~/.pwmd/socket will be used. Returns a new handle for use
123 * with the other functions or NULL if there was an error in which case
124 * 'error' is set to the errno of the error.
126 pwm_t
*pwmd_connect(const char *socket_path
, int *error
);
129 * Closes the connection to the socket and frees the resources of the handle.
132 void pwmd_close(pwm_t
*pwm
);
135 * Sends a command 'cmd' to the daemon using handle 'pwm'. If the command
136 * fails (the return value is not PWMD_OK) and the return value is
137 * PWMD_PERROR, the result is set to NULL and error is set to a protocol error
138 * code. If the return value is PWMD_ERROR, the result is set to NULL and
139 * error is set to the errno of the error. If using gpg-agent to get the
140 * password and there is an error connecting to gpg-agent, PWMD_AGENT_ERROR is
141 * returned and error is set to EPWMD_ERROR. If successful the function
142 * returns PWMD_OK and the result is the character data of the command or NULL
145 int pwmd_command(pwm_t
*pwm
, char **result
, int *error
, pwmd_cmd cmd
, ...);
148 * Protocol error codes.
150 #define EPWMD_ERROR 0
151 #define EPWMD_INVALID_FILENAME 1
152 #define EPWMD_MAX_SLOTS 2
154 #define EPWMD_BADKEY 4
155 #define EPWMD_COMMAND_SYNTAX 5
156 #define EPWMD_ELEMENT_NOT_FOUND 6
157 #define EPWMD_TRAILING_ELEMENT 7
158 #define EPWMD_INVALID_ELEMENT 8
159 #define EPWMD_ROOT_TEXT_ELEMENT 9
160 #define EPWMD_EMPTY_ELEMENT 10
161 #define EPWMD_ATTR_SYNTAX 11
162 #define EPWMD_ACCOUNT_EXISTS 12
163 #define EPWMD_FILE_NOT_FOUND 13
164 #define EPWMD_NO_FILE 14
165 #define EPWMD_FILE_OPENED 15
166 #define EPWMD_LIBXML_ERROR 16
167 #define EPWMD_CACHE_NOT_FOUND 17
168 #define EPWMD_ATTR_NOT_FOUND 18
169 #define EPWMD_NOT_A_FILE 19
170 #define EPWMD_FILE_MODIFIED 20
174 * Return a string describing a pwmd protocol error code.
176 const char *pwmd_strerror(int pwmd_error
);