source: ldm/trunk/fuentes/src/ldm.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: 7.6 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
50get_ldm_env()
51{
52    gchar *greeter_path, *wm_path;
53
54    ldminfo_init(&host_list, getenv("LDM_SERVER"));
55    ldm.allowguest = ldm_getenv_bool("LDM_GUESTLOGIN");
56    ldm.sound = ldm_getenv_bool("SOUND");
57    ldm.sound_daemon = g_strdup(getenv("SOUND_DAEMON"));
58    ldm.localdev = ldm_getenv_bool("LOCALDEV");
59    ldm.override_port = g_strdup(getenv("SSH_OVERRIDE_PORT"));
60    ldm.directx = ldm_getenv_bool("LDM_DIRECTX");
61    ldm.nomad = ldm_getenv_bool("LDM_NOMAD");
62    ldm.autologin = ldm_getenv_bool("LDM_AUTOLOGIN");
63    ldm.lang = g_strdup(getenv("LDM_LANGUAGE"));
64    ldm.session = g_strdup(getenv("LDM_SESSION"));
65
66    /* Greeter Setup */
67    greeter_path = g_strdup(getenv("LDM_GREETER"));
68    if (!greeter_path)
69        greeter_path = g_strdup("ldmgtkgreet");
70
71    if (greeter_path[0] != '/') {
72        ldm.greeter_prog =
73            g_strjoin("/", LDM_EXEC_DIR, greeter_path, NULL);
74        g_free(greeter_path);
75    } else {
76        ldm.greeter_prog = greeter_path;
77    }
78
79    wm_path = g_strdup(getenv("LDM_WINMANAGER"));
80    if (!wm_path)
81        wm_path = g_strdup("wwm");
82
83    if (wm_path[0] != '/') {
84        ldm.wm_prog = g_strjoin("/", LDM_EXEC_DIR, wm_path, NULL);
85        g_free(wm_path);
86    } else {
87        ldm.wm_prog = wm_path;
88    }
89    ldm.authfile = g_strdup(getenv("XAUTHORITY"));
90}
91
92/*
93 * main entry point
94 */
95int
96main(int argc, char *argv[])
97{
98    /* decls */
99    gchar *auth_plugin = NULL;
100    struct sigaction action;
101
102    /* Init log settings */
103    log_init(ldm_getenv_bool("LDM_SYSLOG"),
104             ldm_getenv_int("LDM_LOGLEVEL", -1));
105
106#ifdef ENABLE_NLS
107    setlocale(LC_ALL, "");
108    bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR);
109    bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
110    textdomain(GETTEXT_PACKAGE);
111#endif
112
113    g_type_init();
114
115    /* set an empty handler for SIGCHLD so they're not ignored */
116    action.sa_handler = handle_sigchld;
117    sigemptyset(&action.sa_mask);
118    action.sa_flags = SA_SIGINFO;
119    sigaction(SIGCHLD, &action, NULL);
120
121    /*
122     * Zero out our info struct.
123     */
124    bzero(&ldm, sizeof ldm);
125
126    ldm.pid = getpid();                          /* Get our pid, to use in the command_socket */
127    ldm.display = g_strdup(getenv("DISPLAY"));
128
129    /*
130     * Get our IP address.
131     */
132    get_ipaddr();
133    log_entry("ldm", 6, "started on client with IP address: %s",
134              ldm.ipaddr);
135
136    /*
137     *  Put ip address in environment so that it is available to to the greeter
138     */
139    setenv("LDMINFO_IPADDR", ldm.ipaddr, 1);
140
141    /*
142     * Get some of the environment variables we'll need.
143     */
144    get_ldm_env();
145
146    /*
147     * Load plugins
148     */
149    if (ldm_load_plugins())
150        log_entry("ldm", 3, "unable to load plugins");
151
152    /*
153     * Begin running display manager
154     */
155    log_entry("ldm", 6, "calling rc.d init scripts");
156    rc_files("init");                            /* Execute any rc files */
157
158    if (!ldm.autologin) {
159        /* start interactive greeter only if no autologin */
160        gint rfd, wfd, rfd2, wfd2;
161
162        log_entry("ldm", 7, "spawning window manager: %s", ldm.wm_prog);
163        ldm.wmpid = ldm_spawn(ldm.wm_prog, &rfd2, &wfd2, NULL);
164        log_entry("ldm", 7, "spawning greeter: %s", ldm.greeter_prog);
165        ldm.greeterpid = ldm_spawn(ldm.greeter_prog, &rfd, &wfd, NULL);
166        set_greeter_pid(ldm.greeterpid);
167        /* create GIOChannels for the greeter */
168        ldm.greeterr = g_io_channel_unix_new(rfd);
169        set_greeter_read_channel(ldm.greeterr);
170        ldm.greeterw = g_io_channel_unix_new(wfd);
171        set_greeter_write_channel(ldm.greeterw);
172
173        /* if a backend is forced, leave no choice */
174        if (!getenv("LDM_FORCE_BACKEND")) {
175            gchar *cmd;
176            gchar *backends;
177
178            /* allow choosing backend */
179            backends = g_strjoinv("|", ldm_get_plugins());
180            cmd =
181                g_strconcat
182                ("pref choice;backend;Authentication Backend;Select _Backend ...;session;",
183                 backends, "\n", NULL);
184            if (ask_greeter(cmd))
185                die("ldm", "%s from greeter failed", cmd);
186            g_free(backends);
187            g_free(cmd);
188        }
189
190        do {
191            /* backend precedence is LDM_FORCE_BACKEND, user choice,
192             * LDM_DEFAULT_BACKEND then hardcoded constant. */
193            g_free(auth_plugin);
194            auth_plugin = g_strdup(getenv("LDM_FORCE_BACKEND"));
195            if (!auth_plugin) {
196                auth_plugin = ask_value_greeter("value backend\n");
197                if (!g_strcmp0(auth_plugin, "None")) {
198                    g_free(auth_plugin);
199                    auth_plugin = g_strdup(getenv("LDM_DEFAULT_BACKEND"));
200                    if (!auth_plugin)
201                        auth_plugin = g_strdup(DEFAULT_AUTH_PLUGIN);
202                }
203            }
204
205            /* Init plugin */
206            set_current_plugin(auth_plugin);
207            log_entry("ldm", 6, "authenticating with backend: %s",
208                      auth_plugin);
209            ldm_setup_plugin();
210        } while (ldm_auth_plugin());
211    } else {
212        auth_plugin = g_strdup(getenv("LDM_DEFAULT_BACKEND"));
213        if (!auth_plugin)
214            auth_plugin = g_strdup(DEFAULT_AUTH_PLUGIN);
215
216        set_current_plugin(auth_plugin);
217        log_entry("ldm", 6, "guest authenticating with backend: %s",
218                  auth_plugin);
219        ldm_setup_plugin();
220
221        ldm_guest_auth_plugin();
222    }
223
224    /* Closing Window Manager (wwm) */
225    if (ldm.wmpid)
226        close_wm();
227
228    /* Start Plugin */
229    ldm_start_plugin();
230
231    /*
232     * From here plugins has taken control. When plugin return, close everything
233     */
234
235    log_entry("ldm", 6, "X session ended");
236
237    log_entry("ldm", 6, "calling rc.d stop scripts");
238    rc_files("stop");                            /* Execute any rc files */
239
240    /* Closing plugin */
241    ldm_close_plugin();
242
243    /* Close logging */
244    log_close();
245
246    g_free(ldm.server);
247    g_free(ldm.display);
248    g_free(ldm.override_port);
249    g_free(ldm.authfile);
250    g_free(ldm.username);
251    g_free(ldm.lang);
252    g_free(ldm.session);
253    g_free(ldm.xsession);
254    g_free(ldm.sound_daemon);
255    g_free(ldm.greeter_prog);
256    g_free(ldm.control_socket);
257    g_free(ldm.ipaddr);
258    g_list_foreach(host_list, (GFunc) g_free, NULL);
259    g_list_free(host_list);
260
261    exit(EXIT_SUCCESS);
262}
Note: See TracBrowser for help on using the repository browser.