xfreerdp: add --authonly switch to xfreerdp client
authorMike Carifio <michael.carifio@canonical.com>
Wed, 6 Jun 2012 09:46:21 +0000 (17:46 +0800)
committerRex Tsai <chihchun@kalug.linux.org.tw>
Wed, 6 Jun 2012 09:55:34 +0000 (17:55 +0800)
Signed-off-by: Rex Tsai <chihchun@kalug.linux.org.tw>
client/X11/xfreerdp.1.xml
client/X11/xfreerdp.c
include/freerdp/settings.h
libfreerdp-core/freerdp.c
libfreerdp-core/settings.c
libfreerdp-utils/args.c

index 009e410..79d1af4 100644 (file)
         </listitem>
       </varlistentry>
       <varlistentry>
+        <term>--authonly</term>
+        <listitem>
+          <para>
+            Only authenticates. This is useful to test your credentials (username and password). Returns status code 0 if the client can connect, 1 otherwise. Requires a username, password and connection host at the command line.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
         <term>--no-fastpath</term>
         <listitem>
           <para>
index c8ee690..080efbf 100644 (file)
@@ -479,7 +479,7 @@ boolean xf_pre_connect(freerdp* instance)
        if (arg_parse_result < 0)
        {
                if (arg_parse_result == FREERDP_ARGS_PARSE_FAILURE)
-                       printf("failed to parse arguments.\n");
+                       fprintf(stderr, "%s:%d: failed to parse arguments.\n", __FILE__, __LINE__);
                
                exit(XF_EXIT_PARSE_ARGUMENTS);
        }
@@ -521,6 +521,22 @@ boolean xf_pre_connect(freerdp* instance)
 
        freerdp_channels_pre_connect(xfi->_context->channels, instance);
 
+
+  if (settings->authentication_only) {
+               /* Check --authonly has a username and password. */
+               if (settings->username == NULL ) {
+                       fprintf(stderr, "--authonly, but no -u username. Please provide one.\n");
+                       exit(1);
+               }
+               if (settings->password == NULL ) {
+                       fprintf(stderr, "--authonly, but no -p password. Please provide one.\n");
+                       exit(1);
+               }
+               fprintf(stderr, "%s:%d: Authenication only. Don't connect to X.\n", __FILE__, __LINE__);
+               // Avoid XWindows initialization and configuration below.
+               return true;
+       }
+
        xfi->display = XOpenDisplay(NULL);
 
        if (xfi->display == NULL)
@@ -1072,6 +1088,11 @@ int xfreerdp_run(freerdp* instance)
                xf_free(((xfContext*) instance->context)->xfi);
                return XF_EXIT_CONN_FAILED;
        }
+       /* Connection succeeded. --authonly ? */
+       if (instance->settings->authentication_only) {
+               freerdp_disconnect(instance);
+    exit(0);
+       }
 
        xfi = ((xfContext*) instance->context)->xfi;
        channels = instance->context->channels;
index 2437739..17b405d 100644 (file)
@@ -293,7 +293,8 @@ struct rdp_settings
        ALIGN64 char* tsg_username; /* 66 */
        ALIGN64 char* tsg_password; /* 67 */
        ALIGN64 boolean local; /* 68 */
-       ALIGN64 uint64 paddingC[80 - 69]; /* 69 */
+       ALIGN64 boolean authentication_only; /* 69 */
+       ALIGN64 uint64 paddingC[80 - 70]; /* 70 */
 
        /* User Interface Parameters */
        ALIGN64 boolean sw_gdi; /* 80 */
index a30602d..7d4eb61 100644 (file)
@@ -61,11 +61,16 @@ boolean freerdp_connect(freerdp* instance)
                if(!connectErrorCode){
                        connectErrorCode = PREECONNECTERROR;
                }
-               printf("freerdp_pre_connect failed\n");
+               fprintf(stderr, "%s:%d: freerdp_pre_connect failed\n", __FILE__, __LINE__);
                return false;
        }
 
        status = rdp_client_connect(rdp);
+       // --authonly tests the connection without a UI
+       if (instance->settings->authentication_only) {
+               fprintf(stderr, "%s:%d: Authentication only, exit status %d\n", __FILE__, __LINE__, !status);
+               return true;
+       }
 
        if (status)
        {
index 03ec3ce..609a63a 100644 (file)
@@ -73,6 +73,7 @@ rdpSettings* settings_new(void* instance)
                settings->encryption_level = ENCRYPTION_LEVEL_NONE;
 
                settings->authentication = true;
+               settings->authentication_only = false;
 
                settings->received_caps = xzalloc(32);
                settings->order_support = xzalloc(32);
index 1c30321..06bdb73 100644 (file)
@@ -81,6 +81,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
                                "  --app: RemoteApp connection. This implies -g workarea\n"
                                "  --ext: load an extension\n"
                                "  --no-auth: disable authentication\n"
+                               "  --authonly: authentication only, no UI\n"
                                "  --no-fastpath: disable fast-path\n"
                                "  --no-motion: don't send mouse motion events\n"
                                "  --gdi: graphics rendering (hw, sw)\n"
@@ -306,6 +307,10 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
                {
                        settings->authentication = false;
                }
+               else if (strcmp("--authonly", argv[index]) == 0)
+               {
+                       settings->authentication_only = true;
+               }
                else if (strcmp("--ignore-certificate", argv[index]) == 0)
                {
                        settings->ignore_certificate = true;