summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-02-18 20:45:52 +0000
committerWerner Koch <wk@gnupg.org>2002-02-18 20:45:52 +0000
commite60dc860417f70d14f45e973074db25552af06ec (patch)
tree39dfc04565e3f2e0793031ebc2efdd3174f4c217
parent19267c9da4a608123a0a857c63bfdaccd6afcd23 (diff)
downloadlibassuan-e60dc860417f70d14f45e973074db25552af06ec.tar.gz
A bunch of new features. Allow empty responses on an inquiry.
-rw-r--r--src/ChangeLog13
-rw-r--r--src/assuan-defs.h10
-rw-r--r--src/assuan-inquire.c38
-rw-r--r--src/assuan-pipe-server.c1
-rw-r--r--src/assuan-socket-server.c11
-rw-r--r--src/assuan.h7
6 files changed, 62 insertions, 18 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index f9c7555..a46f554 100644
--- a/src/ChangeLog
+++ b/src/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/src/assuan-defs.h b/src/assuan-defs.h
index 7d55aab..6c502bf 100644
--- a/src/assuan-defs.h
+++ b/src/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/src/assuan-inquire.c b/src/assuan-inquire.c
index 933091e..2bac130 100644
--- a/src/assuan-inquire.c
+++ b/src/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/src/assuan-pipe-server.c b/src/assuan-pipe-server.c
index d15f54f..5c5d124 100644
--- a/src/assuan-pipe-server.c
+++ b/src/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/src/assuan-socket-server.c b/src/assuan-socket-server.c
index d10d9d4..39dd84a 100644
--- a/src/assuan-socket-server.c
+++ b/src/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/src/assuan.h b/src/assuan.h
index 5971d81..fed4e34 100644
--- a/src/assuan.h
+++ b/src/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 */