summaryrefslogtreecommitdiffstats
path: root/sfshare-daemon/src/samba_share.c
diff options
context:
space:
mode:
Diffstat (limited to 'sfshare-daemon/src/samba_share.c')
-rw-r--r--sfshare-daemon/src/samba_share.c152
1 files changed, 81 insertions, 71 deletions
diff --git a/sfshare-daemon/src/samba_share.c b/sfshare-daemon/src/samba_share.c
index d2ccac5..592f53e 100644
--- a/sfshare-daemon/src/samba_share.c
+++ b/sfshare-daemon/src/samba_share.c
@@ -1,5 +1,21 @@
-#include <string.h> /* strlen, strstr */
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+#include <string.h> /* strlen, strstr */
#include <stdlib.h> /* system() call */
#include <glib.h>
@@ -8,6 +24,7 @@
#include "samba_share.h"
#include "sfshare_errors.h"
+/* Define */
#define SECTIONS_COUNT 3 /* Count of special sections in smb.conf */
#define KEYWORDS_COUNT 6 /* Count of keywords used for setup share in smb.conf */
@@ -31,7 +48,8 @@ const gchar *smb_special_section [SECTIONS_COUNT] = {"global", "homes", "printer
/* Send SIGHUP to smb and nmb */
-void smb_reload_service ()
+void
+smb_reload_service ()
{
system("killall -HUP smb nmb");
}
@@ -39,7 +57,8 @@ void smb_reload_service ()
/*
* Function changes path to smb.conf to path
*/
-void set_smbconf_path (const gchar *path)
+void
+set_smbconf_path (const gchar *path)
{
smb_conf_path = g_strdup(path);
}
@@ -48,12 +67,13 @@ void set_smbconf_path (const gchar *path)
/*
* Save string str as new smb.conf
*/
-gint write_smbconf (const gchar *content)
+gint
+write_smbconf (const gchar *content)
{
FILE *smb_file;
/* smb.conf - File exist test */
- if(!g_file_test(smb_conf_path, G_FILE_TEST_EXISTS))
+ if(!g_file_test (smb_conf_path, G_FILE_TEST_EXISTS))
{
g_warning ("Config file \"%s\" does not exist!", smb_conf_path);
return ERROR_FILE_NOT_EXIST;
@@ -68,7 +88,7 @@ gint write_smbconf (const gchar *content)
}
/* Write to smb.conf */
- if(fputs(content,smb_file) == EOF)
+ if(fputs (content,smb_file) == EOF)
{
g_warning ("Can not write to file \"%s\"!", smb_conf_path);
return ERROR_CAN_NOT_WRITE_TO_FILE;
@@ -83,7 +103,8 @@ gint write_smbconf (const gchar *content)
/*
* Function free TSmbConfItem from memmory
*/
-void smbconf_item_free(TSmbConfItem *item)
+void
+smbconf_item_free(TSmbConfItem *item)
{
g_string_free(item->guest_ok, TRUE);
g_string_free(item->writable, TRUE);
@@ -99,7 +120,8 @@ void smbconf_item_free(TSmbConfItem *item)
/*
* Function allocs memory for TSmbConfItem
*/
-TSmbConfItem* smbconf_item_new0 ()
+TSmbConfItem*
+smbconf_item_new0 ()
{
TSmbConfItem *ret;
ret = g_malloc(sizeof(struct smb_conf_item));
@@ -118,7 +140,8 @@ TSmbConfItem* smbconf_item_new0 ()
/*
* Function allocs memory for TSmbConfItem
*/
-TSmbConfItem* smbconf_item_new (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok)
+TSmbConfItem*
+smbconf_item_new (const gchar *name, const gchar *path, const gchar *comment, const gchar *read_only, const gchar *guest_ok)
{
TSmbConfItem *ret;
ret = g_malloc(sizeof(struct smb_conf_item));
@@ -142,7 +165,8 @@ TSmbConfItem* smbconf_item_new (const gchar *name, const gchar *path, const gcha
/*
* Function returns new array
*/
-GPtrArray* shared_items_array_new()
+GPtrArray*
+shared_items_array_new ()
{
GPtrArray *ret = g_ptr_array_new();
return ret;
@@ -152,14 +176,15 @@ GPtrArray* shared_items_array_new()
/*
* Destroy array
*/
-void shared_items_array_free(GPtrArray *array)
+void
+shared_items_array_free (GPtrArray *array)
{
TSmbConfItem *tmp;
- int i;
+ gint i;
for(i = 0; i < array->len; i++)
{
- tmp = g_ptr_array_index(array,i);
- smbconf_item_free(tmp);
+ tmp = g_ptr_array_index (array,i);
+ smbconf_item_free (tmp);
}
g_ptr_array_free(array, TRUE);
@@ -187,9 +212,9 @@ gint check_item(TSmbConfItem *item)
/*
* Parse line of smb.conf and fill competent field of item structure
-* return id of keyword found on line (txt)
*/
-void ParseShareItem(gchar *txt, TSmbConfItem *item)
+void
+ParseShareItem(gchar *txt, TSmbConfItem *item)
{
gchar *lower = g_ascii_strdown(txt, strlen(txt));
gboolean found = FALSE;
@@ -303,7 +328,8 @@ void ParseShareItem(gchar *txt, TSmbConfItem *item)
/*
* Funciton loads all share section to array
*/
-gint load_smb_conf (GPtrArray *shared_items)
+gint
+load_smb_conf (GPtrArray *shared_items)
{
FILE *smb_file; /* Samba config file */
@@ -313,7 +339,7 @@ gint load_smb_conf (GPtrArray *shared_items)
gint arr_index = shared_items->len - 1; /* Count of items in shared_items array - 1; */
/* smb.conf - File exist test */
- if(!g_file_test(smb_conf_path, G_FILE_TEST_EXISTS))
+ if (!g_file_test(smb_conf_path, G_FILE_TEST_EXISTS))
{
g_warning ("Config file \"%s\" not exist!", smb_conf_path);
return ERROR_FILE_NOT_EXIST;
@@ -321,7 +347,7 @@ gint load_smb_conf (GPtrArray *shared_items)
/* Try open smb.conf */
smb_file = fopen(smb_conf_path, "r");
- if(smb_file == NULL)
+ if (smb_file == NULL)
{
g_warning ("Can not open file \"%s\"!", smb_conf_path);
return ERROR_CAN_NOT_OPEN_FILE;
@@ -331,7 +357,7 @@ gint load_smb_conf (GPtrArray *shared_items)
line = g_strnfill(BUFSIZ, '\0');
/* Parse smb.conf file and load shared folders setings */
- while(fgets(line, BUFSIZ, smb_file))
+ while (fgets(line, BUFSIZ, smb_file))
{
/* Remove white space */
g_strstrip(line);
@@ -345,8 +371,8 @@ gint load_smb_conf (GPtrArray *shared_items)
skip = FALSE;
/* Test special sections */
- int i ;
- for(i = 0; i < SECTIONS_COUNT; i++)
+ gint i ;
+ for (i = 0; i < SECTIONS_COUNT; i++)
{
if(strstr(line,smb_special_section[i]) != NULL)
{
@@ -395,12 +421,13 @@ gint load_smb_conf (GPtrArray *shared_items)
* Returns share imte if directory [path] is shared,
* if not return NULL;
*/
-TSmbConfItem *is_shared_item(GPtrArray *shared_items, const gchar *path)
+TSmbConfItem
+*is_shared_item(GPtrArray *shared_items, const gchar *path)
{
TSmbConfItem *ret = NULL;
TSmbConfItem *tmp;
- int i;
+ gint i;
for(i = 0; i < shared_items->len; i++)
{
tmp = g_ptr_array_index(shared_items,i);
@@ -422,7 +449,7 @@ gboolean
share_name_exist (GPtrArray *shared_items, const gchar *sharename)
{
TSmbConfItem *tmp;
- int i;
+ gint i;
for(i = 0; i < shared_items->len; i++)
{
tmp = g_ptr_array_index(shared_items,i);
@@ -516,26 +543,22 @@ write_share(GPtrArray *shared_items, TSmbConfItem *share)
if(!writed_change[COMMENT_ID] && (share->comment->len > 0))
{
- g_sprintf(tmp,"\tcomment = %s\n",share->comment->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tcomment = %s\n",share->comment->str);
}
if(!writed_change[READ_ONLY_ID] && (share->read_only->len > 0))
{
- g_sprintf(tmp,"\tcomment = %s\n",share->read_only->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tread only = %s\n",share->read_only->str);
}
if(!writed_change[WRTITABLE_ID] && (share->writable->len > 0))
{
- g_sprintf(tmp,"\tcomment = %s\n",share->writable->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\twritable = %s\n",share->writable->str);
}
if(!writed_change[GUEST_OK_ID] && (share->guest_ok->len > 0))
{
- g_sprintf(tmp,"\tcomment = %s\n",share->guest_ok->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tguest ok = %s\n",share->guest_ok->str);
}
}
@@ -576,9 +599,7 @@ write_share(GPtrArray *shared_items, TSmbConfItem *share)
/* [share name] */
case SHARE_NAME_ID:
{
- g_sprintf(tmp,"[%s]\n",share->name->str);
- g_string_append(smb_conf_new,tmp);
-
+ g_string_append_printf(smb_conf_new, "[%s]\n",share->name->str);
writed_change[SHARE_NAME_ID] = TRUE;
}
break;
@@ -599,8 +620,8 @@ write_share(GPtrArray *shared_items, TSmbConfItem *share)
{
if(share->comment->len > 0)
{
- g_sprintf(tmp,"\tcomment = %s\n",share->comment->str);
- g_string_append(smb_conf_new,tmp);
+
+ g_string_append_printf(smb_conf_new, "\tcomment = %s\n",share->comment->str);
writed_change[COMMENT_ID] = TRUE;
}
}
@@ -613,8 +634,7 @@ write_share(GPtrArray *shared_items, TSmbConfItem *share)
if(share->read_only->len > 0)
{
- g_sprintf(tmp,"\tread only = %s\n",share->read_only->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tread only = %s\n",share->read_only->str);
writed_change[READ_ONLY_ID] = TRUE;
}
}
@@ -626,8 +646,7 @@ write_share(GPtrArray *shared_items, TSmbConfItem *share)
{
if(share->writable->len > 0)
{
- g_sprintf(tmp,"\twritable = %s\n",share->writable->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\twritable = %s\n",share->writable->str);
writed_change[WRTITABLE_ID] = TRUE;
}
}
@@ -639,8 +658,7 @@ write_share(GPtrArray *shared_items, TSmbConfItem *share)
{
if(share->guest_ok->len > 0)
{
- g_sprintf(tmp,"\tguest ok = %s\n",share->guest_ok->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tguest ok = %s\n",share->guest_ok->str);
writed_change[GUEST_OK_ID] = TRUE;
}
}
@@ -656,68 +674,60 @@ write_share(GPtrArray *shared_items, TSmbConfItem *share)
g_free(orig);
}
- if(!check_writed_changes && change)
- {
+ if(!check_writed_changes && change)
+ {
/* Section name and path are allways writed */
if(!writed_change[COMMENT_ID] && (share->comment->len > 0))
{
- g_sprintf(tmp,"\tcomment = %s\n",share->comment->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tcomment = %s\n",share->comment->str);
}
if(!writed_change[READ_ONLY_ID] && (share->read_only->len > 0))
{
- g_sprintf(tmp,"\tcomment = %s\n",share->read_only->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tread only = %s\n",share->read_only->str);
}
if(!writed_change[WRTITABLE_ID] && (share->writable->len > 0))
{
- g_sprintf(tmp,"\tcomment = %s\n",share->writable->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\twritable = %s\n",share->writable->str);
}
if(!writed_change[GUEST_OK_ID] && (share->guest_ok->len > 0))
{
- g_sprintf(tmp,"\tcomment = %s\n",share->guest_ok->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tguest ok = %s\n",share->guest_ok->str);
}
- }
+ }
/* Create new share */
if(new_share)
{
- g_sprintf(tmp,"\n[%s]\n",share->name->str);
- g_string_append(smb_conf_new,tmp);
- g_sprintf(tmp,"\tpath = %s\n",share->path->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\n[%s]\n",share->name->str);
+
+ g_string_append_printf(smb_conf_new, "\tpath = %s\n",share->path->str);
+
if(share->comment->len > 0)
{
- g_sprintf(tmp,"\tcomment = %s\n",share->comment->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tcomment = %s\n",share->comment->str);
}
if(share->read_only->len > 0)
{
- g_sprintf(tmp,"\tread only = %s\n",share->read_only->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tread only = %s\n",share->read_only->str);
}
if(share->writable->len > 0)
{
- g_sprintf(tmp,"\twritable = %s\n",share->writable->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\twritable = %s\n",share->writable->str);
}
if(share->guest_ok->len > 0)
{
- g_sprintf(tmp,"\tguest ok = %s\n",share->guest_ok->str);
- g_string_append(smb_conf_new,tmp);
+ g_string_append_printf(smb_conf_new, "\tguest ok = %s\n",share->guest_ok->str);
}
}
@@ -852,7 +862,7 @@ smb_get_share_status (const gchar *path, gchar ***result)
gboolean found = FALSE;
GPtrArray *shared_items = shared_items_array_new();
- Error err;
+ Error_sfshare err;
err = load_smb_conf (shared_items);
@@ -865,7 +875,7 @@ smb_get_share_status (const gchar *path, gchar ***result)
TSmbConfItem *test;
- int i;
+ gint i;
for (i = 0; i < shared_items->len; i++)
{
test = g_ptr_array_index(shared_items, i);
@@ -892,7 +902,7 @@ smb_get_share_status (const gchar *path, gchar ***result)
* Write share to smb.conf
*/
gint
-smb_set_share (const gchar **parameters)
+smb_set_share (gchar **parameters)
{
gint ret = OK;
/* Create new items array */
@@ -921,7 +931,7 @@ smb_set_share (const gchar **parameters)
* Delete share to smb.conf
*/
gint
-smb_delete_share (const gchar **path)
+smb_delete_share (gchar **path)
{
gint ret = OK;
/* Create new items array */