Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5145)
+++ ChangeLog	(revision 5146)
@@ -9,4 +9,5 @@
 	  message to client converter code (pr0)
 	* Updated error handling (pr0)
+	* Moved error frame handling into proto functions (pr0)
 
 v. 0.4rc0 - Mon Sep 05 2011 15:25 CEST
Index: doc/man1/roard.1
===================================================================
--- doc/man1/roard.1	(revision 4860)
+++ doc/man1/roard.1	(revision 5146)
@@ -140,9 +140,10 @@
 .TP
 \fB--guest-acclev\fR
-Sets the access level for guest connections.
+Sets the access level for guest connections. Set to "none" to disable guest access.
 
 .TP
 \fB--trust-acclev\fR
 Sets the access level for clients authenticated by trust auth.
+Set to "none" to disable trust auth.
 
 .TP
Index: include/libroar/basic.h
===================================================================
--- include/libroar/basic.h	(revision 5114)
+++ include/libroar/basic.h	(revision 5146)
@@ -103,8 +103,17 @@
 int roar_recv_message (struct roar_connection * con, struct roar_message * mes, char ** data);
 int roar_req          (struct roar_connection * con, struct roar_message * mes, char ** data);
+int roar_recv_message2 (struct roar_connection * con, struct roar_message * mes, char ** data,
+                        struct roar_error_frame * errorframe);
+int roar_req2          (struct roar_connection * con, struct roar_message * mes, char ** data,
+                        struct roar_error_frame * errorframe);
+#define roar_req3(con,mes,data) roar_req2((con), (mes), (data), roar_err_errorframe())
 
 int roar_vsend_message(struct roar_vio_calls  * vio, struct roar_message * mes, char *  data);
 int roar_vrecv_message(struct roar_vio_calls  * vio, struct roar_message * mes, char ** data);
 int roar_vreq         (struct roar_vio_calls  * vio, struct roar_message * mes, char ** data);
+int roar_vrecv_message2(struct roar_vio_calls  * vio, struct roar_message * mes, char ** data,
+                        struct roar_error_frame * errorframe);
+int roar_vreq2         (struct roar_vio_calls  * vio, struct roar_message * mes, char ** data,
+                        struct roar_error_frame * errorframe);
 
 int roar_debug_message_print    (struct roar_message * mes) _LIBROAR_ATTR_DEPRECATED;
Index: include/libroar/error.h
===================================================================
--- include/libroar/error.h	(revision 5109)
+++ include/libroar/error.h	(revision 5146)
@@ -67,5 +67,10 @@
 };
 
+struct roar_error_frame * roar_err_errorframe(void);
+
 int    roar_err_int(struct roar_error_frame * frame);
+int    roar_err_init(struct roar_error_frame * frame);
+void * roar_err_buildmsg2(struct roar_message * mes, void ** data, struct roar_error_frame * frame);
+int    roar_err_parsemsg2(struct roar_message * mes, void *  data, struct roar_error_frame * frame);
 void * roar_err_buildmsg(struct roar_message * mes, struct roar_error_frame * frame);
 int    roar_err_parsemsg(struct roar_message * mes, struct roar_error_frame * frame);
Index: libroar/asyncctl.c
===================================================================
--- libroar/asyncctl.c	(revision 4708)
+++ libroar/asyncctl.c	(revision 5146)
@@ -76,5 +76,5 @@
  m.datalen = len_have;
 
- if ( roar_req(con, &m, NULL) != 0 )
+ if ( roar_req3(con, &m, NULL) != 0 )
   return -1;
 
Index: libroar/auth.c
===================================================================
--- libroar/auth.c	(revision 5144)
+++ libroar/auth.c	(revision 5146)
@@ -135,4 +135,7 @@
  char                  * data = NULL;
 
+ ROAR_DBG("roar_auth_ask_server(con=%p, authmes=%p{.type=%i}) = ?", con, authmes, authmes->type);
+
+ roar_err_init(&error_frame);
  memset(&mes, 0, sizeof(struct roar_message)); // make valgrind happy!
 
