#include "messages.h"
#include <ccan/hash/hash.h>
#include "libcli/security/security.h"
+#include "serverid.h"
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
- struct event_context *ev_ctx,
+ struct tevent_context *ev_ctx,
bool parent_longlived)
{
NTSTATUS status = NT_STATUS_OK;
}
}
-/****************************************************************************
- Interpret a protocol description string, with a default.
-****************************************************************************/
-
-int interpret_protocol(const char *str,int def)
-{
- if (strequal(str,"NT1"))
- return(PROTOCOL_NT1);
- if (strequal(str,"LANMAN2"))
- return(PROTOCOL_LANMAN2);
- if (strequal(str,"LANMAN1"))
- return(PROTOCOL_LANMAN1);
- if (strequal(str,"CORE"))
- return(PROTOCOL_CORE);
- if (strequal(str,"COREPLUS"))
- return(PROTOCOL_COREPLUS);
- if (strequal(str,"CORE+"))
- return(PROTOCOL_COREPLUS);
-
- DEBUG(0,("Unrecognised protocol level %s\n",str));
-
- return(def);
-}
-
-
#if (defined(HAVE_NETGROUP) && defined(WITH_AUTOMOUNT))
/******************************************************************
Remove any mount options such as -rsize=2048,wsize=2048 etc.
{
char *value = NULL;
- char *nis_map = (char *)lp_nis_home_map_name();
+ char *nis_map = (char *)lp_homedir_map();
char buffer[NIS_MAXATTRVAL + 1];
nis_result *result;
char *nis_result; /* yp_match inits this */
int nis_result_len; /* and set this */
char *nis_domain; /* yp_get_default_domain inits this */
- char *nis_map = (char *)lp_nis_home_map_name();
+ char *nis_map = lp_homedir_map(talloc_tos());
if ((nis_error = yp_get_default_domain(&nis_domain)) != 0) {
DEBUG(3, ("YP Error: %s\n", yperr_string(nis_error)));
#endif /* WITH_NISPLUS_HOME */
#endif
-/****************************************************************************
- Check if a process exists. Does this work on all unixes?
-****************************************************************************/
-
bool process_exists(const struct server_id pid)
{
- if (procid_is_me(&pid)) {
- return True;
- }
-
- if (procid_is_local(&pid)) {
- return (kill(pid.pid,0) == 0 || errno != ESRCH);
- }
-
-#ifdef CLUSTER_SUPPORT
- return ctdbd_process_exists(messaging_ctdbd_connection(),
- pid.vnn, pid.pid);
-#else
- return False;
-#endif
-}
-
-bool processes_exist(const struct server_id *pids, int num_pids,
- bool *results)
-{
- struct server_id *remote_pids = NULL;
- int *remote_idx = NULL;
- bool *remote_results = NULL;
- int i, num_remote_pids;
- bool result = false;
-
- remote_pids = talloc_array(talloc_tos(), struct server_id, num_pids);
- if (remote_pids == NULL) {
- goto fail;
- }
- remote_idx = talloc_array(talloc_tos(), int, num_pids);
- if (remote_idx == NULL) {
- goto fail;
- }
- remote_results = talloc_array(talloc_tos(), bool, num_pids);
- if (remote_results == NULL) {
- goto fail;
- }
-
- num_remote_pids = 0;
-
- for (i=0; i<num_pids; i++) {
- if (procid_is_me(&pids[i])) {
- results[i] = true;
- continue;
- }
- if (procid_is_local(&pids[i])) {
- results[i] = ((kill(pids[i].pid,0) == 0) ||
- (errno != ESRCH));
- continue;
- }
-
- remote_pids[num_remote_pids] = pids[i];
- remote_idx[num_remote_pids] = i;
- num_remote_pids += 1;
- }
-
- if (num_remote_pids != 0) {
-#ifdef CLUSTER_SUPPORT
- if (!ctdb_processes_exist(messaging_ctdbd_connection(),
- remote_pids, num_remote_pids,
- remote_results)) {
- goto fail;
- }
-#else
- for (i=0; i<num_remote_pids; i++) {
- remote_results[i] = false;
- }
-#endif
-
- for (i=0; i<num_remote_pids; i++) {
- results[remote_idx[i]] = remote_results[i];
- }
- }
-
- result = true;
-fail:
- TALLOC_FREE(remote_results);
- TALLOC_FREE(remote_idx);
- TALLOC_FREE(remote_pids);
- return result;
+ return serverid_exists(&pid);
}
/*******************************************************************
prctl(PR_SET_PTRACER, getpid(), 0, 0, 0);
#endif
- cmd = lp_panic_action();
+ cmd = lp_panic_action(talloc_tos());
if (cmd && *cmd) {
DEBUG(0, ("smb_panic(): calling panic action [%s]\n", cmd));
result = system(cmd);
char *myhostname_upper(void)
{
- char *name;
static char *ret;
if (ret == NULL) {
- name = get_myname(talloc_tos());
+ char *name = get_myname(NULL);
+ if (name == NULL) {
+ return NULL;
+ }
ret = strupper_talloc(NULL, name);
talloc_free(name);
}
trim_string(fname,"","/");
if (!directory_exist(fname)) {
- if (!mkdir(fname,0755))
- DEBUG(1, ("Unable to create directory %s for file %s. "
- "Error was %s\n", fname, name, strerror(errno)));
+ if (mkdir(fname,0755) == -1) {
+ /* Did someone else win the race ? */
+ if (errno != EEXIST) {
+ DEBUG(1, ("Unable to create directory %s for file %s. "
+ "Error was %s\n", fname, name, strerror(errno)));
+ return NULL;
+ }
+ }
}
- return talloc_asprintf(talloc_tos(),
- "%s/%s",
- fname,
- name);
+ return talloc_asprintf_append(fname, "/%s", name);
}
/**
char *lock_path(const char *name)
{
- return xx_path(name, lp_lockdir());
+ return xx_path(name, lp_lock_directory());
}
/**
char *state_path(const char *name)
{
- return xx_path(name, lp_statedir());
+ return xx_path(name, lp_state_directory());
}
/**
char *cache_path(const char *name)
{
- return xx_path(name, lp_cachedir());
+ return xx_path(name, lp_cache_directory());
}
/*******************************************************************
TALLOC_FREE(ctx);
return false;
}
- strlower_m(p2);
- strlower_m(s2);
+ if (!strlower_m(p2)) {
+ TALLOC_FREE(ctx);
+ return false;
+ }
+ if (!strlower_m(s2)) {
+ TALLOC_FREE(ctx);
+ return false;
+ }
/* Remove any *? and ** from the pattern as they are meaningless */
for(p = p2; *p; p++) {
struct server_id interpret_pid(const char *pid_string)
{
- struct server_id result;
- unsigned long long pid;
- unsigned int vnn, task_id = 0;
-
- ZERO_STRUCT(result);
-
- /* We accept various forms with 1, 2 or 3 component forms
- * because the server_id_str() can print different forms, and
- * we want backwards compatibility for scripts that may call
- * smbclient. */
- if (sscanf(pid_string, "%u:%llu.%u", &vnn, &pid, &task_id) == 3) {
- result.vnn = vnn;
- result.pid = pid;
- result.task_id = task_id;
- } else if (sscanf(pid_string, "%u:%llu", &vnn, &pid) == 2) {
- result.vnn = vnn;
- result.pid = pid;
- result.task_id = 0;
- } else if (sscanf(pid_string, "%llu.%u", &pid, &task_id) == 2) {
- result.vnn = get_my_vnn();
- result.pid = pid;
- result.task_id = task_id;
- } else if (sscanf(pid_string, "%llu", &pid) == 1) {
- result.vnn = get_my_vnn();
- result.pid = pid;
- } else {
- result.vnn = NONCLUSTER_VNN;
- result.pid = (uint64_t)-1;
- }
- return result;
+ return server_id_from_string(get_my_vnn(), pid_string);
}
char *procid_str_static(const struct server_id *pid)
}
return cpy;
}
+
+/****************************************************************************
+ Check that a file matches a particular file type.
+****************************************************************************/
+
+bool dir_check_ftype(uint32_t mode, uint32_t dirtype)
+{
+ uint32_t mask;
+
+ /* Check the "may have" search bits. */
+ if (((mode & ~dirtype) &
+ (FILE_ATTRIBUTE_HIDDEN |
+ FILE_ATTRIBUTE_SYSTEM |
+ FILE_ATTRIBUTE_DIRECTORY)) != 0) {
+ return false;
+ }
+
+ /* Check the "must have" bits,
+ which are the may have bits shifted eight */
+ /* If must have bit is set, the file/dir can
+ not be returned in search unless the matching
+ file attribute is set */
+ mask = ((dirtype >> 8) & (FILE_ATTRIBUTE_DIRECTORY|
+ FILE_ATTRIBUTE_ARCHIVE|
+ FILE_ATTRIBUTE_READONLY|
+ FILE_ATTRIBUTE_HIDDEN|
+ FILE_ATTRIBUTE_SYSTEM)); /* & 0x37 */
+ if(mask) {
+ if((mask & (mode & (FILE_ATTRIBUTE_DIRECTORY|
+ FILE_ATTRIBUTE_ARCHIVE|
+ FILE_ATTRIBUTE_READONLY|
+ FILE_ATTRIBUTE_HIDDEN|
+ FILE_ATTRIBUTE_SYSTEM))) == mask) {
+ /* check if matching attribute present */
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ return true;
+}