summaryrefslogtreecommitdiff
path: root/hardinfo2
diff options
context:
space:
mode:
authorLeandro A. F. Pereira <leandro@hardinfo.org>2009-07-27 19:32:39 -0300
committerLeandro A. F. Pereira <leandro@hardinfo.org>2009-07-27 19:32:39 -0300
commit02b0029cce0ae3038758043f68cb8d8548e17393 (patch)
tree012f3e0ca767500ea6900e2c651ab5416f2e501f /hardinfo2
parent4e89125c9bec74053f8ddce3051e256f4071bd6a (diff)
Show SAMBA usershares
Diffstat (limited to 'hardinfo2')
-rw-r--r--hardinfo2/arch/linux/common/samba.h94
-rw-r--r--hardinfo2/network.c2
-rw-r--r--hardinfo2/shell.c2
3 files changed, 64 insertions, 34 deletions
diff --git a/hardinfo2/arch/linux/common/samba.h b/hardinfo2/arch/linux/common/samba.h
index 65cdc890..8e1f7111 100644
--- a/hardinfo2/arch/linux/common/samba.h
+++ b/hardinfo2/arch/linux/common/samba.h
@@ -17,57 +17,88 @@
*/
static gchar *smb_shares_list = NULL;
+
+void scan_samba_from_string(gchar *str, gsize length);
+void scan_samba_usershares(void);
+
+void
+scan_samba(void)
+{
+ gchar *str;
+ gsize length;
+
+ if (smb_shares_list) {
+ g_free(smb_shares_list);
+ smb_shares_list = g_strdup("");
+ }
+
+ if (g_file_get_contents("/etc/samba/smb.conf",
+ &str, &length, NULL)) {
+ scan_samba_from_string(str, length);
+ g_free(str);
+ }
+
+ scan_samba_usershares();
+}
+
void
-scan_samba_shared_directories(void)
+scan_samba_usershares(void)
+{
+ FILE *usershare_list;
+
+ if ((usershare_list = popen("net usershare list", "r"))) {
+ char buffer[512];
+
+ while (fgets(buffer, 512, usershare_list)) {
+ gchar *usershare, *cmdline;
+ gsize length;
+
+ cmdline = g_strdup_printf("net usershare info %s",
+ strend(buffer, '\n'));
+ if (g_spawn_command_line_sync(cmdline,
+ &usershare, NULL,
+ NULL, NULL)) {
+ length = strlen(usershare);
+ scan_samba_from_string(usershare, length);
+ g_free(usershare);
+ }
+
+ g_free(cmdline);
+ }
+
+ pclose(usershare_list);
+ }
+}
+
+void
+scan_samba_from_string(gchar *str, gsize length)
{
GKeyFile *keyfile;
GError *error = NULL;
gchar **groups;
- gchar *smbconf;
- gsize length = -1;
gint i = 0;
-
- if (smb_shares_list) {
- g_free(smb_shares_list);
- }
keyfile = g_key_file_new();
- if (!g_file_get_contents("/etc/samba/smb.conf", &smbconf, &length, &error) || length == 0) {
- smb_shares_list = g_strdup("Cannot open /etc/samba/smb.conf=\n");
- if (error)
- g_error_free(error);
- goto cleanup;
- }
-
- gchar *_smbconf = smbconf;
+ gchar *_smbconf = str;
for (; *_smbconf; _smbconf++)
if (*_smbconf == ';') *_smbconf = '\0';
- if (!g_key_file_load_from_data(keyfile, smbconf, length, 0, &error)) {
+ if (!g_key_file_load_from_data(keyfile, str, length, 0, &error)) {
smb_shares_list = g_strdup("Cannot parse smb.conf=\n");
if (error)
g_error_free(error);
goto cleanup;
}
- smb_shares_list = g_strdup("");
-
groups = g_key_file_get_groups(keyfile, NULL);
while (groups[i]) {
- if (g_key_file_has_key(keyfile, groups[i], "path", NULL) &&
- g_key_file_has_key(keyfile, groups[i], "available", NULL)) {
-
- gchar *available = g_key_file_get_string(keyfile, groups[i], "available", NULL);
-
- if (g_str_equal(available, "yes")) {
- gchar *path = g_key_file_get_string(keyfile, groups[i], "path", NULL);
- smb_shares_list = g_strconcat(smb_shares_list, groups[i], "=",
- path, "\n", NULL);
- g_free(path);
- }
-
- g_free(available);
+ if (g_key_file_has_key(keyfile, groups[i], "path", NULL)) {
+ gchar *path = g_key_file_get_string(keyfile, groups[i], "path", NULL);
+ smb_shares_list = h_strdup_cprintf("%s=%s\n",
+ smb_shares_list,
+ groups[i], path);
+ g_free(path);
}
i++;
@@ -77,6 +108,5 @@ scan_samba_shared_directories(void)
cleanup:
g_key_file_free(keyfile);
- g_free(smbconf);
}
diff --git a/hardinfo2/network.c b/hardinfo2/network.c
index 8325ca76..556a7723 100644
--- a/hardinfo2/network.c
+++ b/hardinfo2/network.c
@@ -70,7 +70,7 @@ static ModuleEntry entries[] = {
void scan_shares(gboolean reload)
{
SCAN_START();
- scan_samba_shared_directories();
+ scan_samba();
scan_nfs_shared_directories();
SCAN_END();
}
diff --git a/hardinfo2/shell.c b/hardinfo2/shell.c
index 58c05df0..9e2ecbe6 100644
--- a/hardinfo2/shell.c
+++ b/hardinfo2/shell.c
@@ -1460,7 +1460,7 @@ static void module_selected(gpointer data)
RANGE_SET_VALUE(moreinfo, vscrollbar, 0.0);
RANGE_SET_VALUE(moreinfo, hscrollbar, 0.0);
- title = g_strdup_printf("%s - %s", shell->selected_module_name, entry->name);
+ title = g_strdup_printf("%s: %s", shell->selected_module_name, entry->name);
shell_set_title(shell, title);
g_free(title);