@@ -162,8 +165,13 @@
  }
 
- if ( (ret = roar_req(con, &mes, &data)) == -1 ) {
+ ROAR_DBG("roar_auth_ask_server(con=%p, authmes=%p{.type=%i}) = ?", con, authmes, authmes->type);
+
+ if ( (ret = roar_req2(con, &mes, &data, &error_frame)) == -1 ) {
   authmes->type = -1;
-  return -1;
- }
+  ROAR_DBG("roar_auth_ask_server(con=%p, authmes=%p) = -1 // next: -1", con, authmes, authmes->type);
+  return -1;
+ }
+
+ ROAR_DBG("roar_auth_ask_server(con=%p, authmes=%p{.type=%i}): mes->cmd=%i", con, authmes, authmes->type, mes.cmd);
 
  if ( data != NULL ) {
@@ -173,20 +181,16 @@
  }
 
- if ( mes.cmd != ROAR_CMD_OK ) {
-  if ( data != NULL ) {
-   // we currently do not support long error frames.
-   free(data);
-   return -1;
-  }
-
+ if ( mes.cmd == ROAR_CMD_ERROR )
   ret = -1;
-  if ( roar_err_parsemsg(&mes, &error_frame) == -1 ) {
-   authmes->type = -1;
-   return -1;
-  }
-
+
+ ROAR_DBG("roar_auth_ask_server(con=%p, authmes=%p{.type=%i}): error_frame.data=%p",
+           con, authmes, authmes->type, error_frame.data);
+
+ if ( mes.cmd == ROAR_CMD_ERROR && error_frame.data != NULL ) {
   header = error_frame.data;
   mes.datalen = error_frame.datalen;
  }
+
+ ROAR_DBG("roar_auth_ask_server(con=%p, authmes=%p{.type=%i}) = ?", con, authmes, authmes->type);
 
  if ( mes.datalen < 4 ) {
@@ -197,4 +201,6 @@
  }
 
+ ROAR_DBG("roar_auth_ask_server(con=%p, authmes=%p) = ?", con, authmes);
+
  authmes->stage         = header[1];
  authmes->reserved.c[0] = header[2];
@@ -204,4 +210,5 @@
   free(data);
 
+ ROAR_DBG("roar_auth_ask_server(con=%p, authmes=%p) = %i // next: %i", con, authmes, ret, authmes->type);
  return ret;
 }
@@ -307,4 +314,6 @@
  for (i = 0; ltt[i] != _EOL; i++) {
   next = ltt[i];
+  ROAR_DBG("roar_auth(con=%p): next from ltt: %s(%i)", con, roar_autht2str(next), next);
+
   while (next != -1) {
    done = 1;
@@ -312,4 +321,6 @@
    cur  = next;
    next = -1;
+
+   ROAR_DBG("roar_auth(con=%p): cur=%s(%i)", con, roar_autht2str(cur), cur);
 
    switch (cur) {
@@ -322,5 +333,5 @@
     case ROAR_AUTH_T_RHOST:
     case ROAR_AUTH_T_NONE:
-      roar_auth_mes_init(&authmes, ltt[i]);
+      roar_auth_mes_init(&authmes, cur);
       if ( (ret = roar_auth_ask_server(con, &authmes)) == -1 )
        done = 0;
@@ -341,9 +352,14 @@
     done = 0;
 
-   if ( done )
+   ROAR_DBG("roar_auth(con=%p): done=%i, next=%i", con, done, next);
+
+   if ( done ) {
+    ROAR_DBG("roar_auth(con=%p) = 0", con);
     return 0;
+   }
   }
  }
 
+ ROAR_DBG("roar_auth(con=%p) = -1", con);
  return -1;
 }
@@ -354,6 +370,8 @@
  char header[4] = {0, 0, 0, 0};
 
