summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
Diffstat (limited to 'source3')
-rw-r--r--source3/utils/ntlm_auth.c92
-rw-r--r--source3/utils/pdbedit.c26
-rw-r--r--source3/utils/profiles.c63
-rw-r--r--source3/utils/smbcacls.c60
-rw-r--r--source3/utils/smbcquotas.c92
-rw-r--r--source3/utils/smbfilter.c10
-rw-r--r--source3/utils/smbpasswd.c7
-rw-r--r--source3/utils/smbtree.c25
-rw-r--r--source3/utils/testparm.c22
9 files changed, 238 insertions, 159 deletions
diff --git a/source3/utils/ntlm_auth.c b/source3/utils/ntlm_auth.c
index 18db15dfce..9312503d33 100644
--- a/source3/utils/ntlm_auth.c
+++ b/source3/utils/ntlm_auth.c
@@ -252,7 +252,7 @@ static bool get_require_membership_sid(void) {
}
/* Authenticate a user with a plaintext password */
-static bool check_plaintext_auth(const char *user, const char *pass,
+static bool check_plaintext_auth(const char *user, const char *pass,
bool stdout_diagnostics)
{
struct winbindd_request request;
@@ -270,49 +270,52 @@ static bool check_plaintext_auth(const char *user, const char *pass,
fstrcpy(request.data.auth.user, user);
fstrcpy(request.data.auth.pass, pass);
- if (require_membership_of_sid)
- pstrcpy(request.data.auth.require_membership_of_sid, require_membership_of_sid);
+ if (require_membership_of_sid) {
+ strlcpy(request.data.auth.require_membership_of_sid,
+ require_membership_of_sid,
+ sizeof(request.data.auth.require_membership_of_sid));
+ }
result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
/* Display response */
-
+
if (stdout_diagnostics) {
if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
d_printf("Reading winbind reply failed! (0x01)\n");
}
-
- d_printf("%s: %s (0x%x)\n",
- response.data.auth.nt_status_string,
- response.data.auth.error_string,
+
+ d_printf("%s: %s (0x%x)\n",
+ response.data.auth.nt_status_string,
+ response.data.auth.error_string,
response.data.auth.nt_status);
} else {
if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
DEBUG(1, ("Reading winbind reply failed! (0x01)\n"));
}
-
- DEBUG(3, ("%s: %s (0x%x)\n",
- response.data.auth.nt_status_string,
+
+ DEBUG(3, ("%s: %s (0x%x)\n",
+ response.data.auth.nt_status_string,
response.data.auth.error_string,
- response.data.auth.nt_status));
+ response.data.auth.nt_status));
}
-
+
return (result == NSS_STATUS_SUCCESS);
}
/* authenticate a user with an encrypted username/password */
-NTSTATUS contact_winbind_auth_crap(const char *username,
- const char *domain,
+NTSTATUS contact_winbind_auth_crap(const char *username,
+ const char *domain,
const char *workstation,
- const DATA_BLOB *challenge,
- const DATA_BLOB *lm_response,
- const DATA_BLOB *nt_response,
- uint32 flags,
- uint8 lm_key[8],
- uint8 user_session_key[16],
- char **error_string,
- char **unix_name)
+ const DATA_BLOB *challenge,
+ const DATA_BLOB *lm_response,
+ const DATA_BLOB *nt_response,
+ uint32 flags,
+ uint8 lm_key[8],
+ uint8 user_session_key[16],
+ char **error_string,
+ char **unix_name)
{
NTSTATUS nt_status;
NSS_STATUS result;
@@ -994,16 +997,22 @@ static void offer_gss_spnego_mechs(void) {
SPNEGO_DATA spnego;
ssize_t len;
char *reply_base64;
-
- pstring principal;
- pstring myname_lower;
+ TALLOC_CTX *ctx = talloc_tos();
+ char *principal;
+ char *myname_lower;
ZERO_STRUCT(spnego);
- pstrcpy(myname_lower, global_myname());
+ myname_lower = talloc_strdup(ctx, global_myname());
+ if (!myname_lower) {
+ return;
+ }
strlower_m(myname_lower);
- pstr_sprintf(principal, "%s$@%s", myname_lower, lp_realm());
+ principal = talloc_asprintf(ctx, "%s$@%s", myname_lower, lp_realm());
+ if (!principal) {
+ return;
+ }
/* Server negTokenInit (mech offerings) */
spnego.type = SPNEGO_NEG_TOKEN_INIT;
@@ -1047,13 +1056,14 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
DATA_BLOB token;
NTSTATUS status;
ssize_t len;
+ TALLOC_CTX *ctx = talloc_tos();
char *user = NULL;
char *domain = NULL;
const char *reply_code;
char *reply_base64;
- pstring reply_argument;
+ char *reply_argument = NULL;
if (strlen(buf) < 2) {
DEBUG(1, ("SPENGO query [%s] invalid", buf));
@@ -1065,7 +1075,7 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
if (ntlmssp_state)
ntlmssp_end(&ntlmssp_state);
} else if (strncmp(buf, "KK", 2) == 0) {
-
+ ;
} else {
DEBUG(1, ("SPENGO query [%s] invalid", buf));
x_fprintf(x_stdout, "BH\n");
@@ -1235,16 +1245,22 @@ static void manage_gss_spnego_request(enum stdio_helper_mode stdio_helper_mode,
if (NT_STATUS_IS_OK(status)) {
response.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
reply_code = "AF";
- pstr_sprintf(reply_argument, "%s\\%s", domain, user);
+ reply_argument = talloc_asprintf(ctx, "%s\\%s", domain, user);
} else if (NT_STATUS_EQUAL(status,
NT_STATUS_MORE_PROCESSING_REQUIRED)) {
response.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
reply_code = "TT";
- pstr_sprintf(reply_argument, "*");
+ reply_argument = talloc_strdup(ctx, "*");
} else {
response.negTokenTarg.negResult = SPNEGO_REJECT;
reply_code = "NA";
- pstrcpy(reply_argument, nt_errstr(status));
+ reply_argument = talloc_strdup(ctx, nt_errstr(status));
+ }
+
+ if (!reply_argument) {
+ DEBUG(1, ("Could not write SPNEGO data blob\n"));
+ x_fprintf(x_stdout, "BH\n");
+ return;
}
SAFE_FREE(user);
@@ -1401,7 +1417,7 @@ static bool manage_client_krb5_init(SPNEGO_DATA spnego)
SPNEGO_DATA reply;
char *reply_base64;
int retval;
-
+
const char *my_mechs[] = {OID_KERBEROS5_OLD, NULL};
ssize_t len;
@@ -1426,8 +1442,7 @@ static bool manage_client_krb5_init(SPNEGO_DATA spnego)
retval = cli_krb5_get_ticket(principal, 0, &tkt, &session_key_krb5, 0, NULL, NULL);
if (retval) {
-
- pstring user;
+ char *user = NULL;
/* Let's try to first get the TGT, for that we need a
password. */
@@ -1438,7 +1453,10 @@ static bool manage_client_krb5_init(SPNEGO_DATA spnego)
return True;
}
- pstr_sprintf(user, "%s@%s", opt_username, opt_domain);
+ user = talloc_asprintf(talloc_tos(), "%s@%s", opt_username, opt_domain);
+ if (!user) {
+ return false;
+ }
if ((retval = kerberos_kinit_password(user, opt_password, 0, NULL))) {
DEBUG(10, ("Requesting TGT failed: %s\n", error_message(retval)));
diff --git a/source3/utils/pdbedit.c b/source3/utils/pdbedit.c
index 7af417098a..c72d98953d 100644
--- a/source3/utils/pdbedit.c
+++ b/source3/utils/pdbedit.c
@@ -221,11 +221,11 @@ static int print_sam_info (struct samu *sam_pwent, bool verbosity, bool smbpwdst
/* TODO: chaeck if entry is a user or a workstation */
if (!sam_pwent) return -1;
-
+
if (verbosity) {
- pstring temp;
+ char temp[44];
const uint8 *hours;
-
+
printf ("Unix username: %s\n", pdb_get_username(sam_pwent));
printf ("NT username: %s\n", pdb_get_nt_username(sam_pwent));
printf ("Account Flags: %s\n", pdb_encode_acct_ctrl(pdb_get_acct_ctrl(sam_pwent), NEW_PW_FORMAT_SPACE_PADDED_LEN));
@@ -242,34 +242,34 @@ static int print_sam_info (struct samu *sam_pwent, bool verbosity, bool smbpwdst
printf ("Account desc: %s\n", pdb_get_acct_desc(sam_pwent));
printf ("Workstations: %s\n", pdb_get_workstations(sam_pwent));
printf ("Munged dial: %s\n", pdb_get_munged_dial(sam_pwent));
-
+
tmp = pdb_get_logon_time(sam_pwent);
printf ("Logon time: %s\n", tmp ? http_timestring(tmp) : "0");
-
+
tmp = pdb_get_logoff_time(sam_pwent);
printf ("Logoff time: %s\n", tmp ? http_timestring(tmp) : "0");
-
+
tmp = pdb_get_kickoff_time(sam_pwent);
printf ("Kickoff time: %s\n", tmp ? http_timestring(tmp) : "0");
-
+
tmp = pdb_get_pass_last_set_time(sam_pwent);
printf ("Password last set: %s\n", tmp ? http_timestring(tmp) : "0");
-
+
tmp = pdb_get_pass_can_change_time(sam_pwent);
printf ("Password can change: %s\n", tmp ? http_timestring(tmp) : "0");
-
+
tmp = pdb_get_pass_must_change_time(sam_pwent);
printf ("Password must change: %s\n", tmp ? http_timestring(tmp) : "0");
tmp = pdb_get_bad_password_time(sam_pwent);
printf ("Last bad password : %s\n", tmp ? http_timestring(tmp) : "0");
- printf ("Bad password count : %d\n",
+ printf ("Bad password count : %d\n",
pdb_get_bad_password_count(sam_pwent));
-
+
hours = pdb_get_hours(sam_pwent);
pdb_sethexhours(temp, hours);
printf ("Logon hours : %s\n", temp);
-
+
} else if (smbpwdstyle) {
char lm_passwd[33];
char nt_passwd[33];
@@ -277,7 +277,7 @@ static int print_sam_info (struct samu *sam_pwent, bool verbosity, bool smbpwdst
uid = nametouid(pdb_get_username(sam_pwent));
pdb_sethexpwd(lm_passwd, pdb_get_lanman_passwd(sam_pwent), pdb_get_acct_ctrl(sam_pwent));
pdb_sethexpwd(nt_passwd, pdb_get_nt_passwd(sam_pwent), pdb_get_acct_ctrl(sam_pwent));
-
+
printf("%s:%lu:%s:%s:%s:LCT-%08X:\n",
pdb_get_username(sam_pwent),
(unsigned long)uid,
diff --git a/source3/utils/profiles.c b/source3/utils/profiles.c
index f9b17d3dcc..c641429beb 100644
--- a/source3/utils/profiles.c
+++ b/source3/utils/profiles.c
@@ -120,7 +120,7 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
REGVAL_CTR *values;
REGSUBKEY_CTR *subkeys;
int i;
- pstring path;
+ char *path;
/* swap out the SIDs in the security descriptor */
@@ -160,13 +160,18 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
/* write each one of the subkeys out */
- pstr_sprintf( path, "%s%s%s", parentpath, parent ? "\\" : "", nk->keyname );
-
+ path = talloc_asprintf(subkeys, "%s%s%s",
+ parentpath, parent ? "\\" : "",nk->keyname);
+ if (!path) {
+ TALLOC_FREE( subkeys );
+ return false;
+ }
+
nk->subkey_index = 0;
- while ( (subkey = regfio_fetch_subkey( infile, nk )) ) {
- if ( !copy_registry_tree( infile, subkey, key, outfile, path ) ) {
- TALLOC_FREE( subkeys );
- return False;
+ while ((subkey = regfio_fetch_subkey(infile, nk))) {
+ if (!copy_registry_tree( infile, subkey, key, outfile, path)) {
+ TALLOC_FREE(subkeys);
+ return false;
}
}
@@ -184,10 +189,11 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
int main( int argc, char *argv[] )
{
+ TALLOC_CTX *frame = talloc_stackframe();
int opt;
REGF_FILE *infile, *outfile;
REGF_NK_REC *nk;
- pstring orig_filename, new_filename;
+ char *orig_filename, *new_filename;
struct poptOption long_options[] = {
POPT_AUTOHELP
{ "change-sid", 'c', POPT_ARG_STRING, NULL, 'c', "Provides SID to change" },
@@ -207,7 +213,7 @@ int main( int argc, char *argv[] )
dbf = x_stderr;
x_setbuf( x_stderr, NULL );
- pc = poptGetContext("profiles", argc, (const char **)argv, long_options,
+ pc = poptGetContext("profiles", argc, (const char **)argv, long_options,
POPT_CONTEXT_KEEP_FIRST);
poptSetOtherOptionHelp(pc, "<profilefile>");
@@ -237,7 +243,7 @@ int main( int argc, char *argv[] )
}
}
- poptGetArg(pc);
+ poptGetArg(pc);
if (!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0);
@@ -250,39 +256,48 @@ int main( int argc, char *argv[] )
exit(252);
}
- pstrcpy( orig_filename, poptPeekArg(pc) );
- pstr_sprintf( new_filename, "%s.new", orig_filename );
-
- if ( !(infile = regfio_open( orig_filename, O_RDONLY, 0 )) ) {
+ orig_filename = talloc_strdup(frame, poptPeekArg(pc));
+ if (!orig_filename) {
+ exit(ENOMEM);
+ }
+ new_filename = talloc_asprintf(frame,
+ "%s.new",
+ orig_filename);
+ if (!new_filename) {
+ exit(ENOMEM);
+ }
+
+ if (!(infile = regfio_open( orig_filename, O_RDONLY, 0))) {
fprintf( stderr, "Failed to open %s!\n", orig_filename );
fprintf( stderr, "Error was (%s)\n", strerror(errno) );
exit (1);
}
-
+
if ( !(outfile = regfio_open( new_filename, (O_RDWR|O_CREAT|O_TRUNC), (S_IREAD|S_IWRITE) )) ) {
fprintf( stderr, "Failed to open new file %s!\n", new_filename );
fprintf( stderr, "Error was (%s)\n", strerror(errno) );
exit (1);
}
-
+
/* actually do the update now */
-
+
if ((nk = regfio_rootkey( infile )) == NULL) {
fprintf(stderr, "Could not get rootkey\n");
exit(3);
}
-
- if ( !copy_registry_tree( infile, nk, NULL, outfile, "" ) ) {
+
+ if (!copy_registry_tree( infile, nk, NULL, outfile, "")) {
fprintf(stderr, "Failed to write updated registry file!\n");
exit(2);
}
-
+
/* cleanup */
-
- regfio_close( infile );
- regfio_close( outfile );
+
+ regfio_close(infile);
+ regfio_close(outfile);
poptFreeContext(pc);
- return( 0 );
+ TALLOC_FREE(frame);
+ return 0;
}
diff --git a/source3/utils/smbcacls.c b/source3/utils/smbcacls.c
index 8c790c875b..861aea0713 100644
--- a/source3/utils/smbcacls.c
+++ b/source3/utils/smbcacls.c
@@ -569,7 +569,7 @@ because the NT docs say this can't be done :-). JRA.
*******************************************************/
static int owner_set(struct cli_state *cli, enum chown_mode change_mode,
- char *filename, char *new_username)
+ const char *filename, const char *new_username)
{
int fnum;
DOM_SID sid;
@@ -848,8 +848,8 @@ static struct cli_state *connect_one(const char *server, const char *share)
static char *the_acl = NULL;
enum chown_mode change_mode = REQUEST_NONE;
int result;
- fstring path;
- pstring filename;
+ char *path;
+ char *filename = NULL;
poptContext pc;
struct poptOption long_options[] = {
POPT_AUTOHELP
@@ -868,10 +868,8 @@ static struct cli_state *connect_one(const char *server, const char *share)
struct cli_state *cli;
TALLOC_CTX *frame = talloc_stackframe();
- pstring owner_username;
- fstring server;
-
- owner_username[0] = '\0';
+ const char *owner_username = "";
+ char *server;
load_case_tables();
@@ -888,7 +886,7 @@ static struct cli_state *connect_one(const char *server, const char *share)
load_interfaces();
pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
-
+
poptSetOtherOptionHelp(pc, "//server1/share1 filename\nACLs look like: "
"'ACL:user:[ALLOWED|DENIED]/flags/permissions'");
@@ -915,35 +913,44 @@ static struct cli_state *connect_one(const char *server, const char *share)
break;
case 'C':
- pstrcpy(owner_username,poptGetOptArg(pc));
+ owner_username = poptGetOptArg(pc);
change_mode = REQUEST_CHOWN;
break;
case 'G':
- pstrcpy(owner_username,poptGetOptArg(pc));
+ owner_username = poptGetOptArg(pc);
change_mode = REQUEST_CHGRP;
break;
}
}
/* Make connection to server */
- if(!poptPeekArg(pc)) {
+ if(!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0);
return -1;
}
-
- fstrcpy(path, poptGetArg(pc));
-
- if(!poptPeekArg(pc)) {
- poptPrintUsage(pc, stderr, 0);
+
+ path = talloc_strdup(frame, poptGetArg(pc));
+ if (!path) {
return -1;
}
-
- pstrcpy(filename, poptGetArg(pc));
- all_string_sub(path,"/","\\",0);
+ if(!poptPeekArg(pc)) {
+ poptPrintUsage(pc, stderr, 0);
+ return -1;
+ }
+
+ filename = talloc_strdup(frame, poptGetArg(pc));
+ if (!filename) {
+ return -1;
+ }
- fstrcpy(server,path+2);
+ string_replace(path,'/','\\');
+
+ server = talloc_strdup(frame, path+2);
+ if (!server) {
+ return -1;
+ }
share = strchr_m(server,'\\');
if (!share) {
printf("Invalid argument: %s\n", share);
@@ -956,19 +963,20 @@ static struct cli_state *connect_one(const char *server, const char *share)
if (!test_args) {
cli = connect_one(server, share);
if (!cli) {
- TALLOC_FREE(frame);
exit(EXIT_FAILED);
}
} else {
exit(0);
}
- all_string_sub(filename, "/", "\\", 0);
+ string_replace(filename, '/', '\\');
if (filename[0] != '\\') {
- pstring s;
- s[0] = '\\';
- safe_strcpy(&s[1], filename, sizeof(pstring)-2);
- pstrcpy(filename, s);
+ filename = talloc_asprintf(frame,
+ "\\%s",
+ filename);
+ if (!filename) {
+ return -1;
+ }
}
/* Perform requested action */
diff --git a/source3/utils/smbcquotas.c b/source3/utils/smbcquotas.c
index 6ae63f4c68..3aa9e76a14 100644
--- a/source3/utils/smbcquotas.c
+++ b/source3/utils/smbcquotas.c
@@ -23,7 +23,7 @@
#include "includes.h"
-static pstring server;
+static char *server;
/* numeric is set when the user wants numeric SIDs and ACEs rather
than going via LSA calls to resolve them */
@@ -54,7 +54,7 @@ static bool cli_open_policy_hnd(void)
return False;
}
}
-
+
/* Open policy handle */
if (!got_policy_hnd) {
@@ -134,14 +134,20 @@ static bool StringToSid(DOM_SID *sid, const char *str)
enum {PARSE_FLAGS,PARSE_LIM};
-static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA_TYPE *qtype, int *cmd, SMB_NTQUOTA_STRUCT *pqt)
+static int parse_quota_set(TALLOC_CTX *ctx,
+ char *set_str,
+ char **pp_username_str,
+ enum SMB_QUOTA_TYPE *qtype,
+ int *cmd,
+ SMB_NTQUOTA_STRUCT *pqt)
{
char *p = set_str,*p2;
int todo;
bool stop = False;
bool enable = False;
bool deny = False;
-
+
+ *pp_username_str = NULL;
if (strnequal(set_str,"UQLIM:",6)) {
p += 6;
*qtype = SMB_USER_QUOTA_TYPE;
@@ -150,11 +156,11 @@ static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA
if ((p2=strstr(p,":"))==NULL) {
return -1;
}
-
+
*p2 = '\0';
p2++;
-
- fstrcpy(username_str,p);
+
+ *pp_username_str = talloc_strdup(ctx, p);
p = p2;
} else if (strnequal(set_str,"FSQLIM:",7)) {
p +=7;
@@ -179,7 +185,7 @@ static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA
#endif
return -1;
}
-
+
break;
case PARSE_FLAGS:
while (!stop) {
@@ -211,14 +217,18 @@ static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA
} else if (enable) {
pqt->qflags |= QUOTAS_ENABLED;
}
-
- break;
+
+ break;
}
return 0;
}
-static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd, pstring username_str, SMB_NTQUOTA_STRUCT *pqt)
+static int do_quota(struct cli_state *cli,
+ enum SMB_QUOTA_TYPE qtype,
+ uint16 cmd,
+ const char *username_str,
+ SMB_NTQUOTA_STRUCT *pqt)
{
uint32 fs_attrs = 0;
int quota_fnum = 0;
@@ -234,7 +244,7 @@ static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd
if (!(fs_attrs & FILE_VOLUME_QUOTAS)) {
d_printf("Quotas are not supported by the server.\n");
- return 0;
+ return 0;
}
if (!cli_get_quota_handle(cli, &quota_fnum)) {
@@ -250,7 +260,7 @@ static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd
d_printf("StringToSid() failed for [%s]\n",username_str);
return -1;
}
-
+
switch(cmd) {
case QUOTA_GET:
if (!cli_get_user_quota(cli, quota_fnum, &qt)) {
@@ -281,12 +291,12 @@ static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd
return -1;
}
dump_ntquota_list(&qtl,verbose,numeric,SidToString);
- free_ntquota_list(&qtl);
+ free_ntquota_list(&qtl);
break;
default:
d_printf("Unknown Error\n");
return -1;
- }
+ }
break;
case SMB_USER_FS_QUOTA_TYPE:
switch(cmd) {
@@ -340,7 +350,7 @@ static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd
default:
d_printf("Unknown Error\n");
return -1;
- }
+ }
break;
default:
d_printf("Unknown Error\n");
@@ -393,9 +403,9 @@ static struct cli_state *connect_one(const char *share)
int opt;
int result;
int todo = 0;
- pstring username_str = {0};
- pstring path = {0};
- pstring set_str = {0};
+ char *username_str = NULL;
+ char *path = NULL;
+ char *set_str = NULL;
enum SMB_QUOTA_TYPE qtype = SMB_INVALID_QUOTA_TYPE;
int cmd = 0;
static bool test_args = False;
@@ -440,7 +450,7 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
load_interfaces();
pc = poptGetContext("smbcquotas", argc, argv, long_options, 0);
-
+
poptSetOtherOptionHelp(pc, "//server1/share1");
while ((opt = poptGetNextOpt(pc)) != -1) {
@@ -469,23 +479,29 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
}
todo = FS_QUOTA;
break;
-
+
case 'u':
if (todo != 0) {
d_printf("Please specify only one option of <-L|-F|-S|-u>\n");
exit(EXIT_PARSE_ERROR);
}
- pstrcpy(username_str,poptGetOptArg(pc));
+ username_str = talloc_strdup(frame, poptGetOptArg(pc));
+ if (!username_str) {
+ exit(EXIT_PARSE_ERROR);
+ }
todo = USER_QUOTA;
fix_user = True;
break;
-
+
case 'S':
if (todo != 0) {
d_printf("Please specify only one option of <-L|-F|-S|-u>\n");
exit(EXIT_PARSE_ERROR);
}
- pstrcpy(set_str,poptGetOptArg(pc));
+ set_str = talloc_strdup(frame, poptGetOptArg(pc));
+ if (!set_str) {
+ exit(EXIT_PARSE_ERROR);
+ }
todo = SET_QUOTA;
break;
}
@@ -494,20 +510,32 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
if (todo == 0)
todo = USER_QUOTA;
- if (!fix_user)
- pstrcpy(username_str,cmdline_auth_info.username);
+ if (!fix_user) {
+ username_str = talloc_strdup(frame, cmdline_auth_info.username);
+ if (!username_str) {
+ exit(EXIT_PARSE_ERROR);
+ }
+ }
/* Make connection to server */
- if(!poptPeekArg(pc)) {
+ if(!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0);
exit(EXIT_PARSE_ERROR);
}
-
- pstrcpy(path, poptGetArg(pc));
- all_string_sub(path,"/","\\",0);
+ path = talloc_strdup(frame, poptGetArg(pc));
+ if (!path) {
+ printf("Out of memory\n");
+ exit(EXIT_PARSE_ERROR);
+ }
+
+ string_replace(path, '/', '\\');
- pstrcpy(server,path+2);
+ server = SMB_STRDUP(path+2);
+ if (!server) {
+ printf("Out of memory\n");
+ exit(EXIT_PARSE_ERROR);
+ }
share = strchr_m(server,'\\');
if (!share) {
printf("Invalid argument: %s\n", share);
@@ -518,7 +546,7 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
share++;
if (todo == SET_QUOTA) {
- if (parse_quota_set(set_str, username_str, &qtype, &cmd, &qt)) {
+ if (parse_quota_set(talloc_tos(), set_str, &username_str, &qtype, &cmd, &qt)) {
printf("Invalid argument: -S %s\n", set_str);
exit(EXIT_PARSE_ERROR);
}
diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c
index 2051c606a0..89a38d5b40 100644
--- a/source3/utils/smbfilter.c
+++ b/source3/utils/smbfilter.c
@@ -78,7 +78,7 @@ static void filter_request(char *buf)
{
int msg_type = CVAL(buf,0);
int type = CVAL(buf,smb_com);
- pstring name1,name2;
+ fstring name1,name2;
unsigned x;
if (msg_type) {
@@ -228,15 +228,15 @@ static void start_filter(char *desthost)
int main(int argc, char *argv[])
{
char *desthost;
- pstring configfile;
+ const char *configfile;
TALLOC_CTX *frame = talloc_stackframe();
load_case_tables();
setup_logging(argv[0],True);
-
- pstrcpy(configfile,dyn_CONFIGFILE);
-
+
+ configfile = dyn_CONFIGFILE;
+
if (argc < 2) {
fprintf(stderr,"smbfilter <desthost> <netbiosname>\n");
exit(1);
diff --git a/source3/utils/smbpasswd.c b/source3/utils/smbpasswd.c
index 2154f5d15f..fc5933cc1a 100644
--- a/source3/utils/smbpasswd.c
+++ b/source3/utils/smbpasswd.c
@@ -83,8 +83,7 @@ static void set_line_buffering(FILE *f)
static int process_options(int argc, char **argv, int local_flags)
{
int ch;
- pstring configfile;
- pstrcpy(configfile, dyn_CONFIGFILE);
+ const char *configfile = dyn_CONFIGFILE;
local_flags |= LOCAL_SET_PASSWORD;
@@ -98,7 +97,7 @@ static int process_options(int argc, char **argv, int local_flags)
local_flags |= LOCAL_AM_ROOT;
break;
case 'c':
- pstrcpy(configfile,optarg);
+ configfile = optarg;
break;
case 'a':
local_flags |= LOCAL_ADD_USER;
@@ -163,7 +162,7 @@ static int process_options(int argc, char **argv, int local_flags)
usage();
}
}
-
+
argc -= optind;
argv += optind;
diff --git a/source3/utils/smbtree.c b/source3/utils/smbtree.c
index bcacddc414..23090013a3 100644
--- a/source3/utils/smbtree.c
+++ b/source3/utils/smbtree.c
@@ -32,7 +32,7 @@ static enum tree_level level = LEV_SHARE;
struct name_list {
struct name_list *prev, *next;
- pstring name, comment;
+ char *name, *comment;
uint32 server_type;
};
@@ -57,10 +57,17 @@ static void add_name(const char *machine_name, uint32 server_type,
ZERO_STRUCTP(new_name);
- pstrcpy(new_name->name, machine_name);
- pstrcpy(new_name->comment, comment);
+ new_name->name = SMB_STRDUP(machine_name);
+ new_name->comment = SMB_STRDUP(comment);
new_name->server_type = server_type;
+ if (!new_name->name || !new_name->comment) {
+ SAFE_FREE(new_name->name);
+ SAFE_FREE(new_name->comment);
+ SAFE_FREE(new_name);
+ return;
+ }
+
DLIST_ADD(*name_list, new_name);
}
@@ -199,7 +206,7 @@ static bool get_shares(char *server_name, struct user_auth_info *user_info)
if (get_rpc_shares(cli, add_name, &shares))
return True;
-
+
if (!cli_RNetShareEnum(cli, add_name, &shares))
return False;
@@ -268,7 +275,7 @@ static bool print_tree(struct user_auth_info *user_info)
POPT_TABLEEND
};
poptContext pc;
-
+
/* Initialise samba stuff */
load_case_tables();
@@ -278,7 +285,7 @@ static bool print_tree(struct user_auth_info *user_info)
setup_logging(argv[0],True);
- pc = poptGetContext("smbtree", argc, (const char **)argv, long_options,
+ pc = poptGetContext("smbtree", argc, (const char **)argv, long_options,
POPT_CONTEXT_KEEP_FIRST);
while(poptGetNextOpt(pc) != -1);
poptFreeContext(pc);
@@ -291,9 +298,11 @@ static bool print_tree(struct user_auth_info *user_info)
if (!cmdline_auth_info.got_pass) {
char *pass = getpass("Password: ");
if (pass) {
- pstrcpy(cmdline_auth_info.password, pass);
+ strlcpy(cmdline_auth_info.password,
+ pass,
+ sizeof(cmdline_auth_info.password));
}
- cmdline_auth_info.got_pass = True;
+ cmdline_auth_info.got_pass = true;
}
/* Now do our stuff */
diff --git a/source3/utils/testparm.c b/source3/utils/testparm.c
index 30e6b2f502..aa519565ad 100644
--- a/source3/utils/testparm.c
+++ b/source3/utils/testparm.c
@@ -82,18 +82,19 @@ cannot be set in the smb.conf file. nmbd will abort with this setting.\n");
*/
if((lp_security() == SEC_SERVER || lp_security() >= SEC_DOMAIN) && !lp_passwordserver()) {
- pstring sec_setting;
+ const char *sec_setting;
if(lp_security() == SEC_SERVER)
- pstrcpy(sec_setting, "server");
+ sec_setting = "server";
else if(lp_security() == SEC_DOMAIN)
- pstrcpy(sec_setting, "domain");
+ sec_setting = "domain";
+ else
+ sec_setting = "";
fprintf(stderr, "ERROR: The setting 'security=%s' requires the 'password server' parameter be set \
to a valid password server.\n", sec_setting );
ret = 1;
}
-
/*
* Password chat sanity checks.
*/
@@ -113,16 +114,17 @@ to a valid password server.\n", sec_setting );
parameter.\n" );
ret = 1;
} else {
- pstring passwd_prog;
- pstring truncated_prog;
+ const char *passwd_prog;
+ char *truncated_prog = NULL;
const char *p;
- pstrcpy( passwd_prog, lp_passwd_program());
+ passwd_prog = lp_passwd_program();
p = passwd_prog;
*truncated_prog = '\0';
- next_token(&p, truncated_prog, NULL, sizeof(pstring));
-
- if(access(truncated_prog, F_OK) == -1) {
+ next_token_talloc(talloc_tos(),
+ &p,
+ &truncated_prog, NULL);
+ if (truncated_prog && access(truncated_prog, F_OK) == -1) {
fprintf(stderr, "ERROR: the 'unix password sync' parameter is set and the 'passwd program' (%s) \
cannot be executed (error was %s).\n", truncated_prog, strerror(errno) );
ret = 1;