File 0005-fix-pthread-calls.patch of Package sblim-cmpi-samba
From 8ea498f60d3feff8933805c5a5b793e4740bd331 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Klaus=20K=C3=A4mpf?= <kkaempf@gmail.com>
Date: Fri, 21 Feb 2025 19:57:26 +0100
Subject: [PATCH 5/5] fix pthread calls
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Klaus Kämpf <kkaempf@gmail.com>
---
resource-access/smt_smb_ra_support.c | 488 +++++++++++++--------------
1 file changed, 244 insertions(+), 244 deletions(-)
diff --git a/resource-access/smt_smb_ra_support.c b/resource-access/smt_smb_ra_support.c
index e1e3166..6b5943e 100644
--- a/resource-access/smt_smb_ra_support.c
+++ b/resource-access/smt_smb_ra_support.c
@@ -90,7 +90,7 @@ static int create_service(const char* service);
/* Helper functions */
void free_smbopt_list(struct smbopt *list){
-
+
struct smbopt *next;
while(list){
@@ -108,7 +108,7 @@ static char *my_script_path(char *script){
if (!smb_conf)
smb_conf = read_conf(CONFFILE,CONFFILE);
return script_path(smb_conf,script);
-
+
}
@@ -132,13 +132,13 @@ static char **add_string_array(char **array, const char *elem){
}
while ( array[i++] );
-
+
array = (char**) realloc(array,(i+1)*sizeof(char*));
if (!array){
errno = -ENOMEM;
return NULL;
}
-
+
array[i-1] = strdup(elem);
if (!array[i-1]){
errno = -ENOMEM;
@@ -174,7 +174,7 @@ static char **remove_string_array(char **array, const char *name){
}
current++;
}
-
+
array[++last] = NULL;
/* We need one more element for terminating NULL */
array = (char**) realloc(array, ((current+1)-count)*sizeof(char*));
@@ -193,7 +193,7 @@ static int __create_path(const char *path){
while (mpath) {
cur_dir = strsep(&mpath,"/");
-
+
if( strlen(cur_dir) ) {
strcat(built_path,"/");
strcat(built_path,cur_dir);
@@ -223,13 +223,13 @@ static int __check_path(const char *path){
asprintf(&root_path,"/%s",path);
abs_path = (char *) limited_canonicalize_path(root_path);
-
+
ret = stat(abs_path,&status);
if (!ret) goto out; /* path exists */
-
- if (errno == ENOENT )
+
+ if (errno == ENOENT )
ret = __create_path(abs_path);
-
+
out:
free(root_path);
free(abs_path);
@@ -249,7 +249,7 @@ static int start_monitor(struct monitor **monitor, char *filename){
static void free_monitors_cache(struct smbcache *cache){
struct smbmonitors *tmp, *monitor = (struct smbmonitors*) cache->content;
-
+
while (monitor){
free(monitor->service);
free_smbopt_list(monitor->opts);
@@ -268,7 +268,7 @@ static void free_monitors_cache(struct smbcache *cache){
static void free_map_cache(struct smbcache *cache){
-
+
struct smbopt *pp, *p = (struct smbopt*) cache->content;
while(p){
@@ -288,7 +288,7 @@ static void free_map_cache(struct smbcache *cache){
}
static struct smbopt *__create_smbopt(const char *key, const char *value){
-
+
struct smbopt *opt = (struct smbopt *) malloc ( sizeof(struct smbopt) );
if (opt){
@@ -298,7 +298,7 @@ static struct smbopt *__create_smbopt(const char *key, const char *value){
free(opt->key); free(opt->value); free(opt);
opt = NULL;
errno = -ENOMEM;
- }
+ }
}
return opt;
@@ -350,7 +350,7 @@ static struct smbopt *g_synonyms(int pipefd){
}
}
-
+
out:
free(buf_ptr);
fclose(fp);
@@ -413,9 +413,9 @@ static struct smbopt *g_map(int pipefd){
head = map;
head->next = NULL;
}else
- list_add(head,map);
+ list_add(head,map);
}
-
+
out:
free(buf_ptr);
fclose(fp);
@@ -428,17 +428,17 @@ static struct smbopt *g_map(int pipefd){
static char *get_official_name(const char *syn){
/* Checks the synonym list and returns the official name of the option. If no
* entry is found in the list, we return the name passed as argument */
-
+
struct smbopt *synlist;
if (!synonyms) synonyms = (struct smbopt*) get_synonyms_array();
-
+
synlist = synonyms;
while(synlist){
if (!strcasecmp(syn,synlist->key)) return synlist->value;
synlist = synlist->next;
}
-
+
return (char*) syn;
}
@@ -448,10 +448,10 @@ static struct smbopt *g_service(FILE *fp){
char *chr;
char *buf,*buf_ptr = malloc(1024);
struct smbopt *share_opts,*head = NULL;
-
+
if (!fp)
return NULL;
-
+
head = NULL;
while (!feof(fp)){
@@ -459,14 +459,14 @@ static struct smbopt *g_service(FILE *fp){
buf=fgets(buf,1024,fp);
if (!buf || !strncmp(buf,"ENDSHARE",8))
break;
-
+
chr = strrchr(buf,';');
if (!chr)
break;
chr = strrchr(buf,'\n');
if (chr)
*chr = '\0';
-
+
if (!head){
head = (struct smbopt*)malloc(sizeof(struct smbopt));
head->key = strdup(get_official_name(strsep(&buf,";")));
@@ -482,7 +482,7 @@ static struct smbopt *g_service(FILE *fp){
}
}
free(buf_ptr);
- return head;
+ return head;
}
@@ -491,10 +491,10 @@ struct smbmonitors *g_cache_info(int pipefd){
struct smbmonitors *mon,*elem;
char *chr,*buf,*buf_ptr = malloc(1024);
FILE *fp = fdopen(pipefd,"r");
-
+
struct timeval tv = {2,0};
fd_set fset;
-
+
mon = NULL;
FD_ZERO(&fset);
FD_SET(fileno(fp),&fset);
@@ -507,18 +507,18 @@ struct smbmonitors *g_cache_info(int pipefd){
while (!feof(fp)){
buf = buf_ptr;
buf = fgets(buf,1024,fp);
-
+
if (!buf || !strncmp(buf,"SMBEOF",6))
break;
chr = strrchr(buf,'\n');
if (chr)
*chr = '\0';
-
- /* There are 2 cases to handle here. In the first, we do not find a
+
+ /* There are 2 cases to handle here. In the first, we do not find a
* semicolon in the line. It means we're in front of a sharename. Store it.
* If it's not the case, call a helper function to fill the linked list */
- chr = strchr(buf,';');
+ chr = strchr(buf,';');
if (!chr){
elem = (struct smbmonitors *)malloc(sizeof(struct smbmonitors));
elem->service = strdup(buf);
@@ -530,7 +530,7 @@ struct smbmonitors *g_cache_info(int pipefd){
list_add(mon,elem);
}
}
-
+
out:
free(buf_ptr);
fclose(fp);
@@ -544,7 +544,7 @@ static struct smbopt *g_defaults(int pipefd){
struct smbopt *opts = NULL;
char *chr,*buf,*buf_ptr = malloc(1024);
FILE *fp = fdopen(pipefd,"r");
-
+
struct timeval tv = {2,0};
fd_set fset;
@@ -559,25 +559,25 @@ static struct smbopt *g_defaults(int pipefd){
while (!feof(fp)){
buf = buf_ptr;
buf=fgets(buf,1024,fp);
-
+
if (!buf || !strncmp(buf,"SMBEOF",6))
break;
chr = strrchr(buf,'\n');
if (chr)
*chr = '\0';
-
- /* There are 2 cases to handle here. In the first, we do not find a
- * semicolon in the line. It means we're in front of a "sharename". The
+
+ /* There are 2 cases to handle here. In the first, we do not find a
+ * semicolon in the line. It means we're in front of a "sharename". The
* share name was put into the defaults file in order to reuse the scripts
- * that already existed to read a file with that structure; we just Ignore
+ * that already existed to read a file with that structure; we just Ignore
* the share name. If it's not the case, call a helper function to fill the
* linked list */
- chr = strchr(buf,';');
+ chr = strchr(buf,';');
if (!chr)
opts = g_service(fp);
- }
-
+ }
+
out:
free(buf_ptr);
fclose(fp);
@@ -592,19 +592,19 @@ static void *g_single_val_per_line_list(int pipefd){
char **list = (char **)malloc(sizeof(char *));
int i=0;
FILE *fp = fdopen(pipefd,"r");
-
+
struct timeval tv = {2,0};
fd_set fset;
-
+
if (!fp) goto out;
-
+
FD_ZERO(&fset);
FD_SET(fileno(fp),&fset);
if (!select(fileno(fp)+1,&fset,NULL,NULL,&tv)){
errno = -EAGAIN;
goto out;
}
-
+
while (!feof(fp)){
buf=buf_ptr;
buf=fgets(buf,1024,fp);
@@ -619,7 +619,7 @@ static void *g_single_val_per_line_list(int pipefd){
free(buf_ptr);
fclose(fp);
//close(pipefd);
- return (void *) list;
+ return (void *) list;
}
@@ -641,7 +641,7 @@ static void f_cache(int pipefd){
fputs(buf,fp);
}
service = service->next;
- }
+ }
fclose(fp);
//close(pipefd);
}
@@ -684,19 +684,19 @@ static void f_groupmap_cache(int pipefd){
static int flush_usermap_cache(){
/* It's easier to use python to put the usermap file back in order */
-
+
char *script = my_script_path("smt_smb_ra_set_user_mappings.py");
int ret = 0;
if (!usermap_cache.content || !usermap_cache.is_dirty) goto out;
-
+
if (writeData1(script,__get_option(GLOBAL,USERNAME_MAP),f_usermap_cache))
ret = -1;
-
+
/* the file has changed on disk because we wrote to it. Check and ignore */
check_events(usermap_file_monitor);
usermap_cache.is_dirty = 0;
-
+
out:
free(script);
return ret;
@@ -732,9 +732,9 @@ static int flush_smb_cache() {
}
-static void usermap_cache_flusher(void *arg){
+static void *usermap_cache_flusher(void *arg){
/* This function is to be used as a thread. We expect a (smbcache*) as
- * argument */
+ * argument */
struct smbcache *cache = (struct smbcache*) arg;
int ret=0, cache_flush_interval;
@@ -747,7 +747,7 @@ static void usermap_cache_flusher(void *arg){
free(tmp);
}else
cache_flush_interval = CACHE_DFL;
-
+
printf("Using cache interval of %d for usermap\n",cache_flush_interval);
while(1){
@@ -765,9 +765,9 @@ static void usermap_cache_flusher(void *arg){
}
-static void smb_cache_flusher(void *arg){
+static void *smb_cache_flusher(void *arg){
/* This function is to be used as a thread. We expect a (smbcache*) as
- * argument */
+ * argument */
int ret=0, cache_flush_interval;
struct smbcache *cache = (struct smbcache*) arg;
@@ -780,7 +780,7 @@ static void smb_cache_flusher(void *arg){
free(tmp);
}else
cache_flush_interval = CACHE_DFL;
-
+
printf("Using cache interval of %d for smb.conf cache\n",cache_flush_interval);
while(1){
@@ -873,7 +873,7 @@ static void clean_up(){
free_array_elements(global_printers_list);
free_array(global_printers_list);
}
-
+
/* free linked lists and conf*/
if (synonyms) free_smbopt_list(synonyms);
if (defaults) free_smbopt_list(defaults);
@@ -884,7 +884,7 @@ static void clean_up(){
free_monitors_cache(&monitors_cache);
pthread_mutex_unlock(&monitors_cache.mutex);
pthread_mutex_destroy(&monitors_cache.mutex);
-
+
pthread_mutex_lock(&usermap_cache.mutex);
free_map_cache(&usermap_cache);
pthread_mutex_unlock(&usermap_cache.mutex);
@@ -915,13 +915,13 @@ static struct smbopt *get_usermap_list(){
char *username_map, *script = my_script_path("smt_smb_ra_get_user_mappings.py");
struct smbopt *stounix = NULL;
-
- /* we can use g_synonyms to read it because smt_smb_ra_get_user_mappings.py
+
+ /* we can use g_synonyms to read it because smt_smb_ra_get_user_mappings.py
* outputs data in the same format expected by g_synonyms */
username_map = __get_option(GLOBAL,USERNAME_MAP);
if (!username_map) goto out;
stounix = (struct smbopt*) readData1(script,username_map,(void*)g_synonyms);
-
+
out:
free(script);
return stounix;
@@ -931,11 +931,11 @@ static struct smbopt *get_usermap_list(){
static struct smbopt *__get_groupmap_list(){
char *script = my_script_path("smt_smb_ra_get_group_mappings.py");
-
- /* we can use g_synonyms to read it because smt_smb_ra_get_group_mappings.py
+
+ /* we can use g_synonyms to read it because smt_smb_ra_get_group_mappings.py
* outputs data in the same format expected by g_synonyms */
struct smbopt *stounix = (struct smbopt*) readData1(script,GET_GRPMAP_CMD,
- (void*)g_map);
+ (void*)g_map);
free(script);
return stounix;
@@ -943,8 +943,8 @@ static struct smbopt *__get_groupmap_list(){
static int init_usermap_cache(struct smbcache *cache){
- /* Callers of this function should have gotten a lock from the cache mutex
- * first */
+ /* Callers of this function should have gotten a lock from the cache mutex
+ * first */
int ret = 0;
char *map, *usermap_file = __get_option(GLOBAL,USERNAME_MAP);
@@ -954,16 +954,16 @@ static int init_usermap_cache(struct smbcache *cache){
if (ret) goto out;
}else
map = strdup(usermap_file);
-
+
/* initialize file monitor*/
if (!usermap_file_monitor)
start_monitor(&usermap_file_monitor,usermap_file);
- /*set up threading */
+ /*set up threading */
if (pthread_create(&(cache->thread),NULL,usermap_cache_flusher,&usermap_cache)){
free(cache);
goto out;
- }
+ }
cache->thread_running = 1;
cache->content = (void *) get_usermap_list();
cache->is_dirty = 0;
@@ -975,7 +975,7 @@ static int init_usermap_cache(struct smbcache *cache){
static int init_groupmap_cache(struct smbcache *cache){
-
+
char *filename;
int ret = 0;
@@ -991,14 +991,14 @@ static int init_groupmap_cache(struct smbcache *cache){
cache->content = (void *) __get_groupmap_list();
cache->is_dirty = 0;
-
+
free(filename);
return ret;
}
static int populate_cache(struct smbcache *cache){
- /* We go to the file, and go agressively. Get all the information in the
+ /* We go to the file, and go agressively. Get all the information in the
* file, and store it in the cache. This initializes the cache flusher
* thread. Callers of this function should have gotten a lock from the cache
* mutex first */
@@ -1026,7 +1026,7 @@ static int populate_cache(struct smbcache *cache){
static struct smbopt *find_in_cache(struct smbcache *cache, const char *service){
- /* Search the global monitor for a specified cache hit. Finding it in the
+ /* Search the global monitor for a specified cache hit. Finding it in the
* structure DOES NOT mean it is up to date. */
struct smbmonitors *monitor = (struct smbmonitors *) cache->content;
@@ -1035,7 +1035,7 @@ static struct smbopt *find_in_cache(struct smbcache *cache, const char *service)
if (!strcasecmp(monitor->service,service))
return monitor->opts;
}
-
+
return NULL;
}
@@ -1065,7 +1065,7 @@ static struct smbcache *__get_usermap_cache(){
static struct smbcache *__get_groupmap_cache(){
-
+
int ret = 0;
pthread_mutex_lock(&(groupmap_cache.mutex));
@@ -1089,7 +1089,7 @@ static struct smbcache *__get_groupmap_cache(){
static char **__g_samba_groups_list(){
-
+
char **list = (char **)malloc(sizeof(char *));
struct smbcache *cache = (struct smbcache*) __get_groupmap_cache();
struct smbopt *grp = (struct smbopt*) cache->content;
@@ -1107,27 +1107,27 @@ static char **__g_samba_groups_list(){
static struct smbopt *get_defaults_array(void){
- /* If the default values array is null, build it. We use
- * smt_smb_ra_get_all_services.py to parse it because the default file is
+ /* If the default values array is null, build it. We use
+ * smt_smb_ra_get_all_services.py to parse it because the default file is
* built using the same smb.conf structure */
char *script = my_script_path("smt_smb_ra_get_all_services.py");
char *filename = get_conf(smb_conf,SMBDEFAULTS);
-
+
struct smbopt *dfl = (struct smbopt*) readData1(script,filename,(void*)g_defaults);
free(script);
free(filename);
return dfl;
-}
+}
static char *get_default_value(const char* opt){
- char *script = NULL;
+ char *script = NULL;
struct smbopt *dfl;
-
+
if(!defaults){
script = my_script_path("smt_smb_ra_get_defaults.sh");
if ( execScript((const char*)script) ){
@@ -1145,7 +1145,7 @@ static char *get_default_value(const char* opt){
return dfl->value;
dfl = dfl->next;
}
-
+
errno = -ENOOPT;
return NULL;
}
@@ -1156,7 +1156,7 @@ static struct smbcache *__get_monitors_cache(){
int ret = 0;
pthread_mutex_lock(&(monitors_cache.mutex));
-
+
if (!monitors_cache.content)
ret = populate_cache(&monitors_cache);
else if (!check_events(services_list_monitor)) {
@@ -1188,7 +1188,7 @@ static char **__g_system_users_list(){
static char **__g_cups_printers_list(){
-
+
char **ret = NULL;
char *script = my_script_path("smt_smb_ra_get_sys_printers.py");
@@ -1205,7 +1205,7 @@ static char **__g_system_groups_list(){
char *script = my_script_path("smt_smb_ra_get_db_entries.py");
ret = (char**) readData1(script,GET_SYSGRPS_CMD,g_single_val_per_line_list);
-
+
free(script);
return ret;
}
@@ -1218,7 +1218,7 @@ static char **__g_samba_users_list(){
struct smbopt *p = NULL;
struct smbcache *cache = __get_usermap_cache();
int lErrno = 0;
-
+
ret = (char**) readData1(script,GET_SMBUSRS_CMD,g_single_val_per_line_list);
if (!ret) {
lErrno = errno;
@@ -1231,12 +1231,12 @@ static char **__g_samba_users_list(){
else p = (struct smbopt *) cache->content;
/* by now we have samba users defined in samba. Still need to get the samba
* users defined in the user mappings */
- //p = (struct smbopt *) cache->content;
+ //p = (struct smbopt *) cache->content;
while(p){
ret = add_string_array(ret,(const char*)p->key);
p = p->next;
}
-
+
free(script);
return ret;
}
@@ -1248,7 +1248,7 @@ static char **get_services_list(){
char **list = (char **)malloc(sizeof(char *));
struct smbcache *cache = __get_monitors_cache();
int i=0;
-
+
if (!cache) return NULL;
pthread_mutex_lock(&cache->mutex);
@@ -1290,14 +1290,14 @@ static char *__g_option(const char *service, const char *opt){
if (!opt) {
return NULL;
}
-
+
pthread_mutex_lock(&cache->mutex);
for (opt_list = find_in_cache(cache,service); opt_list; opt_list = opt_list->next)
if (!strcasecmp(opt_list->key,opt)){
value = opt_list->value;
break;
}
-
+
pthread_mutex_unlock(&cache->mutex);
return value;
}
@@ -1311,7 +1311,7 @@ static char *__get_option(const char *service, const char *opt){
value = __g_option(service, official);
if (!value /*|| may_override(official) */){
- gvalue = __g_option(GLOBAL, official);
+ gvalue = __g_option(GLOBAL, official);
if (gvalue) {
return gvalue;
// } else if {
@@ -1338,7 +1338,7 @@ char *get_option(const char *service, const char *opt){
char *get_default_option(const char *opt) {
char *official, *value;
-
+
official = get_official_name(opt);
value = get_default_value(official);
@@ -1351,7 +1351,7 @@ char *get_global_option(const char *opt){
static int __check_default_and_global(const char *service, const char *key, const char *value){
- /*
+ /*
Return 0 Is different to global value and/or default value
Return 1 Equals to default value and/or global value
*/
@@ -1360,7 +1360,7 @@ static int __check_default_and_global(const char *service, const char *key, cons
char *default_value = get_default_value(key);
if (strcasecmp(GLOBAL,service) == 0) {
- if ( default_value && strcasecmp(value,default_value) == 0 ) {
+ if ( default_value && strcasecmp(value,default_value) == 0 ) {
return 1;
}
else {
@@ -1384,11 +1384,11 @@ static int __set_option_no_cache(const char *service, const char *key, const cha
char *script = my_script_path("smt_smb_ra_set_option.py");
char *filename = get_conf(smb_conf,SMBCONF);
-
+
if (service_exists(service) ) return -EINVAL;
return execScript4(script,filename,service,key,value);
-
+
}
@@ -1404,7 +1404,7 @@ static int __set_option_in_cache(struct smbcache *cache, const char *service, co
if ( !strcasecmp(monitor->service,service) ){
/* found service */
first = opt = monitor->opts;
-
+
for(; opt; last = opt, opt = opt->next) {
if ( !strcasecmp(key,opt->key) ) {
/* opt exists, update */
@@ -1423,7 +1423,7 @@ static int __set_option_in_cache(struct smbcache *cache, const char *service, co
free(opt->key); free(opt->value); free(opt);
}
ret = 0;
- cache->is_dirty = 1;
+ cache->is_dirty = 1;
goto out;
}
}
@@ -1444,7 +1444,7 @@ static int __set_option_in_cache(struct smbcache *cache, const char *service, co
break;
}
}
-
+
out:
return ret;
}
@@ -1459,14 +1459,14 @@ static int __set_option(const char *service, const char *key, const char *value)
struct smbcache *cache = __get_monitors_cache();
// if (!cache) return -ENOENT;
-
+
/* check if the new option is a default. If it is and there's a global opt
* of the same value, it does not need to be in the opt_list. If there's
* a global value different from the default, then we need to write the opt
* anyway. If value is NULL we should remove the entry (-1) */
if (value) whattodo = __check_default_and_global(service,official,value);
-
+
switch(whattodo){
case 0:
mvalue = strdup(value);
@@ -1485,13 +1485,13 @@ static int __set_option(const char *service, const char *key, const char *value)
ret = __set_option_in_cache(cache,service,official, mvalue);
pthread_mutex_unlock(&(cache->mutex));
}
-
+
return ret;
}
int set_option(const char* service, const char *key, const char *value){
-
+
int ret;
pthread_mutex_lock(&glob_mutex);
@@ -1503,7 +1503,7 @@ int set_option(const char* service, const char *key, const char *value){
int set_global_option(const char *key, const char *value){
-
+
int ret;
pthread_mutex_lock(&glob_mutex);
@@ -1515,29 +1515,29 @@ int set_global_option(const char *key, const char *value){
static int __delete_service_no_cache(const char *name){
-
+
char *filename = get_conf(smb_conf,SMBCONF);
char *script = my_script_path("smt_smb_ra_delete_service.py");
int i,ret = -ENOENT;
char **s_list;
-
+
if (!strcasecmp(name,GLOBAL))
goto out;
-
+
for (s_list = get_services_list(), i=0; s_list[i]; i++)
if (!strcasecmp(s_list[i],name))
ret = execScript2(script,filename,name);
-
+
out:
- return ret;
+ return ret;
}
-static int __delete_service_in_cache(struct smbcache *cache,
+static int __delete_service_in_cache(struct smbcache *cache,
const char *name ){
/* This function has to update everything in cache cause the monitors only
* detect changes in disk files */
-
+
struct smbmonitors *first, *cur, *last = NULL;
struct smbopt *opts, *curopt;
int ret = -EINVAL;
@@ -1552,7 +1552,7 @@ static int __delete_service_in_cache(struct smbcache *cache,
}
if (!cur) goto out;
-
+
if (cur==first) cache->content = cur->next;
else last->next = cur->next;
@@ -1575,7 +1575,7 @@ static int __delete_service_in_cache(struct smbcache *cache,
ret = 0;
out:
return ret;
-
+
}
@@ -1602,27 +1602,27 @@ static int __create_service_no_cache(const char *name){
char *filename = get_conf(smb_conf,SMBCONF);
char **s_list = NULL;
int i,ret;
- FILE *fp;
-
+ FILE *fp;
+
/* check if a service with this name already exists */
ret = -EINVAL;
for (s_list = get_services_list(), i=0; s_list && s_list[i]; i++)
if (!strcasecmp(s_list[i],name))
goto out;
-
+
fp = fopen(filename,"a");
if (!fp){
ret = errno;
goto out;
}
-
- fprintf(fp,"[%s]\n",name);
+
+ fprintf(fp,"[%s]\n",name);
fclose(fp);
ret = 0;
-
+
out:
return ret;
-
+
}
@@ -1659,7 +1659,7 @@ static int __create_service_in_cache(struct smbcache *cache, const char *name ){
return ret;
err:
- if(service) {
+ if(service) {
if(service->service) free(service->service);
free(service);
}
@@ -1690,7 +1690,7 @@ int disable_service(const char *share){
char *script = my_script_path("smt_smb_ra_disable.py");
if (!strcasecmp(share,GLOBAL))
return -EINVAL;
-
+
return execScript2(script,filename,share);
}
@@ -1703,12 +1703,12 @@ int enable_service(const char *share){
int service_exists(const char *name){
-
+
char **services;
int i = 0, ret=0;
-
+
if (!name) return 0;
-
+
pthread_mutex_lock(&glob_mutex);
services = get_services_list();
@@ -1718,12 +1718,12 @@ int service_exists(const char *name){
break;
}
}
-
+
if(!ret && !strcasecmp(name,"global")) {
create_service("global");
ret=1;
}
-
+
pthread_mutex_unlock(&glob_mutex);
return ret;
}
@@ -1777,7 +1777,7 @@ int validHostName(const char* host_name) {
/* *_share : For a while, simple wrappers for _service functions */
char **get_shares_list(){
-
+
char **shares_list = (char **) malloc(sizeof(char *));
char **all_services;
char *printable = NULL;
@@ -1832,7 +1832,7 @@ int add_share(const char *name){
pthread_mutex_lock(&glob_mutex);
ret = create_service(name);
pthread_mutex_unlock(&glob_mutex);
-
+
return ret;
}
@@ -1846,7 +1846,7 @@ int set_share_option(const char *share, const char *key, const char *value){
ret = __set_option(share,key,value);
if (ret) goto out;
-
+
if (!strcasecmp(key,PATH) ){
c = strchr(value,'%');
if (c) goto out; /*a variable substitution will occur in runtime. Leave it*/
@@ -1878,19 +1878,19 @@ static char **__get_cups_printer_list(){
char **get_cups_printer_list(){
-
+
char **value;
-
+
pthread_mutex_lock(&glob_mutex);
value = __get_cups_printer_list();
pthread_mutex_unlock(&glob_mutex);
-
+
return value;
}
char **get_samba_printers_list(){
-
+
char **printer_list = (char **) malloc(sizeof(char *));
char **all_services;
char *printable = NULL;
@@ -1908,7 +1908,7 @@ char **get_samba_printers_list(){
}
printer_list[j] = (char *) NULL;
- pthread_mutex_lock(&printers_list_mutex);
+ pthread_mutex_lock(&printers_list_mutex);
if(global_printers_list){
free_array_elements(global_printers_list);
free_array(global_printers_list);
@@ -1926,7 +1926,7 @@ int add_samba_printer(const char* name){
int ret;
pthread_mutex_lock(&glob_mutex);
-
+
ret = create_service(name);
if (ret) goto out;
@@ -1958,7 +1958,7 @@ int set_printer_option(const char *name, const char* key, const char *value){
return ret;
}
-
+
static int __entry_exists(const char *username, char **list){
/* Returns 1 if true or 0 if false */
@@ -1981,13 +1981,13 @@ static int __remove_usermap_reverse(const char *unix_name){
pthread_mutex_lock(&(cache->mutex));
p = (struct smbopt*) cache->content;
-
+
while(p){
-
+
if ( !strcmp(unix_name,p->value) ){
- if (p==cache->content)
+ if (p==cache->content)
cache->content = (void*) p->next;
- else
+ else
last->next = p->next;
if(p){
if(p->key) free(p->key);
@@ -2002,13 +2002,13 @@ static int __remove_usermap_reverse(const char *unix_name){
}
cache->is_dirty = 1;
- pthread_mutex_unlock(&(cache->mutex));
+ pthread_mutex_unlock(&(cache->mutex));
return 0;
}
static int __remove_usermap(const char *samba_name){
- /* Returns 0 on success. Returns -1 if no samba user was found with the
+ /* Returns 0 on success. Returns -1 if no samba user was found with the
* specified name */
struct smbopt *p,*last = NULL;
@@ -2018,7 +2018,7 @@ static int __remove_usermap(const char *samba_name){
pthread_mutex_lock(&(cache->mutex));
p = (struct smbopt*) cache->content;
-
+
while(p){
if (!strcmp(samba_name,p->key)) break;
last = p;
@@ -2027,7 +2027,7 @@ static int __remove_usermap(const char *samba_name){
if (p==cache->content) cache->content = (void*) p->next;
else last->next = p->next;
-
+
if(p){
if(p->key) free(p->key);
if(p->value) free(p->value);
@@ -2042,32 +2042,32 @@ static int __remove_usermap(const char *samba_name){
static int __add_usermap(const char *samba_name, const char *unix_name){
- /* Returns 0 on success or an error code on falilure */
+ /* Returns 0 on success or an error code on falilure */
struct smbopt *newEntry = NULL;
struct smbcache *cache = __get_usermap_cache();
int ret = -ENOMEM;
-
+
pthread_mutex_lock(&(cache->mutex));
newEntry = (struct smbopt*) malloc(sizeof(struct smbopt));
if (!newEntry) goto out;
-
+
newEntry->next = NULL;
newEntry->key = strdup(samba_name);
newEntry->value = strdup(unix_name);
if (!newEntry->key || !newEntry->value) goto out;
-
+
list_add(cache->content, newEntry);
cache->is_dirty = 1;
ret = 0;
out:
if (ret && newEntry){
- if(newEntry->key) free(newEntry->key);
+ if(newEntry->key) free(newEntry->key);
if(newEntry->value) free(newEntry->value);
free(newEntry);
- }
+ }
pthread_mutex_unlock(&(cache->mutex));
return ret;
}
@@ -2084,14 +2084,14 @@ static int __create_sys_user(const char *user){
}
static int __create_smb_user(const char *user, const char *password){
-
+
char *script = my_script_path("smt_smb_ra_create_samba_user.py");
int ret;
ret = execScript2(script,user,password);
free(script);
return ret;
-}
+}
static int __delete_smb_user(const char *user){
@@ -2139,7 +2139,7 @@ static char *__get_user_unix_name(const char* samba_user){
char *get_user_unix_name(const char* samba_user){
char *value;
-
+
pthread_mutex_lock(&glob_mutex);
value = __get_user_unix_name(samba_user);
pthread_mutex_unlock(&glob_mutex);
@@ -2156,7 +2156,7 @@ static char **__get_samba_users_list(){
* it in order not to leak memory */
pthread_mutex_lock(&samba_users_list_mutex);
-
+
if (global_samba_users_list){
free_array_elements(global_samba_users_list);
free_array(global_samba_users_list);
@@ -2194,32 +2194,32 @@ static char **__get_system_users_list(){
* times. Although we don't cache the return array, we need to keep track of
* it in order not to leak memory */
- pthread_mutex_lock(&system_users_list_mutex);
+ pthread_mutex_lock(&system_users_list_mutex);
if (global_system_users_list){
free_array_elements(global_system_users_list);
free_array(global_system_users_list);
}
-
+
global_system_users_list = __g_system_users_list();
- pthread_mutex_unlock(&system_users_list_mutex);
+ pthread_mutex_unlock(&system_users_list_mutex);
return global_system_users_list;
}
char **get_system_users_list(){
-
+
char **value;
-
+
pthread_mutex_lock(&glob_mutex);
value = __get_system_users_list();
pthread_mutex_unlock(&glob_mutex);
-
+
return value;
}
-int modify_samba_user(const char *samba_name, const char *unix_name_cur,
+int modify_samba_user(const char *samba_name, const char *unix_name_cur,
const char *unix_name_new, const char *password){
char **system_users, **samba_users;
@@ -2240,7 +2240,7 @@ int modify_samba_user(const char *samba_name, const char *unix_name_cur,
}
/*if (!unix_name_cur) unix_name_cur = samba_name;
-
+
if (!__entry_exists(unix_name_cur,system_users)) {
ret = -ENOENT;
goto out;
@@ -2277,7 +2277,7 @@ int modify_samba_user(const char *samba_name, const char *unix_name_cur,
}
-int add_samba_user(const char *samba_name, const char *unix_name,
+int add_samba_user(const char *samba_name, const char *unix_name,
const char *password){
char **system_users, **samba_users;
@@ -2296,7 +2296,7 @@ int add_samba_user(const char *samba_name, const char *unix_name,
ret = -EEXIST;
goto out;
}
-
+
if (!unix_name) unix_name = strdup(samba_name);
/* verify if unix_name is a valid system user */
@@ -2304,14 +2304,14 @@ int add_samba_user(const char *samba_name, const char *unix_name,
ret = -ENOENT;
goto out;
}
-
+
/* create unix user if needed. If you want to make it possible to create
system users, comment the above verification and uncomment this */
if (!__entry_exists(unix_name,system_users) ){
ret = __create_sys_user(unix_name);
if (ret) goto out;
}
-
+
/* add unix user to samba */
if (!__entry_exists(unix_name,samba_users) ){
ret = __create_smb_user(unix_name,password);
@@ -2329,7 +2329,7 @@ int add_samba_user(const char *samba_name, const char *unix_name,
int delete_samba_user(const char *samba_user){
-
+
char *unix_user;
char **samba_users;
int ret = 0;
@@ -2345,28 +2345,28 @@ int delete_samba_user(const char *samba_user){
ret = -ENOENT;
goto out;
}
-
+
unix_user = __get_user_unix_name(samba_user);
if (!strcmp(samba_user,unix_user) ){
/* This is a samba user that maps directly to a unix user. Take it out from
* samba database and also any other users that map to it */
-
+
ret = __remove_usermap_reverse(unix_user);
if (ret) goto out;
-
+
ret = __delete_smb_user(unix_user);
}else{
/* This is a usermap name. Delete it from usermap only */
-
+
ret = __remove_usermap(samba_user);
}
-
+
out:
pthread_mutex_unlock(&glob_mutex);
return ret;
-
+
}
@@ -2374,14 +2374,14 @@ static char *get_group_mapping_reverse(const char* unix_group){
struct smbopt *p = NULL;
struct smbcache *cache = __get_groupmap_cache();
-
+
p = (struct smbopt *) cache->content;
-
+
while(p){
if (!strcmp(unix_group,p->value)) return p->key;
else p = p->next;
}
-
+
return NULL;
}
@@ -2407,7 +2407,7 @@ static char *__get_unix_group_name(const char* samba_group){
char *get_unix_group_name(const char* samba_group){
-
+
char *value;
pthread_mutex_lock(&glob_mutex);
@@ -2421,10 +2421,10 @@ char *get_unix_group_name(const char* samba_group){
static char **__get_samba_groups_list(){
/* We don't implement a cache for this function since it will be called few
* times. Although we don't cache the return array, we need to keep track of
- * it in order not to leak memory. global_samba_groups_list a an array of
+ * it in order not to leak memory. global_samba_groups_list a an array of
* references to samba_groupmap_cache; therefore, we NEVER free the contents
* of each position, we free only the array itself */
-
+
pthread_mutex_lock(&samba_groups_list_mutex);
if (global_samba_groups_list){
@@ -2440,13 +2440,13 @@ static char **__get_samba_groups_list(){
char **get_samba_groups_list(){
-
+
char **value;
- pthread_mutex_lock(&glob_mutex);
+ pthread_mutex_lock(&glob_mutex);
value = __get_samba_groups_list();
- pthread_mutex_unlock(&glob_mutex);
-
+ pthread_mutex_unlock(&glob_mutex);
+
return value;
}
@@ -2462,7 +2462,7 @@ static char **__get_system_groups_list(){
free_array_elements(global_system_groups_list);
free_array(global_system_groups_list);
}
-
+
global_system_groups_list = __g_system_groups_list();
pthread_mutex_unlock(&system_groups_list_mutex);
@@ -2471,13 +2471,13 @@ static char **__get_system_groups_list(){
char **get_system_groups_list(){
-
+
char **value;
-
- pthread_mutex_lock(&glob_mutex);
+
+ pthread_mutex_lock(&glob_mutex);
value = __get_system_groups_list();
- pthread_mutex_unlock(&glob_mutex);
-
+ pthread_mutex_unlock(&glob_mutex);
+
return value;
}
@@ -2517,7 +2517,7 @@ static char **__get_user_groups(const char *user){
free_array_elements(user_groups);
free_array(user_groups);
}
-
+
sys_grps = __get_user_sys_groups(unix_username);
for(i=0; sys_grps && sys_grps[i]; i++){
@@ -2528,7 +2528,7 @@ static char **__get_user_groups(const char *user){
}
smb_grps[j] = NULL;
user_groups = smb_grps;
-
+
free_array_elements(sys_grps);
free_array(sys_grps);
@@ -2558,24 +2558,24 @@ int set_group_mapping(const char *samba_grp, const char *unix_grp){
char **smb_grps, **unx_grps;
int ret = -EINVAL;
- pthread_mutex_lock(&glob_mutex);
+ pthread_mutex_lock(&glob_mutex);
if (!samba_grp) goto out;
-
+
smb_grps = __get_samba_groups_list();
unx_grps = __get_system_groups_list();
if (!__entry_exists(samba_grp,smb_grps) ) goto out;
if (unix_grp && !__entry_exists(unix_grp,unx_grps) ) goto out;
-
+
if (unix_grp)
ret = execScript2(script,samba_grp,unix_grp);
else
ret = execScript1(script,samba_grp);
- out:
+ out:
free(script);
- pthread_mutex_unlock(&glob_mutex);
+ pthread_mutex_unlock(&glob_mutex);
return ret;
}
@@ -2639,7 +2639,7 @@ int create_samba_group(const char* samba_grp, const char *unix_grp){
char create_sys_grp[] = "0"; //Leave this as 0 in order NOT to create new
//system groups
- pthread_mutex_lock(&glob_mutex);
+ pthread_mutex_lock(&glob_mutex);
smb_grps = __get_samba_groups_list();
unx_grps = __get_system_groups_list();
@@ -2667,7 +2667,7 @@ int create_samba_group(const char* samba_grp, const char *unix_grp){
out:
free(script);
- pthread_mutex_unlock(&glob_mutex);
+ pthread_mutex_unlock(&glob_mutex);
return ret;
}
@@ -2679,7 +2679,7 @@ int delete_samba_group(const char* samba_grp){
char **smb_grps;
int ret;
- pthread_mutex_lock(&glob_mutex);
+ pthread_mutex_lock(&glob_mutex);
smb_grps = __get_samba_groups_list();
if (!__entry_exists(samba_grp, smb_grps) ) {
@@ -2689,7 +2689,7 @@ int delete_samba_group(const char* samba_grp){
if (!smb_conf) smb_conf = read_conf(CONFFILE,CONFFILE);
groupmap_file = get_conf(smb_conf,SMBGRPMAP);
- if (!groupmap_file)
+ if (!groupmap_file)
groupmap_file = strdup(DEF_SMBGRPMAPF);
ret = execScript2(script,samba_grp,groupmap_file);
@@ -2697,7 +2697,7 @@ int delete_samba_group(const char* samba_grp){
out:
free(script);
free(groupmap_file);
- pthread_mutex_unlock(&glob_mutex);
+ pthread_mutex_unlock(&glob_mutex);
return ret;
}
@@ -2713,7 +2713,7 @@ int add_user_to_group(const char *samba_user, const char *samba_group){
return -EINVAL; //We have disabled this function. It should not be used for
//now. Take this out to start using it again
- pthread_mutex_lock(&glob_mutex);
+ pthread_mutex_lock(&glob_mutex);
usr_grps = __get_user_groups(samba_user);
if (!usr_grps && errno) goto out;
smb_users = __get_samba_users_list();
@@ -2723,7 +2723,7 @@ int add_user_to_group(const char *samba_user, const char *samba_group){
if (!__entry_exists(samba_user,smb_users) ) goto out;
if (!__entry_exists(samba_group,smb_groups) ) goto out;
if (__entry_exists(samba_group,usr_grps) ) goto out;
-
+
unix_user = __get_user_unix_name(samba_user);
unix_group = __get_unix_group_name(samba_group);
@@ -2731,7 +2731,7 @@ int add_user_to_group(const char *samba_user, const char *samba_group){
out:
free(script);
- pthread_mutex_unlock(&glob_mutex);
+ pthread_mutex_unlock(&glob_mutex);
return ret;
}
@@ -2746,38 +2746,38 @@ int remove_user_from_group(const char *samba_user, const char *samba_group){
return -EINVAL; //We have disabled this function. It should not be used for
//now. Take this out to start using it again
- pthread_mutex_lock(&glob_mutex);
+ pthread_mutex_lock(&glob_mutex);
usr_grps = __get_user_groups(samba_user);
if (!usr_grps && errno) goto out;
smb_users = __get_samba_users_list();
if (!smb_users && errno) goto out;
smb_groups = __get_samba_groups_list();
-
+
if (!__entry_exists(samba_user,smb_users) ) goto out;
if (!__entry_exists(samba_group,smb_groups) ) goto out;
if (!__entry_exists(samba_group,usr_grps) ) goto out;
-
+
unix_user = __get_user_unix_name(samba_user);
unix_group = __get_unix_group_name(samba_group);
ret = execScript2(script,unix_user,unix_group);
out:
free(script);
- pthread_mutex_unlock(&glob_mutex);
+ pthread_mutex_unlock(&glob_mutex);
return ret;
}
int start_server(){
-
+
char *configured_service = NULL, *service, *nmb, *dname, *copy;
struct stat status;
int ret = 1;
- if ( status_server() ) return 0; /* return success if server already up */
-
+ if ( status_server() ) return 0; /* return success if server already up */
+
configured_service = get_conf(smb_conf,SMB_SERVICE);
-
+
if (!configured_service) service = strdup(SMB_DEF); /*fall back to default*/
else service = strdup(configured_service);
@@ -2787,17 +2787,17 @@ int start_server(){
nmb = (char*) malloc((strlen(dname)+strlen("/nmb")+1)*sizeof(char));
sprintf(nmb,"%s/nmb",dname);
- if ( !stat(nmb,&status) ){
+ if ( !stat(nmb,&status) ){
ret = execScript1(nmb,"start");
if (ret) goto out;
}
-
+
/*samba service*/
if ( stat(service,&status) ){
ret = 1;
goto out;
- }else ret = execScript1(service,"start");
-
+ }else ret = execScript1(service,"start");
+
out:
free(copy);
free(service);
@@ -2808,15 +2808,15 @@ int start_server(){
int stop_server(){
-
+
char *configured_service = NULL, *service, *nmb, *dname, *copy;
struct stat status;
int ret = 1;
if ( !status_server() ) return 0; /* return success if server already down */
-
+
configured_service = get_conf(smb_conf,SMB_SERVICE);
-
+
if (!configured_service) service = strdup(SMB_DEF); /*fall back to default*/
else service = strdup(configured_service);
@@ -2825,18 +2825,18 @@ int stop_server(){
dname = dirname(copy);
nmb = (char*) malloc((strlen(dname)+strlen("/nmb")+1)*sizeof(char));
sprintf(nmb,"%s/nmb",dname);
-
- if ( !stat(nmb,&status) ){
+
+ if ( !stat(nmb,&status) ){
ret = execScript1(nmb,"stop");
if (ret) goto out;
}
-
+
/*samba service*/
if ( stat(service,&status) ){
ret = 1;
goto out;
- }else ret = execScript1(service,"stop");
-
+ }else ret = execScript1(service,"stop");
+
out:
free(copy);
free(service);
@@ -2849,9 +2849,9 @@ int restart_server(){
char *configured_service = NULL, *service, *nmb, *dname, *copy;
struct stat status;
int ret = 1;
-
+
configured_service = get_conf(smb_conf,SMB_SERVICE);
-
+
if (!configured_service) service = strdup(SMB_DEF); /*fall back to default*/
else service = strdup(configured_service);
@@ -2860,53 +2860,53 @@ int restart_server(){
dname = dirname(copy);
nmb = (char*) malloc((strlen(dname)+strlen("/nmb")+1)*sizeof(char));
sprintf(nmb,"%s/nmb",dname);
- if ( !stat(nmb,&status) ){
+ if ( !stat(nmb,&status) ){
ret = execScript1(nmb,"restart");
if (ret) goto out;
}
-
+
/*samba service*/
if ( stat(service,&status) ){
ret = 1;
goto out;
- }else ret = execScript1(service,"restart");
-
+ }else ret = execScript1(service,"restart");
+
out:
free(copy);
free(service);
return ret;
}
-
+
int status_server(){
char *configured_service = NULL, *service, *nmb, *dname, *copy;
struct stat status;
int nret = 1, sret, ret=0;
-
+
configured_service = get_conf(smb_conf,SMB_SERVICE);
-
+
if (!configured_service) service = strdup(SMB_DEF); /*fall back to default*/
else service = strdup(configured_service);
-
+
/* samba version compatibility check. Look for nmb */
copy = strdup(service);
dname = dirname(copy);
nmb = (char*) malloc((strlen(dname)+strlen("/nmb")+1)*sizeof(char));
sprintf(nmb,"%s/nmb",dname);
-
- if ( !stat(nmb,&status) ){
+
+ if ( !stat(nmb,&status) ){
nret = !execScript1(nmb,"status");
}
-
+
/*samba service*/
if ( stat(service,&status) ){
sret = 0;
goto out;
- }else sret = !execScript1(service,"status");
-
+ }else sret = !execScript1(service,"status");
+
if (nret*sret!=0) ret = 1;
-
+
out:
free(copy);
free(service);
--
2.48.1