- if ( ames == NULL || mes == NULL )
-  return -1;
+ if ( ames == NULL || mes == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( data != NULL ) {
@@ -386,6 +404,8 @@
  char * obuf;
 
- if ( mes == NULL || ames == NULL )
-  return -1;
+ if ( mes == NULL || ames == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( data != NULL )
Index: libroar/basic.c
===================================================================
--- libroar/basic.c	(revision 5144)
+++ libroar/basic.c	(revision 5146)
@@ -389,5 +389,5 @@
  mes.stream = -1;
 
- return roar_req(con, &mes, NULL);
+ return roar_req3(con, &mes, NULL);
 }
 
@@ -432,5 +432,5 @@
  strncpy(mes.data+5, name, max_len);
 
- return roar_req(con, &mes, NULL);
+ return roar_req3(con, &mes, NULL);
 }
 
Index: libroar/beep.c
===================================================================
--- libroar/beep.c	(revision 5145)
+++ libroar/beep.c	(revision 5146)
@@ -63,5 +63,5 @@
  }
 
- if ( roar_req(con, &m, NULL) != 0 )
+ if ( roar_req3(con, &m, NULL) != 0 )
   return -1;
 
Index: libroar/error.c
===================================================================
--- libroar/error.c	(revision 5097)
+++ libroar/error.c	(revision 5146)
@@ -45,35 +45,90 @@
 int roar_errno = ROAR_ERROR_NONE;
 
+struct roar_error_frame * roar_err_errorframe(void) {
+ static struct roar_error_frame frame = {
+  .version     =  0,
+  .cmd         = -1,
+  .ra_errno    = ROAR_ERROR_UNKNOWN,
+  .ra_suberrno = -1,
+  .p_errno     = -1,
+  .flags       =  0,
+  .datalen     =  0,
+  .data        = NULL
+ };
+
+ return &frame;
+}
+
 int    roar_err_int(struct roar_error_frame * frame) {
- if ( frame == NULL )
+ roar_debug_warn_obsolete("roar_err_int", "roar_err_init", NULL);
+ return roar_err_init(frame);
+}
+int    roar_err_init(struct roar_error_frame * frame) {
+ if ( frame == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return -1;
+ }
 
  memset(frame, 0, sizeof(struct roar_error_frame));
 
  frame->cmd         = -1;
- frame->ra_errno    = -1;
+ frame->ra_errno    = ROAR_ERROR_UNKNOWN;
  frame->ra_suberrno = -1;
  frame->p_errno     = -1;
+ frame->datalen     =  0;
+ frame->data        = NULL;
 
  return 0;
 }
 
