1
/* LTSP Graphical GTK Greeter
2
* Copyright (C) 2007 Francis Giraldeau, <francis.giraldeau@revolutionlinux.com>
4
* - Queries servers to get information about them
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
31
#include <glib/gi18n.h>
32
#include <sys/utsname.h>
33
#include <sys/types.h>
35
#include <sys/ioctl.h>
41
ldminfo_init(GHashTable ** ldminfo_hash, GList ** host_list,
42
const char *ldm_server)
44
char **hosts_char = NULL;
45
ldminfo *ldm_host_info = NULL;
48
*ldminfo_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
50
hosts_char = g_strsplit(ldm_server, " ", -1);
52
for (i = 0; hosts_char != NULL && hosts_char[i] != NULL; i++) {
53
/* Initialize to default values */
54
ldm_host_info = g_new0(ldminfo, 1);
55
ldm_host_info->languages = NULL;
56
ldm_host_info->sessions = NULL;
57
ldm_host_info->rating = 0;
58
ldm_host_info->state = SRV_DOWN;
61
* Insert into the hash table.
64
g_hash_table_insert(*ldminfo_hash, g_strdup(hosts_char[i]),
68
* Populate the ldminfo structure, and determine if the host
72
_ldminfo_query_one(hosts_char[i], ldm_host_info);
75
* Add the host to the host list.
78
*host_list = g_list_append(*host_list, g_strdup(hosts_char[i]));
80
g_strfreev(hosts_char);
84
* Do the query for one host and fill ldminfo struct
85
* Note: for right now, we're reading files in /var/run/ldm. Francis would like
86
* the host detection closer to the login and checking network availability
87
* etc. What should happen here, for gutsy+1, is to call out to an
88
* external script. This script will query ldminfo, perform ssh port testing,
89
* etc. Things like nc -z hostname ssh, etc.
93
_ldminfo_query_one(const char *hostname, ldminfo * ldm_host_info)
95
int filedes, numbytes;
97
char hostfile[BUFSIZ];
99
snprintf(hostfile, sizeof hostfile, "/var/run/ldm/%s", hostname);
101
filedes = open(hostfile, O_RDONLY);
103
if ((numbytes = read(filedes, buf, MAXBUFSIZE - 1)) == -1) {
108
buf[numbytes] = '\0';
111
ldm_host_info->state = SRV_UP;
112
_ldminfo_parse_string(buf, ldm_host_info);
117
ldm_host_info->state = SRV_DOWN;
121
* split string by line and then construct the ldm_host_info
125
_ldminfo_parse_string(const char *s, ldminfo * ldm_host_info)
131
lines = g_strsplit(s, "\n", -1);
133
for (i = 0; lines != NULL && lines[i] != NULL; i++) {
134
if (!g_ascii_strncasecmp(lines[i], "language:", 9)) {
136
val = g_strsplit(lines[i], ":", 2);
137
ldm_host_info->languages =
138
g_list_append(ldm_host_info->languages, g_strdup(val[1]));
140
} else if (!g_ascii_strncasecmp(lines[i], "session:", 8)) {
142
val = g_strsplit(lines[i], ":", 2);
143
ldm_host_info->sessions =
144
g_list_append(ldm_host_info->sessions, g_strdup(val[1]));
146
} else if (!g_ascii_strncasecmp(lines[i], "rating:", 7)) {
148
val = g_strsplit(lines[i], ":", 2);
149
ldm_host_info->rating = atoi(val[1]);
152
/* Variable not supported */