char *attrib_string(uint16 mode)
{
- static fstring attrstr;
+ fstring attrstr;
attrstr[0] = 0;
if (mode & aSYSTEM) fstrcat(attrstr,"S");
if (mode & aRONLY) fstrcat(attrstr,"R");
- return(attrstr);
+ return talloc_strdup(talloc_tos(), attrstr);
}
/*******************************************************************
dump_data(10, (uint8 *)smb_buf(buf), bcc);
}
-/*******************************************************************
- Set the length and marker of an encrypted smb packet.
-********************************************************************/
-
-void smb_set_enclen(char *buf,int len,uint16 enc_ctx_num)
-{
- _smb_setlen(buf,len);
-
- SCVAL(buf,4,0xFF);
- SCVAL(buf,5,'E');
- SSVAL(buf,6,enc_ctx_num);
-}
-
/*******************************************************************
Set the length and marker of an smb packet.
********************************************************************/
-void smb_setlen(const char *frombuf, char *buf, int len)
+void smb_setlen(char *buf,int len)
{
_smb_setlen(buf,len);
- if (frombuf) {
- if (buf != frombuf) {
- memcpy(buf+4, frombuf+4, 4);
- }
- } else {
- SCVAL(buf,4,0xFF);
- SCVAL(buf,5,'S');
- SCVAL(buf,6,'M');
- SCVAL(buf,7,'B');
- }
+ SCVAL(buf,4,0xFF);
+ SCVAL(buf,5,'S');
+ SCVAL(buf,6,'M');
+ SCVAL(buf,7,'B');
}
/*******************************************************************
Setup the word count and byte count for a smb message.
********************************************************************/
-int set_message(const char *frombuf, char *buf,int num_words,int num_bytes,BOOL zero)
+int set_message(char *buf,int num_words,int num_bytes,BOOL zero)
{
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(frombuf, 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.
********************************************************************/
-int set_message_bcc(const char *frombuf, char *buf,int num_bytes)
+int set_message_bcc(char *buf,int num_bytes)
{
int num_words = CVAL(buf,smb_wct);
SSVAL(buf,smb_vwv + num_words*SIZEOFWORD,num_bytes);
- smb_setlen(frombuf, 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);
}
message as a marker.
********************************************************************/
-int set_message_end(const char *frombuf, void *outbuf,void *end_ptr)
+int set_message_end(void *outbuf,void *end_ptr)
{
- return set_message_bcc(frombuf,
- (char *)outbuf,
- PTR_DIFF(end_ptr,smb_buf((char *)outbuf)));
+ return set_message_bcc((char *)outbuf,PTR_DIFF(end_ptr,smb_buf((char *)outbuf)));
}
/*******************************************************************
*outbuf = tmp;
memcpy(tmp + smb_len(tmp) + 4, blob.data, blob.length);
- set_message_bcc(NULL, (char *)tmp, smb_buflen(tmp) + blob.length);
+ set_message_bcc((char *)tmp, smb_buflen(tmp) + blob.length);
return blob.length;
}
BOOL get_myname(char *my_name)
{
- pstring hostname;
+ fstring hostname;
*hostname = 0;
if (gethostname(hostname, sizeof(hostname)) == -1) {
DEBUG(0,("gethostname failed\n"));
return False;
- }
+ }
/* Ensure null termination. */
hostname[sizeof(hostname)-1] = '\0';
if (p)
*p = 0;
-
+
fstrcpy(my_name,hostname);
}
-
+
return(True);
}
if (p) {
p++;
fstrcpy(my_domname, p);
+ return True;
}
return False;
const char *uidtoname(uid_t uid)
{
- static fstring name;
- struct passwd *pass;
+ TALLOC_CTX *ctx = talloc_tos();
+ char *name = NULL;
+ struct passwd *pass = NULL;
- pass = getpwuid_alloc(NULL, uid);
+ pass = getpwuid_alloc(ctx,uid);
if (pass) {
- fstrcpy(name, pass->pw_name);
+ name = talloc_strdup(ctx,pass->pw_name);
TALLOC_FREE(pass);
} else {
- slprintf(name, sizeof(name) - 1, "%ld",(long int)uid);
+ name = talloc_asprintf(ctx,
+ "%ld",
+ (long int)uid);
}
return name;
}
-
/*******************************************************************
Convert a gid into a group name.
********************************************************************/
char *gidtoname(gid_t gid)
{
- static fstring name;
+ fstring name;
struct group *grp;
grp = getgrgid(gid);
- if (grp)
- return(grp->gr_name);
- slprintf(name,sizeof(name) - 1, "%d",(int)gid);
- return(name);
+ if (grp) {
+ fstrcpy(name, grp->gr_name);
+ }
+ else {
+ slprintf(name,sizeof(name) - 1, "%d",(int)gid);
+ }
+ return talloc_strdup(talloc_tos(), name);
}
/*******************************************************************
dname = dname - 2;
#endif
- {
- static pstring buf;
- int len = NAMLEN(ptr);
- memcpy(buf, dname, len);
- buf[len] = 0;
- dname = buf;
- }
-
- return(dname);
+ return talloc_strdup(talloc_tos(), dname);
}
/*******************************************************************
/* optimize for the common case */
- if (strequal(servername, global_myname()))
+ if (strequal(servername, global_myname()))
return True;
/* check for an alias */
/* check for loopback */
- if (strequal(servername, "127.0.0.1"))
+ if (strequal(servername, "127.0.0.1"))
return True;
- if (strequal(servername, "localhost"))
+ if (strequal(servername, "localhost"))
return True;
/* maybe it's my dns name */
if ( get_mydnsfullname( dnsname ) )
if ( strequal( servername, dnsname ) )
return True;
-
+
/* handle possible CNAME records */
if ( !is_ipaddress( servername ) ) {
putip( (char*)&return_ip, (char*)hp->h_addr );
fstrcpy( name, inet_ntoa( return_ip ) );
servername = name;
- }
+ }
}
-
+
/* maybe its an IP address? */
if (is_ipaddress(servername)) {
struct iface_struct nics[MAX_INTERFACES];
int i, n;
uint32 ip;
-
+
ip = interpret_addr(servername);
if ((ip==0) || (ip==0xffffffff))
return False;
-
+
n = get_interfaces(nics, MAX_INTERFACES);
for (i=0; i<n; i++) {
- if (ip == nics[i].ip.s_addr)
+ if (ip == nics[i].iface_addr.ip.s_addr)
return True;
}
- }
+ }
/* no match */
return False;
WinXP => "Windows 2002 5.1"
WinXP 64bit => "Windows XP 5.2"
Win2k => "Windows 2000 5.0"
- NT4 => "Windows NT 4.0"
+ NT4 => "Windows NT 4.0"
Win9x => "Windows 4.0"
- Windows 2003 doesn't set the native lan manager string but
+ Windows 2003 doesn't set the native lan manager string but
they do set the domain to "Windows 2003 5.2" (probably a bug).
********************************************************************/
void ra_lanman_string( const char *native_lanman )
-{
+{
if ( strcmp( native_lanman, "Windows 2002 5.1" ) == 0 )
set_remote_arch( RA_WINXP );
else if ( strcmp( native_lanman, "Windows XP 5.2" ) == 0 )
DEBUG(level,("%c", isprint(buf[i])?buf[i]:'.'));
}
-void dump_data(int level, const unsigned char *buf,int len)
+void dump_data(int level, const unsigned char *buf1,int len)
{
+ const unsigned char *buf = (const unsigned char *)buf1;
int i=0;
if (len<=0) return;
char *lock_path(const char *name)
{
- static pstring fname;
+ pstring fname;
pstrcpy(fname,lp_lockdir());
trim_char(fname,'\0','/');
pstrcat(fname,"/");
pstrcat(fname,name);
- return fname;
+ return talloc_strdup(talloc_tos(), fname);
}
/*****************************************************************
char *pid_path(const char *name)
{
- static pstring fname;
+ pstring fname;
pstrcpy(fname,lp_piddir());
trim_char(fname,'\0','/');
pstrcat(fname,"/");
pstrcat(fname,name);
- return fname;
+ return talloc_strdup(talloc_tos(), fname);
}
/**
char *lib_path(const char *name)
{
- static pstring fname;
- fstr_sprintf(fname, "%s/%s", dyn_LIBDIR, name);
- return fname;
+ return talloc_asprintf(talloc_tos(), "%s/%s", dyn_LIBDIR, name);
}
/**
/*******************************************************************
Given a filename - get its directory name
NB: Returned in static storage. Caveats:
- o Not safe in thread environment.
- o Caller must not free.
o If caller wishes to preserve, they should copy.
********************************************************************/
char *parent_dirname(const char *path)
{
- static pstring dirpath;
- char *p;
-
- if (!path)
- return(NULL);
+ char *parent;
- pstrcpy(dirpath, path);
- p = strrchr_m(dirpath, '/'); /* Find final '/', if any */
- if (!p) {
- pstrcpy(dirpath, "."); /* No final "/", so dir is "." */
- } else {
- if (p == dirpath)
- ++p; /* For root "/", leave "/" in place */
- *p = '\0';
+ if (!parent_dirname_talloc(talloc_tos(), path, &parent, NULL)) {
+ return NULL;
}
- return dirpath;
+
+ return parent;
}
BOOL parent_dirname_talloc(TALLOC_CTX *mem_ctx, const char *dir,
#endif
}
-char *procid_str_static(const struct server_id *pid)
+char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid)
{
- static fstring str;
+ fstring str;
#ifdef CLUSTER_SUPPORT
if (pid->vnn == NONCLUSTER_VNN) {
fstr_sprintf(str, "%d", (int)pid->pid);
#else
fstr_sprintf(str, "%d", (int)pid->pid);
#endif
- return str;
+ return talloc_strdup(mem_ctx, str);
}
-char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid)
+char *procid_str_static(const struct server_id *pid)
{
- return talloc_strdup(mem_ctx, procid_str_static(pid));
+ return procid_str(talloc_tos(), pid);
}
BOOL procid_valid(const struct server_id *pid)