summaryrefslogtreecommitdiffstats
path: root/assuan
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-02-18 21:45:52 +0100
committerWerner Koch <wk@gnupg.org>2002-02-18 21:45:52 +0100
commita46e786221dc2c08960acdfd94cab35729f0891d (patch)
treee50198672b8181aae4fb9f56be5283c91ab8e1f8 /assuan
parent* command.c (cmd_marktrusted): Implemented. (diff)
downloadgnupg2-a46e786221dc2c08960acdfd94cab35729f0891d.tar.xz
gnupg2-a46e786221dc2c08960acdfd94cab35729f0891d.zip
A bunch of new features. Allow empty responses on an inquiry.
Diffstat (limited to 'assuan')
-rw-r--r--assuan/ChangeLog13
-rw-r--r--assuan/assuan-defs.h10
-rw-r--r--assuan/assuan-inquire.c38
-rw-r--r--assuan/assuan-pipe-server.c1
-rw-r--r--assuan/assuan-socket-server.c11
-rw-r--r--assuan/assuan.h7
6 files changed, 62 insertions, 18 deletions
diff --git a/assuan/ChangeLog b/assuan/ChangeLog
index f9c755529..a46f55421 100644
--- a/assuan/ChangeLog
+++ b/assuan/ChangeLog
@@ -1,3 +1,16 @@
+2002-02-14 Werner Koch <wk@gnupg.org>
+
+ * assuan-inquire.c (assuan_inquire): Check for a cancel command
+ and return ASSUAN_Canceled. Allow for non-data inquiry.
+
+ * assuan.h: Add a few token specific error codes.
+
+2002-02-13 Werner Koch <wk@gnupg.org>
+
+ * assuan-defs.h (assuan_context_s): New var CLIENT_PID.
+ * assuan-pipe-server.c (_assuan_new_context): set default value.
+ * assuan-socket-server.c (accept_connection): get the actual pid.
+
2002-02-12 Werner Koch <wk@gnupg.org>
* assuan-buffer.c (writen,readline) [USE_GNU_PT]: Use pth_read/write.
diff --git a/assuan/assuan-defs.h b/assuan/assuan-defs.h
index 7d55aabd9..6c502bf9c 100644
--- a/assuan/assuan-defs.h
+++ b/assuan/assuan-defs.h
@@ -77,6 +77,9 @@ struct assuan_context_s {
In socket mode, the pid of the server */
int listen_fd; /* The fd we are listening on (used by socket servers) */
+ pid_t client_pid; /* for a socket server the PID of the client or -1
+ if not available */
+
void (*deinit_handler)(ASSUAN_CONTEXT);
int (*accept_handler)(ASSUAN_CONTEXT);
int (*finish_handler)(ASSUAN_CONTEXT);
@@ -92,7 +95,6 @@ struct assuan_context_s {
void (*input_notify_fnc)(ASSUAN_CONTEXT, const char *);
void (*output_notify_fnc)(ASSUAN_CONTEXT, const char *);
-
int input_fd; /* set by INPUT command */
int output_fd; /* set by OUTPUT command */
@@ -135,9 +137,3 @@ void _assuan_log_sanitized_string (const char *string);
#endif /*ASSUAN_DEFS_H*/
-
-
-
-
-
-
diff --git a/assuan/assuan-inquire.c b/assuan/assuan-inquire.c
index 933091e15..2bac13030 100644
--- a/assuan/assuan-inquire.c
+++ b/assuan/assuan-inquire.c
@@ -126,9 +126,10 @@ free_membuf (struct membuf *mb)
* @keyword: The keyword used for the inquire
* @r_buffer: Returns an allocated buffer
* @r_length: Returns the length of this buffer
- * @maxlen: If no 0, the size limit of the inquired data.
+ * @maxlen: If not 0, the size limit of the inquired data.
*
- * A Server may use this to Send an inquire
+ * A Server may use this to Send an inquire. r_buffer, r_length and
+ * maxlen may all be NULL/0 to indicate that no real data is expected.
*
* Return value: 0 on success or an ASSUAN error code
**/
@@ -141,9 +142,12 @@ assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword,
char cmdbuf[100];
unsigned char *line, *p;
int linelen;
+ int nodataexpected;
- if (!ctx || !keyword || (10 + strlen (keyword) >= sizeof (cmdbuf))
- || !r_buffer || !r_length )
+ if (!ctx || !keyword || (10 + strlen (keyword) >= sizeof (cmdbuf)))
+ return ASSUAN_Invalid_Value;
+ nodataexpected = !r_buffer && !r_length && !maxlen;
+ if (!nodataexpected && (!r_buffer || !r_length))
return ASSUAN_Invalid_Value;
if (!ctx->is_server)
return ASSUAN_Not_A_Server;
@@ -151,7 +155,10 @@ assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword,
return ASSUAN_Nested_Commands;
ctx->in_inquire = 1;
- init_membuf (&mb, maxlen? maxlen:1024, maxlen);
+ if (nodataexpected)
+ memset (&mb, 0, sizeof mb); /* avoid compiler warnings */
+ else
+ init_membuf (&mb, maxlen? maxlen:1024, maxlen);
strcpy (stpcpy (cmdbuf, "INQUIRE "), keyword);
rc = assuan_write_line (ctx, cmdbuf);
@@ -172,7 +179,12 @@ assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword,
if (line[0] == 'E' && line[1] == 'N' && line[2] == 'D'
&& (!line[3] || line[3] == ' '))
break; /* END command received*/
- if (line[0] != 'D' || line[1] != ' ')
+ if (line[0] == 'C' && line[1] == 'A' && line[2] == 'N')
+ {
+ rc = ASSUAN_Canceled;
+ goto leave;
+ }
+ if (line[0] != 'D' || line[1] != ' ' || nodataexpected)
{
rc = ASSUAN_Unexpected_Command;
goto leave;
@@ -205,13 +217,17 @@ assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword,
goto leave;
}
}
-
- *r_buffer = get_membuf (&mb, r_length);
- if (!*r_buffer)
- rc = ASSUAN_Out_Of_Core;
+
+ if (!nodataexpected)
+ {
+ *r_buffer = get_membuf (&mb, r_length);
+ if (!*r_buffer)
+ rc = ASSUAN_Out_Of_Core;
+ }
leave:
- free_membuf (&mb);
+ if (!nodataexpected)
+ free_membuf (&mb);
ctx->in_inquire = 0;
return rc;
}
diff --git a/assuan/assuan-pipe-server.c b/assuan/assuan-pipe-server.c
index d15f54f5a..5c5d1248c 100644
--- a/assuan/assuan-pipe-server.c
+++ b/assuan/assuan-pipe-server.c
@@ -64,6 +64,7 @@ _assuan_new_context (ASSUAN_CONTEXT *r_ctx)
ctx->outbound.fd = -1;
ctx->listen_fd = -1;
+ ctx->client_pid = (pid_t)-1;
/* use the pipe server handler as a default */
ctx->deinit_handler = deinit_pipe_server;
ctx->accept_handler = accept_connection;
diff --git a/assuan/assuan-socket-server.c b/assuan/assuan-socket-server.c
index d10d9d4a9..39dd84a13 100644
--- a/assuan/assuan-socket-server.c
+++ b/assuan/assuan-socket-server.c
@@ -38,6 +38,7 @@ accept_connection (ASSUAN_CONTEXT ctx)
struct sockaddr_un clnt_addr;
size_t len = sizeof clnt_addr;
+ ctx->client_pid = (pid_t)-1;
#ifdef USE_GNU_PTH
fd = pth_accept (ctx->listen_fd, (struct sockaddr*)&clnt_addr, &len );
#else
@@ -49,6 +50,16 @@ accept_connection (ASSUAN_CONTEXT ctx)
return ASSUAN_Accept_Failed;
}
+#ifdef HAVE_SO_PEERCRED
+ {
+ struct ucred cr;
+ int cl = sizeof cr;
+
+ if ( !getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) )
+ ctx->client_pid = cr.pid;
+ }
+#endif
+
ctx->inbound.fd = fd;
ctx->inbound.eof = 0;
ctx->inbound.linelen = 0;
diff --git a/assuan/assuan.h b/assuan/assuan.h
index 5971d81b8..fed4e3468 100644
--- a/assuan/assuan.h
+++ b/assuan/assuan.h
@@ -74,6 +74,8 @@ typedef enum {
ASSUAN_Inquire_Error = 121,
ASSUAN_Invalid_Option = 122,
+ ASSUAN_Not_Confirmed = 128,
+
ASSUAN_Bad_Certificate = 201,
ASSUAN_Bad_Certificate_Path = 202,
ASSUAN_Missing_Certificate = 203,
@@ -89,6 +91,11 @@ typedef enum {
ASSUAN_CRL_Too_Old = 303,
ASSUAN_Not_Trusted = 304,
+ ASSUAN_Card_Error = 401,
+ ASSUAN_Invalid_Card = 402,
+ ASSUAN_No_PKCS15_App = 403,
+ ASSUAN_Card_Not_Present = 404
+
} AssuanError;
/* This is a list of pre-registered ASSUAN commands */