+
 void * roar_err_buildmsg(struct roar_message * mes, struct roar_error_frame * frame) {
+ roar_debug_warn_obsolete("roar_err_buildmsg", "roar_err_buildmsg2", NULL);
+ return roar_err_buildmsg2(mes, NULL, frame);
+}
+void * roar_err_buildmsg2(struct roar_message * mes, void ** data, struct roar_error_frame * frame) {
+ char * databuf = NULL;
  int16_t * d;
-
- if ( mes == NULL || frame == NULL )
+ size_t datalen;
+
+ if ( mes == NULL || frame == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
   return NULL;
+ }
+
+ if ( data != NULL )
+  *data = NULL;
+
+ datalen = 8 + frame->datalen;
+ if ( datalen > LIBROAR_BUFFER_MSGDATA ) {
+  if ( data == NULL ) {
+   roar_err_set(ROAR_ERROR_FAULT);
+   return NULL;
+  }
+
+  roar_err_clear_errno();
+  *data = malloc(datalen);
+  roar_err_from_errno();
+  if ( *data == NULL )
+   return NULL;
+
+  databuf = *data;
+ } else {
+  databuf = mes->data;
+ }
 
  memset(mes,  0, sizeof(struct roar_message));
-
- d = (int16_t*)mes->data;
-
- mes->datalen = 8 + frame->datalen;
- frame->data  = &(mes->data[8]);
-
- mes->data[0]    = 0; // version.
- mes->data[1]    = frame->cmd;
- mes->data[2]    = frame->ra_errno;
- mes->data[3]    = frame->ra_suberrno;
+ memset(databuf, 0, mes->datalen);
+
+ mes->datalen = datalen;
+
+ d = (int16_t*)databuf;
+
+ frame->data  = &(databuf[8]);
+
+ databuf[0]    = 0; // version.
+ databuf[1]    = frame->cmd;
+ databuf[2]    = frame->ra_errno;
+ databuf[3]    = frame->ra_suberrno;
  d[2]            = ROAR_HOST2NET16(frame->p_errno);
  d[3]            = ROAR_HOST2NET16(frame->flags);
@@ -83,26 +138,63 @@
 
 int    roar_err_parsemsg(struct roar_message * mes, struct roar_error_frame * frame) {
+ roar_debug_warn_obsolete("roar_err_parsemsg", "roar_err_parsemsg", NULL);
+ return roar_err_parsemsg2(mes, NULL, frame);
+}
+int    roar_err_parsemsg2(struct roar_message * mes, void *  data, struct roar_error_frame * frame) {
+ char * databuf = (char *)data;
  int16_t * d;
 
- if ( mes == NULL || frame == NULL )
+ ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
+          mes, (int)mes->datalen, mes->data, data, frame);
+
+ if ( mes == NULL || frame == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = -1 // error=FAULT",
+           mes, (int)mes->datalen, mes->data, data, frame);
   return -1;
-
- d = (int16_t*)mes->data;
-
- if ( mes->datalen < 8 )
+ }
+
+ ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
+          mes, (int)mes->datalen, mes->data, data, frame);
+
+ if ( databuf == NULL )
+  databuf = mes->data;
+
+ d = (int16_t*)databuf;
+
+ ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
+          mes, (int)mes->datalen, mes->data, data, frame);
+
+ if ( mes->datalen < 8 ) {
+  roar_err_set(ROAR_ERROR_MSGSIZE);
+  ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = -1 // error=MSGSIZE",
+           mes, (int)mes->datalen, mes->data, data, frame);
   return -1;
-
- if ( mes->data[0] != 0 )
+ }
+
+ ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
+          mes, (int)mes->datalen, mes->data, data, frame);
+
+ if ( databuf[0] != 0 ) {
+  roar_err_set(ROAR_ERROR_NSVERSION);
+  ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = -1 // error=NSVERSION",
+           mes, (int)mes->datalen, mes->data, data, frame);
   return -1;
-
- frame->cmd         = mes->data[1];
- frame->ra_errno    = mes->data[2];
- frame->ra_suberrno = mes->data[3];
+ }
+
+ ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = ?",
+          mes, (int)mes->datalen, mes->data, data, frame);
+
+ frame->cmd         = databuf[1];
+ frame->ra_errno    = databuf[2];
+ frame->ra_suberrno = databuf[3];
  frame->p_errno     = ROAR_NET2HOST16(d[2]);
  frame->flags       = ROAR_NET2HOST16(d[3]);
 
  frame->datalen     = mes->datalen - 8;
- frame->data        = &(mes->data[8]);
-
+ frame->data        = &(databuf[8]);
+
+ ROAR_DBG("roar_err_parsemsg2(mes=%p{.datalen=%i, .data=%p}, data=%p, frame=%p) = 0",
+          mes, (int)mes->datalen, mes->data, data, frame);
  return 0;
 }
@@ -128,5 +220,5 @@
  int * err = roar_errno2();
 
- // NOTE: _NEVER_ call ROAR_{DBG,INFO,WARN,ERRO}() in here! (will result in endless loop)
+ // NOTE: _NEVER_ call ROAR_{DBG,INFO,WARN,ERROR}() in here! (will result in endless loop)
  //printf("*err=%i, errno=%i\n", *err, (int)errno);
 
