source: ldm/trunk/fuentes/src/ldm.c @ 516

Last change on this file since 516 was 516, checked in by mabarracus, 5 years ago

Copy trusty code

File size: 7.4 KB
Line 
1/*
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of the
6 * License, or (at your option) any later version.
7
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * GNU General Public License for more details.
12
13 * You should have received a copy of the GNU General Public License
14 * along with this program.  If not, you can find it on the World Wide
15 * Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free
16 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
17 * MA 02110-1301, USA.
18 */
19
20#include <config.h>
21#include <glib.h>
22#include <glib-object.h>
23#include <libintl.h>
24#include <locale.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <sys/types.h>
29#include <unistd.h>
30
31#include "ldm.h"
32#include "ldmgreetercomm.h"
33#include "ldmplugin.h"
34#include "ldminfo.h"
35#include "ldmutils.h"
36#include "logging.h"
37
38GList *host_list = NULL;
39volatile sig_atomic_t unexpected_child = 0;
40volatile sig_atomic_t child_exited = 0;
41
42/* stub declaration */
43struct ldm_info ldm;
44
45/*
46 * get_ldm_env
47 *  Setting up LDM env. variables
48 */
49void get_ldm_env() {
50    gchar *greeter_path, *wm_path;
51
52    ldminfo_init(&host_list, getenv("LDM_SERVER"));
53    ldm.allowguest = ldm_getenv_bool("LDM_GUESTLOGIN");
54    ldm.sound = ldm_getenv_bool("SOUND");
55    ldm.sound_daemon = g_strdup(getenv("SOUND_DAEMON"));
56    ldm.localdev = ldm_getenv_bool("LOCALDEV");
57    ldm.override_port = g_strdup(getenv("SSH_OVERRIDE_PORT"));
58    ldm.directx = ldm_getenv_bool("LDM_DIRECTX");
59    ldm.nomad = ldm_getenv_bool("LDM_NOMAD");
60    ldm.autologin = ldm_getenv_bool("LDM_AUTOLOGIN");
61    ldm.lang = g_strdup(getenv("LDM_LANGUAGE"));
62    ldm.session = g_strdup(getenv("LDM_SESSION"));
63
64    /* Greeter Setup */
65    greeter_path = g_strdup(getenv("LDM_GREETER"));
66    if (!greeter_path)
67        greeter_path = g_strdup("ldmgtkgreet");
68
69    if(greeter_path[0] != '/') {
70        ldm.greeter_prog = g_strjoin("/", LDM_EXEC_DIR, greeter_path, NULL);
71        g_free(greeter_path);
72    } else {
73        ldm.greeter_prog = greeter_path;
74    }
75
76    wm_path = g_strdup(getenv("LDM_WINMANAGER"));
77    if(!wm_path)
78        wm_path = g_strdup("wwm");
79
80    if(wm_path[0] != '/') {
81        ldm.wm_prog = g_strjoin("/", LDM_EXEC_DIR, wm_path, NULL);
82        g_free(wm_path);
83    } else {
84        ldm.wm_prog = wm_path;
85    }
86    ldm.authfile = g_strdup(getenv("XAUTHORITY"));
87}
88
89/*
90 * main entry point
91 */
92int main(int argc, char *argv[]) {
93    /* decls */
94    gchar *auth_plugin = NULL;
95    struct sigaction action;
96
97    /* Init log settings */
98    log_init(ldm_getenv_bool("LDM_SYSLOG"),ldm_getenv_int("LDM_LOGLEVEL",-1));
99
100#ifdef ENABLE_NLS
101    setlocale (LC_ALL, "");
102    bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
103    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
104    textdomain (GETTEXT_PACKAGE);
105#endif
106
107    g_type_init();
108
109    /* set an empty handler for SIGCHLD so they're not ignored */
110    action.sa_handler = handle_sigchld;
111    sigemptyset(&action.sa_mask);
112    action.sa_flags = SA_SIGINFO;
113    sigaction (SIGCHLD, &action, NULL);
114
115    /*
116     * Zero out our info struct.
117     */
118    bzero(&ldm, sizeof ldm);
119
120    ldm.pid = getpid();  /* Get our pid, to use in the command_socket */
121    ldm.display = g_strdup(getenv("DISPLAY"));
122
123    /*
124     * Get our IP address.
125     */
126    get_ipaddr();
127    log_entry("ldm",6,"started on client with IP address: %s", ldm.ipaddr);
128
129    /*
130     *  Put ip address in environment so that it is available to to the greeter
131     */
132    setenv("LDMINFO_IPADDR", ldm.ipaddr, 1);
133
134    /*
135     * Get some of the environment variables we'll need.
136     */
137    get_ldm_env();
138
139    /*
140     * Load plugins
141     */
142    if(ldm_load_plugins())
143        log_entry("ldm",3,"unable to load plugins");
144
145    /*
146     * Begin running display manager
147     */
148    log_entry("ldm",6,"calling rc.d init scripts");
149    rc_files("init");                      /* Execute any rc files */
150
151    if (!ldm.autologin) {
152        /* start interactive greeter only if no autologin */
153        gint rfd, wfd, rfd2, wfd2;
154
155        log_entry("ldm",7,"spawning window manager: %s", ldm.wm_prog);
156        ldm.wmpid = ldm_spawn(ldm.wm_prog, &rfd2, &wfd2, NULL);
157        log_entry("ldm",7,"spawning greeter: %s", ldm.greeter_prog);
158        ldm.greeterpid = ldm_spawn(ldm.greeter_prog, &rfd, &wfd, NULL);
159        set_greeter_pid(ldm.greeterpid);
160        /* create GIOChannels for the greeter */
161        ldm.greeterr = g_io_channel_unix_new(rfd);
162        set_greeter_read_channel(ldm.greeterr);
163        ldm.greeterw = g_io_channel_unix_new(wfd);
164        set_greeter_write_channel(ldm.greeterw);
165
166        /* if a backend is forced, leave no choice */
167        if (!getenv("LDM_FORCE_BACKEND")) {
168            gchar *cmd;
169            gchar *backends;
170
171            /* allow choosing backend */
172            backends = g_strjoinv("|", ldm_get_plugins());
173            cmd = g_strconcat("pref choice;backend;Authentication Backend;Select _Backend ...;session;",
174                              backends, "\n", NULL);
175            if(ask_greeter(cmd))
176                die("ldm", "%s from greeter failed", cmd);
177            g_free(backends);
178            g_free(cmd);
179        }
180
181        do {
182            /* backend precedence is LDM_FORCE_BACKEND, user choice,
183             * LDM_DEFAULT_BACKEND then hardcoded constant. */
184            g_free(auth_plugin);
185            auth_plugin = g_strdup(getenv("LDM_FORCE_BACKEND"));
186            if (!auth_plugin) {
187                auth_plugin = ask_value_greeter("value backend\n");
188                if (!g_strcmp0(auth_plugin, "None")) {
189                    g_free(auth_plugin);
190                    auth_plugin = g_strdup(getenv("LDM_DEFAULT_BACKEND"));
191                    if (!auth_plugin)
192                        auth_plugin = g_strdup(DEFAULT_AUTH_PLUGIN);
193                }
194            }
195
196            /* Init plugin */
197            set_current_plugin(auth_plugin);
198            log_entry("ldm",6,"authenticating with backend: %s", auth_plugin);
199            ldm_setup_plugin();
200        } while (ldm_auth_plugin());
201    } else {
202        auth_plugin = g_strdup(getenv("LDM_DEFAULT_BACKEND"));
203        if (!auth_plugin)
204            auth_plugin = g_strdup(DEFAULT_AUTH_PLUGIN);
205
206        set_current_plugin(auth_plugin);
207        log_entry("ldm",6,"guest authenticating with backend: %s", auth_plugin);
208        ldm_setup_plugin();
209
210        ldm_guest_auth_plugin();
211    }
212
213    /* Closing Window Manager (wwm) */
214    if (ldm.wmpid)
215        close_wm();
216
217    /* Start Plugin */
218    ldm_start_plugin();
219
220    /*
221     * From here plugins has taken control. When plugin return, close everything
222     */
223
224    log_entry("ldm",6,"X session ended");
225
226    log_entry("ldm",6,"calling rc.d stop scripts");
227    rc_files("stop");                       /* Execute any rc files */
228
229    /* Closing plugin */
230    ldm_close_plugin();
231
232    /* Close logging */
233    log_close();
234
235    g_free(ldm.server);
236    g_free(ldm.display);
237    g_free(ldm.override_port);
238    g_free(ldm.authfile);
239    g_free(ldm.username);
240    g_free(ldm.lang);
241    g_free(ldm.session);
242    g_free(ldm.xsession);
243    g_free(ldm.sound_daemon);
244    g_free(ldm.greeter_prog);
245    g_free(ldm.control_socket);
246    g_free(ldm.ipaddr);
247    g_list_foreach(host_list, (GFunc)g_free, NULL);
248    g_list_free(host_list);
249
250    exit(EXIT_SUCCESS);
251}
Note: See TracBrowser for help on using the repository browser.