source: ldm/trunk/fuentes/src/plugins/rdesktop/rdesktop.c @ 855

Last change on this file since 855 was 855, checked in by mabarracus, 5 years ago
  • Updated sources to 2.2.18
  • Ported code from patches to apply in 2.2.18
File size: 4.1 KB
Line 
1#include <config.h>
2#include <ctype.h>
3#include <glib.h>
4#include <libintl.h>
5#include <locale.h>
6#include <pthread.h>
7#include <pty.h>
8#include <signal.h>
9#include <stdarg.h>
10#include <stdio.h>
11#include <stdlib.h>
12#include <string.h>
13#include <sys/ioctl.h>
14#include <utmp.h>
15
16#include "../../ldmutils.h"
17#include "../../ldmgreetercomm.h"
18#include "../../logging.h"
19#include "../../plugin.h"
20#include "rdesktop.h"
21
22LdmBackend *descriptor;
23RdpInfo *rdpinfo;
24
25void __attribute__ ((constructor)) initialize()
26{
27    descriptor = (LdmBackend *) malloc(sizeof(LdmBackend));
28    bzero(descriptor, sizeof(LdmBackend));
29
30    descriptor->name = "rdesktop";
31    descriptor->description = "rdesktop plugin";
32    descriptor->init_cb = init_rdesktop;
33    descriptor->auth_cb = auth_rdesktop;
34    descriptor->start_cb = start_rdesktop;
35    descriptor->clean_cb = close_rdesktop;
36    ldm_init_plugin(descriptor);
37}
38
39/*
40 * init_rdesktop
41 *  Callback function for initialization
42 */
43void
44init_rdesktop()
45{
46    rdpinfo = (RdpInfo *) malloc(sizeof(RdpInfo));
47    bzero(rdpinfo, sizeof(RdpInfo));
48
49    /* Get ENV value */
50    rdpinfo->rdpoptions = g_strdup(getenv("RDP_OPTIONS"));
51    rdpinfo->server = g_strdup(getenv("RDP_SERVER"));
52}
53
54/*
55 * start_rdesktop
56 *  Callback function for starting rdesktop session
57 */
58void
59start_rdesktop()
60{
61    gboolean error = FALSE;
62
63    /* Variable validation */
64    if (!rdpinfo->username) {
65        log_entry("rdesktop", 3, "no username");
66        error = TRUE;
67    }
68
69    if (!rdpinfo->password) {
70        log_entry("rdesktop", 3, "no password");
71        error = TRUE;
72    }
73
74    if (!rdpinfo->server) {
75        log_entry("rdesktop", 3, "no server");
76        error = TRUE;
77    }
78
79    if (!rdpinfo->domain) {
80        log_entry("rdesktop", 3, "no domain");
81        error = TRUE;
82    }
83
84    if (error) {
85        die("rdesktop", "missing mandatory information");
86    }
87
88    /* Greeter not needed anymore */
89    close_greeter();
90
91    log_entry("rdesktop", 6, "starting rdesktop session to '%s' as '%s'",
92              rdpinfo->server, rdpinfo->username);
93    rdesktop_session();
94    log_entry("rdesktop", 6, "closing rdesktop session");
95}
96
97/*
98 * _get_domain
99 */
100void
101_get_domain()
102{
103    gchar *cmd = "value domain\n";
104
105    rdpinfo->domain = ask_value_greeter(cmd);
106}
107
108/*
109 * auth_rdesktop
110 *  Callback function for authentication
111 */
112void
113auth_rdesktop()
114{
115    gchar *cmd;
116
117    /* Separator for domains : '|' */
118    gchar *domains = getenv("RDP_DOMAIN");
119    cmd =
120        g_strconcat
121        ("pref choice;domain;Domain;Select Domai_n ...;session;", domains,
122         "\n", NULL);
123    if (domains) {
124        if (ask_greeter(cmd))
125            die("rdesktop", "%s from greeter failed", cmd);
126    } else {
127        log_entry("rdesktop", 7,
128                  "RDP_DOMAIN isn't defined, rdesktop will connect on default domain");
129    }
130
131    /* Ask for UserID */
132    get_userid(&(rdpinfo->username));
133
134    /* If user clicks on guest button above, this has changed  */
135    get_passwd(&(rdpinfo->password));
136
137    /* Get hostname */
138    if (!rdpinfo->server)
139        get_host(&(rdpinfo->server));
140
141    /* Get Domain (rdesktop plugin specific) */
142    _get_domain();
143
144    /* Get Language */
145    get_language(&(rdpinfo->lang));
146
147    g_free(cmd);
148}
149
150/*
151 * close_rdesktop
152 *  Callback function for closing the plugins
153 */
154void
155close_rdesktop()
156{
157    log_entry("rdesktop", 7, "closing rdesktop session");
158    free(rdpinfo);
159}
160
161/*
162 * rdesktop_session
163 *  Start a rdesktop session to server
164 */
165void
166rdesktop_session()
167{
168    gchar *cmd;
169
170    cmd = g_strjoin(" ", "rdesktop", "-f",
171                    "-u", rdpinfo->username,
172                    "-p", rdpinfo->password, NULL);
173
174    /* Only append the domain if it's set */
175    if (g_strcmp0(rdpinfo->domain, "None") != 0) {
176        cmd = g_strjoin(" ", cmd, "-d", rdpinfo->domain, NULL);
177    }
178
179    /* If we have custom options, append them */
180    if (rdpinfo->rdpoptions) {
181        cmd = g_strjoin(" ", cmd, rdpinfo->rdpoptions, NULL);
182    }
183
184    cmd = g_strjoin(" ", cmd, rdpinfo->server, NULL);
185
186    /* Spawning rdesktop session */
187    rdpinfo->rdppid = ldm_spawn(cmd, NULL, NULL, NULL);
188    ldm_wait(rdpinfo->rdppid);
189
190    g_free(cmd);
191}
Note: See TracBrowser for help on using the repository browser.