Index: libroar/proto.c
===================================================================
--- libroar/proto.c	(revision 5030)
+++ libroar/proto.c	(revision 5146)
@@ -134,4 +134,8 @@
 
 int roar_recv_message (struct roar_connection * con, struct roar_message * mes, char ** data) {
+ return roar_recv_message2(con, mes, data, NULL);
+}
+int roar_recv_message2 (struct roar_connection * con, struct roar_message * mes, char ** data,
+                        struct roar_error_frame * errorframe) {
  struct roar_vio_calls * vio;
 
@@ -139,8 +143,13 @@
   return -1;
 
- return roar_vrecv_message(vio, mes, data);
+ return roar_vrecv_message2(vio, mes, data, errorframe);
 }
 
 int roar_vrecv_message(struct roar_vio_calls * vio, struct roar_message * mes, char ** data) {
+ return roar_vrecv_message2(vio, mes, data, NULL);
+}
+
+int roar_vrecv_message2(struct roar_vio_calls  * vio, struct roar_message * mes, char ** data,
+                        struct roar_error_frame * errorframe) {
  // TODO: add CRC support.
  char buf[_ROAR_MESS_BUF_LEN_MAX];
@@ -153,8 +162,12 @@
  roar_err_set(ROAR_ERROR_UNKNOWN);
 
- ROAR_DBG("roar_recv_message(*): try to get a response form the server...");
-
- if ( mes == NULL )
-  return -1;
+ ROAR_DBG("roar_vrecv_message2(vio=%p, mes=%p, data=%p, errorframe=%p) = ?", vio, mes, data, errorframe);
+
+ ROAR_DBG("roar_vrecv_message2(*): try to get a response form the server...");
+
+ if ( vio == NULL || mes == NULL ) {
+  roar_err_set(ROAR_ERROR_FAULT);
+  return -1;
+ }
 
  if ( data != NULL )
@@ -168,5 +181,5 @@
  }
 
- ROAR_DBG("roar_recv_message(*): Got a header");
+ ROAR_DBG("roar_vrecv_message2(*): Got a header");
 
  mes->version = buf[0];
@@ -224,5 +237,5 @@
   mes->stream = -1;
 
