summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-11-08 18:50:07 -0800
committerJeremy Allison <jra@samba.org>2007-11-08 18:50:07 -0800
commit7a1de5b44e84a7474e78518c6ba33b3fedc42b5f (patch)
treeb27891de35d06dc48adaa7d353ab3defe385a081
parentc21bc756e36581d3adc770bc2b773b5cf9bf11d0 (diff)
downloadsamba-7a1de5b44e84a7474e78518c6ba33b3fedc42b5f.tar.gz
samba-7a1de5b44e84a7474e78518c6ba33b3fedc42b5f.tar.xz
samba-7a1de5b44e84a7474e78518c6ba33b3fedc42b5f.zip
Remove more pstring/fstrings.
Jeremy.
-rw-r--r--source/client/smbspool.c30
-rw-r--r--source/lib/util.c99
-rw-r--r--source/libsmb/cliconnect.c5
-rw-r--r--source/nmbd/nmbd_processlogon.c9
-rw-r--r--source/torture/rpctorture.c5
-rw-r--r--source/torture/torture.c9
6 files changed, 81 insertions, 76 deletions
diff --git a/source/client/smbspool.c b/source/client/smbspool.c
index 5a1556bd706..0ba4d57ff57 100644
--- a/source/client/smbspool.c
+++ b/source/client/smbspool.c
@@ -69,11 +69,12 @@ static char * uri_unescape_alloc(const char *);
*printer; /* Printer name */
const char *workgroup; /* Workgroup */
FILE *fp; /* File to print */
- int status=0; /* Status of LPD job */
+ int status=1; /* Status of LPD job */
struct cli_state *cli; /* SMB interface */
char null_str[1];
int tries = 0;
const char *dev_uri;
+ TALLOC_CTX *frame = talloc_stackframe();
null_str[0] = '\0';
@@ -93,7 +94,8 @@ static char * uri_unescape_alloc(const char *);
*/
list_devices();
- return (0);
+ status = 0;
+ goto done;
}
if (argc < 6 || argc > 7)
@@ -104,7 +106,7 @@ static char * uri_unescape_alloc(const char *);
fputs(" destination printer:\n", stderr);
fputs("\n", stderr);
fputs(" smb://[username:password@][workgroup/]server[:port]/printer\n", stderr);
- return (1);
+ goto done;
}
/*
@@ -125,7 +127,7 @@ static char * uri_unescape_alloc(const char *);
else if ((fp = fopen(argv[6], "rb")) == NULL)
{
perror("ERROR: Unable to open print file");
- return (1);
+ goto done;
}
else
copies = atoi(argv[4]);
@@ -142,7 +144,7 @@ static char * uri_unescape_alloc(const char *);
else
{
fputs("ERROR: No device URI found in DEVICE_URI environment variable or argv[0] !\n", stderr);
- return (1);
+ goto done;
}
uri[sizeof(uri) - 1] = '\0';
@@ -184,7 +186,7 @@ static char * uri_unescape_alloc(const char *);
if ((sep = strchr_m(tmp, '/')) == NULL)
{
fputs("ERROR: Bad URI - need printer name!\n", stderr);
- return (1);
+ goto done;
}
*sep++ = '\0';
@@ -231,7 +233,7 @@ static char * uri_unescape_alloc(const char *);
if (!lp_load(dyn_CONFIGFILE, True, False, False, True))
{
fprintf(stderr, "ERROR: Can't load %s - run testparm to debug it\n", dyn_CONFIGFILE);
- return (1);
+ goto done;
}
if (workgroup == NULL)
@@ -252,7 +254,7 @@ static char * uri_unescape_alloc(const char *);
else
{
fprintf(stderr, "ERROR: Unable to connect to CIFS host, trying next printer...\n");
- return (1);
+ goto done;
}
}
}
@@ -260,7 +262,7 @@ static char * uri_unescape_alloc(const char *);
if (cli == NULL) {
fprintf(stderr, "ERROR: Unable to connect to CIFS host after (tried %d times)\n", tries);
- return (1);
+ goto done;
}
/*
@@ -287,6 +289,9 @@ static char * uri_unescape_alloc(const char *);
* Return the queue status...
*/
+ done:
+
+ TALLOC_FREE(frame);
return (status);
}
@@ -480,14 +485,17 @@ smb_connect(const char *workgroup, /* I - Workgroup */
const char *jobusername) /* I - User who issued the print job */
{
struct cli_state *cli; /* New connection */
- pstring myname; /* Client name */
+ char *myname = NULL; /* Client name */
struct passwd *pwd;
/*
* Get the names and addresses of the client and server...
*/
- get_myname(myname);
+ myname = get_myname(talloc_tos());
+ if (!myname) {
+ return NULL;
+ }
/* See if we have a username first. This is for backwards compatible
behavior with 3.0.14a */
diff --git a/source/lib/util.c b/source/lib/util.c
index ab33df47ee8..f96439525f0 100644
--- a/source/lib/util.c
+++ b/source/lib/util.c
@@ -1180,9 +1180,10 @@ void safe_free(void *p)
Get my own name and IP.
****************************************************************************/
-bool get_myname(char *my_name)
+char *get_myname(TALLOC_CTX *ctx)
{
- fstring hostname;
+ char *p;
+ char hostname[HOST_NAME_MAX];
*hostname = 0;
@@ -1195,17 +1196,13 @@ bool get_myname(char *my_name)
/* Ensure null termination. */
hostname[sizeof(hostname)-1] = '\0';
- if (my_name) {
- /* split off any parts after an initial . */
- char *p = strchr_m(hostname,'.');
-
- if (p)
- *p = 0;
-
- fstrcpy(my_name,hostname);
+ /* split off any parts after an initial . */
+ p = strchr_m(hostname,'.');
+ if (p) {
+ *p = 0;
}
- return(True);
+ return talloc_strdup(ctx, hostname);
}
/****************************************************************************
@@ -2355,7 +2352,7 @@ char *smb_xstrndup(const char *s, size_t n)
/*****************************************************************
Like strdup but for memory.
-*****************************************************************/
+*****************************************************************/
void *memdup(const void *p, size_t size)
{
@@ -2371,54 +2368,59 @@ void *memdup(const void *p, size_t size)
/*****************************************************************
Get local hostname and cache result.
-*****************************************************************/
+*****************************************************************/
char *myhostname(void)
{
- static pstring ret;
- if (ret[0] == 0)
- get_myname(ret);
+ static char *ret;
+ if (ret == NULL) {
+ /* This is cached forever so
+ * use NULL talloc ctx. */
+ ret = get_myname(NULL);
+ }
return ret;
}
/*****************************************************************
- A useful function for returning a path in the Samba lock directory.
-*****************************************************************/
+ A useful function for returning a path in the Samba pid directory.
+*****************************************************************/
-char *lock_path(const char *name)
+static char *xx_path(const char *name, const char *rootpath)
{
- pstring fname;
+ char *fname = NULL;
- pstrcpy(fname,lp_lockdir());
- trim_char(fname,'\0','/');
-
- if (!directory_exist(fname,NULL))
+ fname = talloc_strdup(talloc_tos(), rootpath);
+ if (!fname) {
+ return NULL;
+ }
+ trim_string(fname,"","/");
+
+ if (!directory_exist(fname,NULL)) {
mkdir(fname,0755);
-
- pstrcat(fname,"/");
- pstrcat(fname,name);
+ }
- return talloc_strdup(talloc_tos(), fname);
+ return talloc_asprintf(talloc_tos(),
+ "%s/%s",
+ fname,
+ name);
}
/*****************************************************************
- A useful function for returning a path in the Samba pid directory.
+ A useful function for returning a path in the Samba lock directory.
*****************************************************************/
-char *pid_path(const char *name)
+char *lock_path(const char *name)
{
- pstring fname;
-
- pstrcpy(fname,lp_piddir());
- trim_char(fname,'\0','/');
-
- if (!directory_exist(fname,NULL))
- mkdir(fname,0755);
+ return xx_path(name, lp_lockdir());
+}
- pstrcat(fname,"/");
- pstrcat(fname,name);
+/*****************************************************************
+ A useful function for returning a path in the Samba pid directory.
+*****************************************************************/
- return talloc_strdup(talloc_tos(), fname);
+char *pid_path(const char *name)
+{
+ return xx_path(name, lp_piddir());
}
/**
@@ -2453,22 +2455,7 @@ a useful function for returning a path in the Samba state directory
char *state_path(const char *name)
{
- TALLOC_CTX *ctx = talloc_tos();
- char *fname = talloc_strdup(ctx, dyn_STATEDIR());
-
- if (!fname) {
- smb_panic("state_path: out of memory");
- }
- trim_string(fname,"","/");
-
- if (!directory_exist(fname,NULL)) {
- mkdir(fname,0755);
- }
-
- fname = talloc_asprintf(ctx, "%s/%s",
- fname, name);
-
- return fname;
+ return xx_path(name, dyn_STATEDIR());
}
/**
diff --git a/source/libsmb/cliconnect.c b/source/libsmb/cliconnect.c
index b86939a8970..8b180f01358 100644
--- a/source/libsmb/cliconnect.c
+++ b/source/libsmb/cliconnect.c
@@ -1772,12 +1772,9 @@ struct cli_state *get_ipc_connect(char *server,
struct user_auth_info *user_info)
{
struct cli_state *cli;
- pstring myname;
NTSTATUS nt_status;
- get_myname(myname);
-
- nt_status = cli_full_connection(&cli, myname, server, server_ss, 0, "IPC$", "IPC",
+ nt_status = cli_full_connection(&cli, NULL, server, server_ss, 0, "IPC$", "IPC",
user_info->username, lp_workgroup(), user_info->password,
CLI_FULL_CONNECTION_ANONYMOUS_FALLBACK, Undefined, NULL);
diff --git a/source/nmbd/nmbd_processlogon.c b/source/nmbd/nmbd_processlogon.c
index 50a614a3908..8cbb87355a0 100644
--- a/source/nmbd/nmbd_processlogon.c
+++ b/source/nmbd/nmbd_processlogon.c
@@ -395,7 +395,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
struct GUID domain_guid;
UUID_FLAT flat_guid;
char *domain;
- pstring hostname;
+ char *hostname;
char *component, *dc, *q1;
char *q_orig = q;
int str_offset;
@@ -406,7 +406,12 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
("get_mydnsdomname failed.\n"));
return;
}
- get_myname(hostname);
+ hostname = get_myname(talloc_tos());
+ if (!hostname) {
+ DEBUG(2,
+ ("get_myname failed.\n"));
+ return;
+ }
if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) {
return;
diff --git a/source/torture/rpctorture.c b/source/torture/rpctorture.c
index d8fcedd8de6..64e7b580f3c 100644
--- a/source/torture/rpctorture.c
+++ b/source/torture/rpctorture.c
@@ -228,6 +228,7 @@ enum client_action
int nprocs = 1;
int numops = 100;
pstring logfile;
+ TALLOC_CTX *frame = talloc_stackframe();
struct client_info cli_info;
@@ -292,8 +293,8 @@ enum client_action
setup_logging(pname, True);
- if (!get_myname(global_myname))
- {
+ global_myname = get_myname(global_myname);
+ if (!global_myname) {
fprintf(stderr, "Failed to get my hostname.\n");
}
diff --git a/source/torture/torture.c b/source/torture/torture.c
index 697d87adc7b..88711ef6776 100644
--- a/source/torture/torture.c
+++ b/source/torture/torture.c
@@ -5175,6 +5175,7 @@ static void usage(void)
int gotuser = 0;
int gotpass = 0;
bool correct = True;
+ TALLOC_CTX *frame = talloc_stackframe();
dbf = x_stdout;
@@ -5207,7 +5208,11 @@ static void usage(void)
*p = 0;
fstrcpy(share, p+1);
- get_myname(myname);
+ fstrcpy(myname, get_myname(talloc_tos()));
+ if (!*myname) {
+ fprintf(stderr, "Failed to get my hostname.\n");
+ return 1;
+ }
if (*username == 0 && getenv("LOGNAME")) {
fstrcpy(username,getenv("LOGNAME"));
@@ -5309,6 +5314,8 @@ static void usage(void)
}
}
+ TALLOC_FREE(frame);
+
if (correct) {
return(0);
} else {