enum protocol_types Protocol = PROTOCOL_COREPLUS;
-/* a default finfo structure to ensure all fields are sensible */
-file_info def_finfo;
-
/* this is used by the chaining code */
int chain_size = 0;
-int trans_num = 0;
-
static enum remote_arch_types ra_type = RA_UNKNOWN;
/***********************************************************************
SAFE_FREE( smb_myworkgroup );
SAFE_FREE( smb_scope );
free_netbios_names_array();
+ free_local_machine_name();
}
void gfree_all( void )
{
- gfree_names();
+ gfree_names();
gfree_loadparm();
gfree_case_tables();
- gfree_debugsyms();
gfree_charcnv();
gfree_interfaces();
-
- /* release the talloc null_context memory last */
- talloc_disable_null_tracking();
+ gfree_debugsyms();
}
const char *my_netbios_names(int i)
return( True );
}
+/**************************************************************************n
+ Code to cope with username/password auth options from the commandline.
+ Used mainly in client tools.
+****************************************************************************/
+
+static struct user_auth_info cmdline_auth_info = {
+ NULL, /* username */
+ NULL, /* password */
+ false, /* got_pass */
+ false, /* use_kerberos */
+ Undefined, /* signing state */
+ false, /* smb_encrypt */
+ false /* use machine account */
+};
+
+const char *get_cmdline_auth_info_username(void)
+{
+ if (!cmdline_auth_info.username) {
+ return "";
+ }
+ return cmdline_auth_info.username;
+}
+
+void set_cmdline_auth_info_username(const char *username)
+{
+ SAFE_FREE(cmdline_auth_info.username);
+ cmdline_auth_info.username = SMB_STRDUP(username);
+ if (!cmdline_auth_info.username) {
+ exit(ENOMEM);
+ }
+}
+
+const char *get_cmdline_auth_info_password(void)
+{
+ if (!cmdline_auth_info.password) {
+ return "";
+ }
+ return cmdline_auth_info.password;
+}
+
+void set_cmdline_auth_info_password(const char *password)
+{
+ SAFE_FREE(cmdline_auth_info.password);
+ cmdline_auth_info.password = SMB_STRDUP(password);
+ if (!cmdline_auth_info.password) {
+ exit(ENOMEM);
+ }
+ cmdline_auth_info.got_pass = true;
+}
+
+bool set_cmdline_auth_info_signing_state(const char *arg)
+{
+ cmdline_auth_info.signing_state = -1;
+ if (strequal(arg, "off") || strequal(arg, "no") ||
+ strequal(arg, "false")) {
+ cmdline_auth_info.signing_state = false;
+ } else if (strequal(arg, "on") || strequal(arg, "yes") ||
+ strequal(arg, "true") || strequal(arg, "auto")) {
+ cmdline_auth_info.signing_state = true;
+ } else if (strequal(arg, "force") || strequal(arg, "required") ||
+ strequal(arg, "forced")) {
+ cmdline_auth_info.signing_state = Required;
+ } else {
+ return false;
+ }
+ return true;
+}
+
+int get_cmdline_auth_info_signing_state(void)
+{
+ return cmdline_auth_info.signing_state;
+}
+
+void set_cmdline_auth_info_use_kerberos(bool b)
+{
+ cmdline_auth_info.use_kerberos = b;
+}
+
+bool get_cmdline_auth_info_use_kerberos(void)
+{
+ return cmdline_auth_info.use_kerberos;
+}
+
+/* This should only be used by lib/popt_common.c JRA */
+void set_cmdline_auth_info_use_krb5_ticket(void)
+{
+ cmdline_auth_info.use_kerberos = true;
+ cmdline_auth_info.got_pass = true;
+}
+
+/* This should only be used by lib/popt_common.c JRA */
+void set_cmdline_auth_info_smb_encrypt(void)
+{
+ cmdline_auth_info.smb_encrypt = true;
+}
+
+void set_cmdline_auth_info_use_machine_account(void)
+{
+ cmdline_auth_info.use_machine_account = true;
+}
+
+bool get_cmdline_auth_info_got_pass(void)
+{
+ return cmdline_auth_info.got_pass;
+}
+
+bool get_cmdline_auth_info_smb_encrypt(void)
+{
+ return cmdline_auth_info.smb_encrypt;
+}
+
+bool get_cmdline_auth_info_use_machine_account(void)
+{
+ return cmdline_auth_info.use_machine_account;
+}
+
+bool get_cmdline_auth_info_copy(struct user_auth_info *info)
+{
+ *info = cmdline_auth_info;
+ /* Now re-alloc the strings. */
+ info->username = SMB_STRDUP(get_cmdline_auth_info_username());
+ info->password = SMB_STRDUP(get_cmdline_auth_info_password());
+ if (!info->username || !info->password) {
+ return false;
+ }
+ return true;
+}
+
+bool set_cmdline_auth_info_machine_account_creds(void)
+{
+ char *pass = NULL;
+ char *account = NULL;
+
+ if (!get_cmdline_auth_info_use_machine_account()) {
+ return false;
+ }
+
+ if (!secrets_init()) {
+ d_printf("ERROR: Unable to open secrets database\n");
+ return false;
+ }
+
+ if (asprintf(&account, "%s$@%s", global_myname(), lp_realm()) < 0) {
+ return false;
+ }
+
+ pass = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
+ if (!pass) {
+ d_printf("ERROR: Unable to fetch machine password for "
+ "%s in domain %s\n",
+ account, lp_workgroup());
+ SAFE_FREE(account);
+ return false;
+ }
+
+ set_cmdline_auth_info_username(account);
+ set_cmdline_auth_info_password(pass);
+
+ SAFE_FREE(account);
+ SAFE_FREE(pass);
+
+ return true;
+}
+
/**************************************************************************n
Find a suitable temporary directory. The result should be copied immediately
as it may be overwritten by a subsequent call.
return((S_ISREG(sbuf->st_mode)) || (S_ISFIFO(sbuf->st_mode)));
}
+/*******************************************************************
+ Check if a unix domain socket exists - call vfs_file_exist for samba files.
+********************************************************************/
+
+bool socket_exist(const char *fname)
+{
+ SMB_STRUCT_STAT st;
+ if (sys_stat(fname,&st) != 0)
+ return(False);
+
+ return S_ISSOCK(st.st_mode);
+}
+
/*******************************************************************
Check a files mod time.
********************************************************************/
}
/*******************************************************************
- Set the length and marker of an smb packet.
+ Set the length and marker of an encrypted smb packet.
********************************************************************/
-void smb_setlen(char *buf,int len)
+void smb_set_enclen(char *buf,int len,uint16 enc_ctx_num)
{
_smb_setlen(buf,len);
SCVAL(buf,4,0xFF);
- SCVAL(buf,5,'S');
- SCVAL(buf,6,'M');
- SCVAL(buf,7,'B');
+ SCVAL(buf,5,'E');
+ SSVAL(buf,6,enc_ctx_num);
}
/*******************************************************************
- Setup the word count and byte count for a smb message.
+ Set the length and marker of an smb packet.
********************************************************************/
-int set_message(char *buf,int num_words,int num_bytes,bool zero)
+void smb_setlen(char *buf,int len)
{
- if (zero && (num_words || num_bytes)) {
- memset(buf + smb_size,'\0',num_words*2 + num_bytes);
- }
- SCVAL(buf,smb_wct,num_words);
- SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes);
- smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4);
- return (smb_size + num_words*2 + num_bytes);
+ _smb_setlen(buf,len);
+
+ SCVAL(buf,4,0xFF);
+ SCVAL(buf,5,'S');
+ SCVAL(buf,6,'M');
+ SCVAL(buf,7,'B');
}
/*******************************************************************
{
int num_words = CVAL(buf,smb_wct);
SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes);
- smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4);
+ _smb_setlen(buf,smb_size + num_words*2 + num_bytes - 4);
return (smb_size + num_words*2 + num_bytes);
}
-/*******************************************************************
- Setup only the byte count for a smb message, using the end of the
- message as a marker.
-********************************************************************/
-
-int set_message_end(void *outbuf,void *end_ptr)
-{
- return set_message_bcc((char *)outbuf,PTR_DIFF(end_ptr,smb_buf((char *)outbuf)));
-}
-
/*******************************************************************
Add a data blob to the end of a smb_buf, adjusting bcc and smb_len.
Return the bytes added
return unix_clean_name(ctx, str);
}
-/*******************************************************************
- Horrible temporary hack until pstring is dead.
-********************************************************************/
-
-char *pstring_clean_name(pstring s)
-{
- char *str = clean_name(NULL,s);
- if (!str) {
- return NULL;
- }
- pstrcpy(s, str);
- TALLOC_FREE(str);
- return s;
-}
-
/*******************************************************************
Close the low 3 fd's and open dev/null in their place.
********************************************************************/
int i;
close(0);
- close(1);
+ close(1);
if (stderr_too)
close(2);
#undef FLAG_TO_SET
}
-/****************************************************************************
- Transfer some data between two fd's.
-****************************************************************************/
-
-#ifndef TRANSFER_BUF_SIZE
-#define TRANSFER_BUF_SIZE 65536
-#endif
-
-ssize_t transfer_file_internal(int infd, int outfd, size_t n, ssize_t (*read_fn)(int, void *, size_t),
- ssize_t (*write_fn)(int, const void *, size_t))
-{
- char *buf;
- size_t total = 0;
- ssize_t read_ret;
- ssize_t write_ret;
- size_t num_to_read_thistime;
- size_t num_written = 0;
-
- if ((buf = SMB_MALLOC_ARRAY(char, TRANSFER_BUF_SIZE)) == NULL)
- return -1;
-
- while (total < n) {
- num_to_read_thistime = MIN((n - total), TRANSFER_BUF_SIZE);
-
- read_ret = (*read_fn)(infd, buf, num_to_read_thistime);
- if (read_ret == -1) {
- DEBUG(0,("transfer_file_internal: read failure. Error = %s\n", strerror(errno) ));
- SAFE_FREE(buf);
- return -1;
- }
- if (read_ret == 0)
- break;
-
- num_written = 0;
-
- while (num_written < read_ret) {
- write_ret = (*write_fn)(outfd,buf + num_written, read_ret - num_written);
-
- if (write_ret == -1) {
- DEBUG(0,("transfer_file_internal: write failure. Error = %s\n", strerror(errno) ));
- SAFE_FREE(buf);
- return -1;
- }
- if (write_ret == 0)
- return (ssize_t)total;
-
- num_written += (size_t)write_ret;
- }
-
- total += (size_t)read_ret;
- }
-
- SAFE_FREE(buf);
- return (ssize_t)total;
-}
-
-SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n)
-{
- return (SMB_OFF_T)transfer_file_internal(infd, outfd, (size_t)n, sys_read, sys_write);
-}
-
/*******************************************************************
Sleep for a specified number of milliseconds.
********************************************************************/
attach it to the logfile */
}
+bool reinit_after_fork(struct messaging_context *msg_ctx,
+ bool parent_longlived)
+{
+ NTSTATUS status;
+
+ /* Reset the state of the random
+ * number generation system, so
+ * children do not get the same random
+ * numbers as each other */
+ set_need_random_reseed();
+
+ /* tdb needs special fork handling */
+ if (tdb_reopen_all(parent_longlived ? 1 : 0) == -1) {
+ DEBUG(0,("tdb_reopen_all failed.\n"));
+ return false;
+ }
+
+ /*
+ * For clustering, we need to re-init our ctdbd connection after the
+ * fork
+ */
+ status = messaging_reinit(msg_ctx);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(0,("messaging_reinit() failed: %s\n",
+ nt_errstr(status)));
+ return false;
+ }
+
+ return true;
+}
+
/****************************************************************************
Put up a yes/no prompt.
****************************************************************************/
Returns a malloc'ed string.
*******************************************************************/
-static char *strip_mount_options(const char *str)
+static char *strip_mount_options(TALLOC_CTX *ctx, const char *str)
{
if (*str == '-') {
const char *p = str;
while(*p && isspace(*p))
p++;
if(*p) {
- return SMB_STRDUP(p);
+ return talloc_strdup(ctx, p);
}
}
return NULL;
/*******************************************************************
Patch from jkf@soton.ac.uk
Split Luke's automount_server into YP lookup and string splitter
- so can easily implement automount_path().
- As we may end up doing both, cache the last YP result.
+ so can easily implement automount_path().
+ Returns a malloc'ed string.
*******************************************************************/
#ifdef WITH_NISPLUS_HOME
-char *automount_lookup(const char *user_name)
+char *automount_lookup(TALLOC_CTX *ctx, const char *user_name)
{
- static fstring last_key = "";
- static pstring last_value = "";
-
+ char *value = NULL;
+
char *nis_map = (char *)lp_nis_home_map_name();
-
+
char buffer[NIS_MAXATTRVAL + 1];
nis_result *result;
nis_object *object;
entry_obj *entry;
- char *tmpstr = NULL;
-
- if (strcmp(user_name, last_key)) {
- slprintf(buffer, sizeof(buffer)-1, "[key=%s],%s", user_name, nis_map);
- DEBUG(5, ("NIS+ querystring: %s\n", buffer));
-
- if (result = nis_list(buffer, FOLLOW_PATH|EXPAND_NAME|HARD_LOOKUP, NULL, NULL)) {
- if (result->status != NIS_SUCCESS) {
- DEBUG(3, ("NIS+ query failed: %s\n", nis_sperrno(result->status)));
- fstrcpy(last_key, ""); pstrcpy(last_value, "");
- } else {
- object = result->objects.objects_val;
- if (object->zo_data.zo_type == ENTRY_OBJ) {
- entry = &object->zo_data.objdata_u.en_data;
- DEBUG(5, ("NIS+ entry type: %s\n", entry->en_type));
- DEBUG(3, ("NIS+ result: %s\n", entry->en_cols.en_cols_val[1].ec_value.ec_value_val));
-
- pstrcpy(last_value, entry->en_cols.en_cols_val[1].ec_value.ec_value_val);
- pstring_sub(last_value, "&", user_name);
- fstrcpy(last_key, user_name);
+
+ snprintf(buffer, sizeof(buffer), "[key=%s],%s", user_name, nis_map);
+ DEBUG(5, ("NIS+ querystring: %s\n", buffer));
+
+ if (result = nis_list(buffer, FOLLOW_PATH|EXPAND_NAME|HARD_LOOKUP, NULL, NULL)) {
+ if (result->status != NIS_SUCCESS) {
+ DEBUG(3, ("NIS+ query failed: %s\n", nis_sperrno(result->status)));
+ } else {
+ object = result->objects.objects_val;
+ if (object->zo_data.zo_type == ENTRY_OBJ) {
+ entry = &object->zo_data.objdata_u.en_data;
+ DEBUG(5, ("NIS+ entry type: %s\n", entry->en_type));
+ DEBUG(3, ("NIS+ result: %s\n", entry->en_cols.en_cols_val[1].ec_value.ec_value_val));
+
+ value = talloc_strdup(ctx,
+ entry->en_cols.en_cols_val[1].ec_value.ec_value_val);
+ if (!value) {
+ nis_freeresult(result);
+ return NULL;
}
+ value = talloc_string_sub(ctx,
+ value,
+ "&",
+ user_name);
}
}
- nis_freeresult(result);
}
+ nis_freeresult(result);
- tmpstr = strip_mount_options(last_value);
- if (tmpstr) {
- pstrcpy(last_value, tmpstr);
- SAFE_FREE(tmpstr);
+ if (value) {
+ value = strip_mount_options(ctx, value);
+ DEBUG(4, ("NIS+ Lookup: %s resulted in %s\n",
+ user_name, value));
}
-
- DEBUG(4, ("NIS+ Lookup: %s resulted in %s\n", user_name, last_value));
- return last_value;
+ return value;
}
#else /* WITH_NISPLUS_HOME */
-char *automount_lookup(const char *user_name)
+char *automount_lookup(TALLOC_CTX *ctx, const char *user_name)
{
- static fstring last_key = "";
- static pstring last_value = "";
+ char *value = NULL;
int nis_error; /* returned by yp all functions */
char *nis_result; /* yp_match inits this */
if ((nis_error = yp_get_default_domain(&nis_domain)) != 0) {
DEBUG(3, ("YP Error: %s\n", yperr_string(nis_error)));
- return last_value;
+ return NULL;
}
DEBUG(5, ("NIS Domain: %s\n", nis_domain));
- if (!strcmp(user_name, last_key)) {
- nis_result = last_value;
- nis_result_len = strlen(last_value);
- nis_error = 0;
- } else {
- if ((nis_error = yp_match(nis_domain, nis_map, user_name, strlen(user_name),
- &nis_result, &nis_result_len)) == 0) {
- char *tmpstr = NULL;
- fstrcpy(last_key, user_name);
- pstrcpy(last_value, nis_result);
- tmpstr = strip_mount_options(last_value);
- if (tmpstr) {
- pstrcpy(last_value, tmpstr);
- SAFE_FREE(tmpstr);
- }
-
- } else if(nis_error == YPERR_KEY) {
-
- /* If Key lookup fails user home server is not in nis_map
- use default information for server, and home directory */
- last_value[0] = 0;
- DEBUG(3, ("YP Key not found: while looking up \"%s\" in map \"%s\"\n",
- user_name, nis_map));
- DEBUG(3, ("using defaults for server and home directory\n"));
- } else {
- DEBUG(3, ("YP Error: \"%s\" while looking up \"%s\" in map \"%s\"\n",
- yperr_string(nis_error), user_name, nis_map));
+ if ((nis_error = yp_match(nis_domain, nis_map, user_name,
+ strlen(user_name), &nis_result,
+ &nis_result_len)) == 0) {
+ value = talloc_strdup(ctx, nis_result);
+ if (!value) {
+ return NULL;
}
+ value = strip_mount_options(ctx, value);
+ } else if(nis_error == YPERR_KEY) {
+ DEBUG(3, ("YP Key not found: while looking up \"%s\" in map \"%s\"\n",
+ user_name, nis_map));
+ DEBUG(3, ("using defaults for server and home directory\n"));
+ } else {
+ DEBUG(3, ("YP Error: \"%s\" while looking up \"%s\" in map \"%s\"\n",
+ yperr_string(nis_error), user_name, nis_map));
}
- DEBUG(4, ("YP Lookup: %s resulted in %s\n", user_name, last_value));
- return last_value;
+ if (value) {
+ DEBUG(4, ("YP Lookup: %s resulted in %s\n", user_name, value));
+ }
+ return value;
}
#endif /* WITH_NISPLUS_HOME */
#endif
if possible.
********************************************************************/
-void set_namearray(name_compare_entry **ppname_array, char *namelist)
+void set_namearray(name_compare_entry **ppname_array, const char *namelist)
{
char *name_end;
- char *nameptr = namelist;
+ const char *nameptr = namelist;
int num_entries = 0;
int i;
if ( strcmp( native_lanman, "Windows 2002 5.1" ) == 0 )
set_remote_arch( RA_WINXP );
else if ( strcmp( native_lanman, "Windows XP 5.2" ) == 0 )
- set_remote_arch( RA_WINXP );
+ set_remote_arch( RA_WINXP64 );
else if ( strcmp( native_lanman, "Windows Server 2003 5.2" ) == 0 )
set_remote_arch( RA_WIN2K3 );
}
case RA_WINXP:
remote_arch_str = "WinXP";
break;
+ case RA_WINXP64:
+ remote_arch_str = "WinXP64";
+ break;
case RA_WIN2K3:
remote_arch_str = "Win2K3";
break;
DEBUG(level,("%c", isprint(buf[i])?buf[i]:'.'));
}
-void dump_data(int level, const unsigned char *buf1,int len)
+/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level.
+ */
+static void _dump_data(int level, const uint8_t *buf, int len,
+ bool omit_zero_bytes)
{
- const unsigned char *buf = (const unsigned char *)buf1;
int i=0;
+ const uint8_t empty[16];
+ bool skipped = false;
+
if (len<=0) return;
if (!DEBUGLVL(level)) return;
-
- DEBUGADD(level,("[%03X] ",i));
+
+ memset(&empty, '\0', 16);
+
for (i=0;i<len;) {
+
+ if (i%16 == 0) {
+ if ((omit_zero_bytes == true) &&
+ (i > 0) &&
+ (len > i+16) &&
+ (memcmp(&buf[i], &empty, 16) == 0))
+ {
+ i +=16;
+ continue;
+ }
+
+ if (i<len) {
+ DEBUGADD(level,("[%04X] ",i));
+ }
+ }
+
DEBUGADD(level,("%02X ",(int)buf[i]));
i++;
- if (i%8 == 0) DEBUGADD(level,(" "));
- if (i%16 == 0) {
+ if (i%8 == 0) DEBUGADD(level,(" "));
+ if (i%16 == 0) {
+
print_asc(level,&buf[i-16],8); DEBUGADD(level,(" "));
print_asc(level,&buf[i-8],8); DEBUGADD(level,("\n"));
- if (i<len) DEBUGADD(level,("[%03X] ",i));
+
+ if ((omit_zero_bytes == true) &&
+ (len > i+16) &&
+ (memcmp(&buf[i], &empty, 16) == 0)) {
+ if (!skipped) {
+ DEBUGADD(level,("skipping zero buffer bytes\n"));
+ skipped = true;
+ }
+ }
}
}
+
if (i%16) {
int n;
n = 16 - (i%16);
n = MIN(8,i%16);
print_asc(level,&buf[i-(i%16)],n); DEBUGADD(level,( " " ));
n = (i%16) - n;
- if (n>0) print_asc(level,&buf[i-n],n);
- DEBUGADD(level,("\n"));
- }
+ if (n>0) print_asc(level,&buf[i-n],n);
+ DEBUGADD(level,("\n"));
+ }
+
}
+/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level.
+ */
+_PUBLIC_ void dump_data(int level, const uint8_t *buf, int len)
+{
+ _dump_data(level, buf, len, false);
+}
+
+/**
+ * Write dump of binary data to the log file.
+ *
+ * The data is only written if the log level is at least level.
+ * 16 zero bytes in a row are ommited
+ */
+_PUBLIC_ void dump_data_skip_zeros(int level, const uint8_t *buf, int len)
+{
+ _dump_data(level, buf, len, true);
+}
+
+
+
void dump_data_pw(const char *msg, const uchar * data, size_t len)
{
#ifdef DEBUG_PASSWORD
#endif
}
-char *tab_depth(int depth)
+const char *tab_depth(int level, int depth)
{
- static pstring spaces;
- size_t len = depth * 4;
- if (len > sizeof(pstring)-1) {
- len = sizeof(pstring)-1;
+ if( CHECK_DEBUGLVL(level) ) {
+ dbgtext("%*s", depth*4, "");
}
-
- memset(spaces, ' ', len);
- spaces[len] = 0;
- return spaces;
+ return "";
}
/*****************************************************************************
int res = 0;
int c;
int i=0;
-
+
while(*s) {
c = *s;
res ^= (c << (i % 15)) ^ (c >> (15-(i%15)));
if (n == -1 || ! *ptr) {
smb_panic("smb_xvasprintf: out of memory");
}
+ va_end(ap2);
return n;
}
*
* @param name File to find, relative to LIBDIR.
*
- * @retval Pointer to a static #pstring containing the full path.
+ * @retval Pointer to a string containing the full path.
**/
char *lib_path(const char *name)
{
- return talloc_asprintf(talloc_tos(), "%s/%s", dyn_LIBDIR, name);
+ return talloc_asprintf(talloc_tos(), "%s/%s", get_dyn_LIBDIR(), name);
+}
+
+/**
+ * @brief Returns an absolute path to a file in the Samba modules directory.
+ *
+ * @param name File to find, relative to MODULESDIR.
+ *
+ * @retval Pointer to a string containing the full path.
+ **/
+
+char *modules_path(const char *name)
+{
+ return talloc_asprintf(talloc_tos(), "%s/%s", get_dyn_MODULESDIR(), name);
}
/**
char *data_path(const char *name)
{
- return talloc_asprintf(talloc_tos(), "%s/%s", dyn_CODEPAGEDIR, name);
+ return talloc_asprintf(talloc_tos(), "%s/%s", get_dyn_CODEPAGEDIR(), name);
}
/*****************************************************************
char *state_path(const char *name)
{
- return xx_path(name, dyn_STATEDIR());
+ return xx_path(name, get_dyn_STATEDIR());
}
/**
* @brief Returns the platform specific shared library extension.
*
- * @retval Pointer to a static #fstring containing the extension.
+ * @retval Pointer to a const char * containing the extension.
**/
const char *shlib_ext(void)
{
- return dyn_SHLIBEXT;
+ return get_dyn_SHLIBEXT();
}
/*******************************************************************
return NULL;
}
+/**********************************************************************
+ Append a DATA_BLOB to a talloc'ed object
+***********************************************************************/
+
+void *talloc_append_blob(TALLOC_CTX *mem_ctx, void *buf, DATA_BLOB blob)
+{
+ size_t old_size = 0;
+ char *result;
+
+ if (blob.length == 0) {
+ return buf;
+ }
+
+ if (buf != NULL) {
+ old_size = talloc_get_size(buf);
+ }
+
+ result = (char *)TALLOC_REALLOC(mem_ctx, buf, old_size + blob.length);
+ if (result == NULL) {
+ return NULL;
+ }
+
+ memcpy(result + old_size, blob.data, blob.length);
+ return result;
+}
+
uint32 map_share_mode_to_deny_mode(uint32 share_access, uint32 private_options)
{
switch (share_access & ~FILE_SHARE_DELETE) {
result.pid = pid;
}
else if (sscanf(pid_string, "%u", &pid) == 1) {
- result.vnn = NONCLUSTER_VNN;
+ result.vnn = get_my_vnn();
result.pid = pid;
}
else {
return IVAL(ptr,off);
}
+/****************************************************************
+ Split DOM\user into DOM and user. Do not mix with winbind variants of that
+ call (they take care of winbind separator and other winbind specific settings).
+****************************************************************/
+
+void split_domain_user(TALLOC_CTX *mem_ctx,
+ const char *full_name,
+ char **domain,
+ char **user)
+{
+ const char *p = NULL;
+
+ p = strchr_m(full_name, '\\');
+
+ if (p != NULL) {
+ *domain = talloc_strndup(mem_ctx, full_name,
+ PTR_DIFF(p, full_name));
+ *user = talloc_strdup(mem_ctx, p+1);
+ } else {
+ *domain = talloc_strdup(mem_ctx, "");
+ *user = talloc_strdup(mem_ctx, full_name);
+ }
+}
+
#if 0
Disable these now we have checked all code paths and ensured
return talloc_named_const(context, size, name);
}
#endif
+
+/* Split a path name into filename and stream name components. Canonicalise
+ * such that an implicit $DATA token is always explicit.
+ *
+ * The "specification" of this function can be found in the
+ * run_local_stream_name() function in torture.c, I've tried those
+ * combinations against a W2k3 server.
+ */
+
+NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
+ char **pbase, char **pstream)
+{
+ char *base = NULL;
+ char *stream = NULL;
+ char *sname; /* stream name */
+ const char *stype; /* stream type */
+
+ DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
+
+ sname = strchr_m(fname, ':');
+
+ if (lp_posix_pathnames() || (sname == NULL)) {
+ if (pbase != NULL) {
+ base = talloc_strdup(mem_ctx, fname);
+ NT_STATUS_HAVE_NO_MEMORY(base);
+ }
+ goto done;
+ }
+
+ if (pbase != NULL) {
+ base = talloc_strndup(mem_ctx, fname, PTR_DIFF(sname, fname));
+ NT_STATUS_HAVE_NO_MEMORY(base);
+ }
+
+ sname += 1;
+
+ stype = strchr_m(sname, ':');
+
+ if (stype == NULL) {
+ sname = talloc_strdup(mem_ctx, sname);
+ stype = "$DATA";
+ }
+ else {
+ if (StrCaseCmp(stype, ":$DATA") != 0) {
+ /*
+ * If there is an explicit stream type, so far we only
+ * allow $DATA. Is there anything else allowed? -- vl
+ */
+ DEBUG(10, ("[%s] is an invalid stream type\n", stype));
+ TALLOC_FREE(base);
+ return NT_STATUS_OBJECT_NAME_INVALID;
+ }
+ sname = talloc_strndup(mem_ctx, sname, PTR_DIFF(stype, sname));
+ stype += 1;
+ }
+
+ if (sname == NULL) {
+ TALLOC_FREE(base);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ if (sname[0] == '\0') {
+ /*
+ * no stream name, so no stream
+ */
+ goto done;
+ }
+
+ if (pstream != NULL) {
+ stream = talloc_asprintf(mem_ctx, "%s:%s", sname, stype);
+ if (stream == NULL) {
+ TALLOC_FREE(sname);
+ TALLOC_FREE(base);
+ return NT_STATUS_NO_MEMORY;
+ }
+ /*
+ * upper-case the type field
+ */
+ strupper_m(strchr_m(stream, ':')+1);
+ }
+
+ done:
+ if (pbase != NULL) {
+ *pbase = base;
+ }
+ if (pstream != NULL) {
+ *pstream = stream;
+ }
+ return NT_STATUS_OK;
+}
+
+bool is_valid_policy_hnd(const POLICY_HND *hnd)
+{
+ POLICY_HND tmp;
+ ZERO_STRUCT(tmp);
+ return (memcmp(&tmp, hnd, sizeof(tmp)) != 0);
+}
+
+bool policy_hnd_equal(const struct policy_handle *hnd1,
+ const struct policy_handle *hnd2)
+{
+ if (!hnd1 || !hnd2) {
+ return false;
+ }
+
+ return (memcmp(hnd1, hnd2, sizeof(*hnd1)) == 0);
+}
+
+/****************************************************************
+ strip off leading '\\' from a hostname
+****************************************************************/
+
+const char *strip_hostname(const char *s)
+{
+ if (!s) {
+ return NULL;
+ }
+
+ if (strlen_m(s) < 3) {
+ return s;
+ }
+
+ if (s[0] == '\\') s++;
+ if (s[0] == '\\') s++;
+
+ return s;
+}