- ROAR_DBG("roar_recv_message(*): command=%i(%s)", mes->cmd,
+ ROAR_DBG("roar_vrecv_message2(*): command=%i(%s)", mes->cmd,
            mes->cmd == ROAR_CMD_OK ? "OK" : (mes->cmd == ROAR_CMD_ERROR ? "ERROR" : "UNKNOWN"));
 
@@ -230,7 +243,10 @@
 
  if ( mes->datalen == 0 ) {
-  ROAR_DBG("roar_recv_message(*): no data in this pkg");
-  ROAR_DBG("roar_recv_message(*) = 0");
+  ROAR_DBG("roar_vrecv_message2(*): no data in this pkg");
+  if ( mes->cmd == ROAR_CMD_ERROR && errorframe != NULL ) {
+   roar_err_init(errorframe);
+  }
   roar_err_clear();
+  ROAR_DBG("roar_vrecv_message2(*) = 0");
   return 0;
  }
@@ -238,7 +254,12 @@
  if ( mes->datalen <= LIBROAR_BUFFER_MSGDATA ) {
   if ( roar_vio_read(vio, mes->data, mes->datalen) == mes->datalen ) {
-   ROAR_DBG("roar_recv_message(*): Got data!");
-   ROAR_DBG("roar_recv_message(*) = 0");
+   ROAR_DBG("roar_vrecv_message2(*): Got data!");
    roar_err_clear();
+   if ( mes->cmd == ROAR_CMD_ERROR && errorframe != NULL ) {
+    if ( roar_err_parsemsg2(mes, *data, errorframe) != 0 ) {
+     roar_err_init(errorframe);
+    }
+   }
+   ROAR_DBG("roar_vrecv_message2(*) = 0");
    return 0;
   }
@@ -258,11 +279,20 @@
   if ( mes->datalen == 0 ) {
    roar_err_clear();
+   if ( mes->cmd == ROAR_CMD_ERROR && errorframe != NULL ) {
+    roar_err_init(errorframe);
+   }
    return 0;
   }
 
   if ( roar_vio_read(vio, *data, mes->datalen) == mes->datalen ) {
-   ROAR_DBG("roar_recv_message(*): Got data!");
-   ROAR_DBG("roar_recv_message(*) = 0");
+   ROAR_DBG("roar_vrecv_message2(*): Got data!");
+
    roar_err_clear();
+   if ( mes->cmd == ROAR_CMD_ERROR && errorframe != NULL ) {
+    if ( roar_err_parsemsg2(mes, *data, errorframe) != 0 ) {
+     roar_err_init(errorframe);
+    }
+   }
+   ROAR_DBG("roar_vrecv_message2(*) = 0");
    return 0;
   }
@@ -277,4 +307,9 @@
 
 int roar_req (struct roar_connection * con, struct roar_message * mes, char ** data) {
+ return roar_req2(con, mes, data, NULL);
+}
+
+int roar_req2          (struct roar_connection * con, struct roar_message * mes, char ** data,
+                        struct roar_error_frame * errorframe) {
  struct roar_vio_calls * vio;
 
@@ -282,8 +317,13 @@
   return -1;
 
- return roar_vreq(vio, mes, data);
+ return roar_vreq2(vio, mes, data, errorframe);
 }
 
 int roar_vreq         (struct roar_vio_calls * vio, struct roar_message * mes, char ** data) {
+ return roar_vreq2(vio, mes, data, NULL);
+}
+
+int roar_vreq2         (struct roar_vio_calls  * vio, struct roar_message * mes, char ** data,
+                        struct roar_error_frame * errorframe) {
  if ( roar_vsend_message(vio, mes, data != NULL ? *data : NULL) != 0 )
   return -1;
@@ -294,5 +334,5 @@
  roar_vio_sync(vio); // we need to do this becasue of ssl/compressed links
 
- return roar_vrecv_message(vio, mes, data);
+ return roar_vrecv_message2(vio, mes, data, errorframe);
 }
 
Index: roard/auth.c
===================================================================
--- roard/auth.c	(revision 4745)
+++ roard/auth.c	(revision 5146)
@@ -127,5 +127,6 @@
  for (i = 0; i < AUTH_KEYRING_LEN; i++) {
   if ( (key = &(g_auth_keyring[i]))->type == authmes->type ) {
-    ret = -1;
+   ROAR_DBG("auth_client_ckeck(cs=%p, authmes=%p, next=%p{%i}): key=%p{.type=%i, ...}", cs, authmes, next, *next, key, key->type);
+   ret = -1;
    switch (key->type) {
     case ROAR_AUTH_T_NONE:
Index: roard/clients.c
===================================================================
--- roard/clients.c	(revision 4947)
+++ roard/clients.c	(revision 5146)
@@ -1028,5 +1028,5 @@
    return _g_acclevs[i].acclev;
 
- return -1;
+ return ACCLEV_ERROR;
 }
 
Index: roard/include/client.h
===================================================================
--- roard/include/client.h	(revision 4708)
+++ roard/include/client.h	(revision 5146)
@@ -49,11 +49,12 @@
 // access level:
 enum roard_client_acclev {
- ACCLEV_NONE     = 0, // only very basic commands like NOOP and IDENTIFY
- ACCLEV_IDENTED,      // same as NONE but INDENTIFY worked.
- ACCLEV_CONCTL,       // only allowed to do basic connection things.
- ACCLEV_GUEST,        // guest connection (read only)
- ACCLEV_USER,         // normal user connect (read write)
- ACCLEV_PWRUSER,      // power user, may access other user's clients
- ACCLEV_ALL           // full (admin) access (read write ctl)
+ ACCLEV_ERROR    = -1, // used as erorr return value.
+ ACCLEV_NONE     =  0, // only very basic commands like NOOP and IDENTIFY
+ ACCLEV_IDENTED,       // same as NONE but INDENTIFY worked.
+ ACCLEV_CONCTL,        // only allowed to do basic connection things.
+ ACCLEV_GUEST,         // guest connection (read only)
+ ACCLEV_USER,          // normal user connect (read write)
+ ACCLEV_PWRUSER,       // power user, may access other user's clients
+ ACCLEV_ALL            // full (admin) access (read write ctl)
 };
 
Index: roard/req.c
===================================================================
--- roard/req.c	(revision 5065)
+++ roard/req.c	(revision 5146)
@@ -141,8 +141,13 @@
                            client, roar_autht2str(authmes.type), authmes.type, (long long unsigned int)authmes.len);
 
+ ROAR_DBG("req_on_auth(client=%i,...): CALL auth_client_ckeck(cs=%p, &authmes=%p, &next=%p)", client, cs, &authmes, &next);
  ret = auth_client_ckeck(cs, &authmes, &next);
+ ROAR_DBG("req_on_auth(client=%i,...): RET %i // next=%s(%i)", client, ret, roar_autht2str(next), next);
 
  if ( ret != 1 ) {
+  ROAR_DBG("req_on_auth(client=%i,...) = ?", client);
+
   if ( next != -1 ) {
+   ROAR_DBG("req_on_auth(client=%i,...) = ?", client);
    memset(&authmes, 0, sizeof(authmes));
 
@@ -152,6 +157,10 @@
     return -1;
 
-   if ( roar_err_int(&error_frame) == -1 )
-    return -1;
+   ROAR_DBG("req_on_auth(client=%i,...) = ?", client);
+
+   if ( roar_err_init(&error_frame) == -1 )
+    return -1;
+
+   ROAR_DBG("req_on_auth(client=%i,...) = ?", client);
 
    error_frame.ra_errno = ROAR_ERROR_PERM;
@@ -159,4 +168,5 @@
 
    error_data   = roar_err_buildmsg(mes, &error_frame);
+   ROAR_DBG("req_on_auth(client=%i,...): error_data=%p", client, error_data);
 
    memcpy(error_data, error_mes.data, error_mes.datalen);
@@ -164,7 +174,11 @@
    mes->cmd     = ROAR_CMD_ERROR;
    mes->pos     = g_pos;
+
+   ROAR_DBG("req_on_auth(client=%i,...): mes=%p{.datalen=%i}", client, mes, (int)mes->datalen);
+   ROAR_DBG("req_on_auth(client=%i,...) = 0 // cmd=ERROR", client);
    return 0;
   }
 
+  ROAR_DBG("req_on_auth(client=%i,...) = 0", client);
   return -1;
  }
@@ -173,4 +187,6 @@
  mes->pos     = g_pos;
  mes->datalen = 0;
+
+ ROAR_DBG("req_on_auth(client=%i,...) = 0", client);
  return 0;
 }
Index: roard/roard.c
===================================================================
--- roard/roard.c	(revision 5103)
+++ roard/roard.c	(revision 5146)
@@ -217,7 +217,8 @@
  printf("\nAuth Options:\n\n");
  printf(
-        " --guest-acclev ACCLEV - Sets the access level for guest access to ACCLEV\n"
+        " --guest-acclev ACCLEV - Sets the access level for guest access to ACCLEV,\n"
+        "                         Use \"none\" to disable guest access.\n"
         " --trust-acclev ACCLEV - Sets the access level for trust-authed\n"
-        "                         connections to ACCLEV\n"
+        "                         connections to ACCLEV. Use \"none\" to disable trust auth.\n"
         " --trust-root          - Trust root user\n"
         " --no-trust-root       - Don't trust root user\n"
@@ -1679,7 +1680,15 @@
    _CKHAVEARGS(1);
    none_acclev = clients_str2acclev(argv[++i]);
+   if ( none_acclev == -1 ) {
+    ROAR_ERR("Invalid access level: %s", argv[i]);
+    return 1;
+   }
   } else if ( strcmp(k, "--trust-acclev") == 0 ) {
    _CKHAVEARGS(1);
    trust_acclev = clients_str2acclev(argv[++i]);
+   if ( trust_acclev == -1 ) {
+    ROAR_ERR("Invalid access level: %s", argv[i]);
+    return 1;
+   }
   } else if ( strcmp(k, "--trust-root") == 0 ) {
    trust_root = 1;
