1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

Getting to the home stretch for elimination of pstrings...

Jeremy.
This commit is contained in:
Jeremy Allison 2007-12-03 18:48:41 -08:00
parent 9ccac8abb0
commit 0411635511
9 changed files with 238 additions and 159 deletions

View File

@ -252,7 +252,7 @@ static bool get_require_membership_sid(void) {
} }
/* Authenticate a user with a plaintext password */ /* 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) bool stdout_diagnostics)
{ {
struct winbindd_request request; 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.user, user);
fstrcpy(request.data.auth.pass, pass); fstrcpy(request.data.auth.pass, pass);
if (require_membership_of_sid) if (require_membership_of_sid) {
pstrcpy(request.data.auth.require_membership_of_sid, 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); result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
/* Display response */ /* Display response */
if (stdout_diagnostics) { if (stdout_diagnostics) {
if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) { if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
d_printf("Reading winbind reply failed! (0x01)\n"); d_printf("Reading winbind reply failed! (0x01)\n");
} }
d_printf("%s: %s (0x%x)\n", d_printf("%s: %s (0x%x)\n",
response.data.auth.nt_status_string, response.data.auth.nt_status_string,
response.data.auth.error_string, response.data.auth.error_string,
response.data.auth.nt_status); response.data.auth.nt_status);
} else { } else {
if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) { if ((result != NSS_STATUS_SUCCESS) && (response.data.auth.nt_status == 0)) {
DEBUG(1, ("Reading winbind reply failed! (0x01)\n")); DEBUG(1, ("Reading winbind reply failed! (0x01)\n"));
} }
DEBUG(3, ("%s: %s (0x%x)\n", DEBUG(3, ("%s: %s (0x%x)\n",
response.data.auth.nt_status_string, response.data.auth.nt_status_string,
response.data.auth.error_string, response.data.auth.error_string,
response.data.auth.nt_status)); response.data.auth.nt_status));
} }
return (result == NSS_STATUS_SUCCESS); return (result == NSS_STATUS_SUCCESS);
} }
/* authenticate a user with an encrypted username/password */ /* authenticate a user with an encrypted username/password */
NTSTATUS contact_winbind_auth_crap(const char *username, NTSTATUS contact_winbind_auth_crap(const char *username,
const char *domain, const char *domain,
const char *workstation, const char *workstation,
const DATA_BLOB *challenge, const DATA_BLOB *challenge,
const DATA_BLOB *lm_response, const DATA_BLOB *lm_response,
const DATA_BLOB *nt_response, const DATA_BLOB *nt_response,
uint32 flags, uint32 flags,
uint8 lm_key[8], uint8 lm_key[8],
uint8 user_session_key[16], uint8 user_session_key[16],
char **error_string, char **error_string,
char **unix_name) char **unix_name)
{ {
NTSTATUS nt_status; NTSTATUS nt_status;
NSS_STATUS result; NSS_STATUS result;
@ -994,16 +997,22 @@ static void offer_gss_spnego_mechs(void) {
SPNEGO_DATA spnego; SPNEGO_DATA spnego;
ssize_t len; ssize_t len;
char *reply_base64; char *reply_base64;
TALLOC_CTX *ctx = talloc_tos();
pstring principal; char *principal;
pstring myname_lower; char *myname_lower;
ZERO_STRUCT(spnego); ZERO_STRUCT(spnego);
pstrcpy(myname_lower, global_myname()); myname_lower = talloc_strdup(ctx, global_myname());
if (!myname_lower) {
return;
}
strlower_m(myname_lower); 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) */ /* Server negTokenInit (mech offerings) */
spnego.type = SPNEGO_NEG_TOKEN_INIT; 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; DATA_BLOB token;
NTSTATUS status; NTSTATUS status;
ssize_t len; ssize_t len;
TALLOC_CTX *ctx = talloc_tos();
char *user = NULL; char *user = NULL;
char *domain = NULL; char *domain = NULL;
const char *reply_code; const char *reply_code;
char *reply_base64; char *reply_base64;
pstring reply_argument; char *reply_argument = NULL;
if (strlen(buf) < 2) { if (strlen(buf) < 2) {
DEBUG(1, ("SPENGO query [%s] invalid", buf)); 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) if (ntlmssp_state)
ntlmssp_end(&ntlmssp_state); ntlmssp_end(&ntlmssp_state);
} else if (strncmp(buf, "KK", 2) == 0) { } else if (strncmp(buf, "KK", 2) == 0) {
;
} else { } else {
DEBUG(1, ("SPENGO query [%s] invalid", buf)); DEBUG(1, ("SPENGO query [%s] invalid", buf));
x_fprintf(x_stdout, "BH\n"); 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)) { if (NT_STATUS_IS_OK(status)) {
response.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED; response.negTokenTarg.negResult = SPNEGO_ACCEPT_COMPLETED;
reply_code = "AF"; 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, } else if (NT_STATUS_EQUAL(status,
NT_STATUS_MORE_PROCESSING_REQUIRED)) { NT_STATUS_MORE_PROCESSING_REQUIRED)) {
response.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE; response.negTokenTarg.negResult = SPNEGO_ACCEPT_INCOMPLETE;
reply_code = "TT"; reply_code = "TT";
pstr_sprintf(reply_argument, "*"); reply_argument = talloc_strdup(ctx, "*");
} else { } else {
response.negTokenTarg.negResult = SPNEGO_REJECT; response.negTokenTarg.negResult = SPNEGO_REJECT;
reply_code = "NA"; 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); SAFE_FREE(user);
@ -1401,7 +1417,7 @@ static bool manage_client_krb5_init(SPNEGO_DATA spnego)
SPNEGO_DATA reply; SPNEGO_DATA reply;
char *reply_base64; char *reply_base64;
int retval; int retval;
const char *my_mechs[] = {OID_KERBEROS5_OLD, NULL}; const char *my_mechs[] = {OID_KERBEROS5_OLD, NULL};
ssize_t len; 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); retval = cli_krb5_get_ticket(principal, 0, &tkt, &session_key_krb5, 0, NULL, NULL);
if (retval) { if (retval) {
char *user = NULL;
pstring user;
/* Let's try to first get the TGT, for that we need a /* Let's try to first get the TGT, for that we need a
password. */ password. */
@ -1438,7 +1453,10 @@ static bool manage_client_krb5_init(SPNEGO_DATA spnego)
return True; 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))) { if ((retval = kerberos_kinit_password(user, opt_password, 0, NULL))) {
DEBUG(10, ("Requesting TGT failed: %s\n", error_message(retval))); DEBUG(10, ("Requesting TGT failed: %s\n", error_message(retval)));

View File

@ -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 */ /* TODO: chaeck if entry is a user or a workstation */
if (!sam_pwent) return -1; if (!sam_pwent) return -1;
if (verbosity) { if (verbosity) {
pstring temp; char temp[44];
const uint8 *hours; const uint8 *hours;
printf ("Unix username: %s\n", pdb_get_username(sam_pwent)); printf ("Unix username: %s\n", pdb_get_username(sam_pwent));
printf ("NT username: %s\n", pdb_get_nt_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)); 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 ("Account desc: %s\n", pdb_get_acct_desc(sam_pwent));
printf ("Workstations: %s\n", pdb_get_workstations(sam_pwent)); printf ("Workstations: %s\n", pdb_get_workstations(sam_pwent));
printf ("Munged dial: %s\n", pdb_get_munged_dial(sam_pwent)); printf ("Munged dial: %s\n", pdb_get_munged_dial(sam_pwent));
tmp = pdb_get_logon_time(sam_pwent); tmp = pdb_get_logon_time(sam_pwent);
printf ("Logon time: %s\n", tmp ? http_timestring(tmp) : "0"); printf ("Logon time: %s\n", tmp ? http_timestring(tmp) : "0");
tmp = pdb_get_logoff_time(sam_pwent); tmp = pdb_get_logoff_time(sam_pwent);
printf ("Logoff time: %s\n", tmp ? http_timestring(tmp) : "0"); printf ("Logoff time: %s\n", tmp ? http_timestring(tmp) : "0");
tmp = pdb_get_kickoff_time(sam_pwent); tmp = pdb_get_kickoff_time(sam_pwent);
printf ("Kickoff time: %s\n", tmp ? http_timestring(tmp) : "0"); printf ("Kickoff time: %s\n", tmp ? http_timestring(tmp) : "0");
tmp = pdb_get_pass_last_set_time(sam_pwent); tmp = pdb_get_pass_last_set_time(sam_pwent);
printf ("Password last set: %s\n", tmp ? http_timestring(tmp) : "0"); printf ("Password last set: %s\n", tmp ? http_timestring(tmp) : "0");
tmp = pdb_get_pass_can_change_time(sam_pwent); tmp = pdb_get_pass_can_change_time(sam_pwent);
printf ("Password can change: %s\n", tmp ? http_timestring(tmp) : "0"); printf ("Password can change: %s\n", tmp ? http_timestring(tmp) : "0");
tmp = pdb_get_pass_must_change_time(sam_pwent); tmp = pdb_get_pass_must_change_time(sam_pwent);
printf ("Password must change: %s\n", tmp ? http_timestring(tmp) : "0"); printf ("Password must change: %s\n", tmp ? http_timestring(tmp) : "0");
tmp = pdb_get_bad_password_time(sam_pwent); tmp = pdb_get_bad_password_time(sam_pwent);
printf ("Last bad password : %s\n", tmp ? http_timestring(tmp) : "0"); 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)); pdb_get_bad_password_count(sam_pwent));
hours = pdb_get_hours(sam_pwent); hours = pdb_get_hours(sam_pwent);
pdb_sethexhours(temp, hours); pdb_sethexhours(temp, hours);
printf ("Logon hours : %s\n", temp); printf ("Logon hours : %s\n", temp);
} else if (smbpwdstyle) { } else if (smbpwdstyle) {
char lm_passwd[33]; char lm_passwd[33];
char nt_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)); 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(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)); 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", printf("%s:%lu:%s:%s:%s:LCT-%08X:\n",
pdb_get_username(sam_pwent), pdb_get_username(sam_pwent),
(unsigned long)uid, (unsigned long)uid,

View File

@ -120,7 +120,7 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
REGVAL_CTR *values; REGVAL_CTR *values;
REGSUBKEY_CTR *subkeys; REGSUBKEY_CTR *subkeys;
int i; int i;
pstring path; char *path;
/* swap out the SIDs in the security descriptor */ /* 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 */ /* 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; nk->subkey_index = 0;
while ( (subkey = regfio_fetch_subkey( infile, nk )) ) { while ((subkey = regfio_fetch_subkey(infile, nk))) {
if ( !copy_registry_tree( infile, subkey, key, outfile, path ) ) { if (!copy_registry_tree( infile, subkey, key, outfile, path)) {
TALLOC_FREE( subkeys ); TALLOC_FREE(subkeys);
return False; return false;
} }
} }
@ -184,10 +189,11 @@ static bool copy_registry_tree( REGF_FILE *infile, REGF_NK_REC *nk,
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
{ {
TALLOC_CTX *frame = talloc_stackframe();
int opt; int opt;
REGF_FILE *infile, *outfile; REGF_FILE *infile, *outfile;
REGF_NK_REC *nk; REGF_NK_REC *nk;
pstring orig_filename, new_filename; char *orig_filename, *new_filename;
struct poptOption long_options[] = { struct poptOption long_options[] = {
POPT_AUTOHELP POPT_AUTOHELP
{ "change-sid", 'c', POPT_ARG_STRING, NULL, 'c', "Provides SID to change" }, { "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; dbf = x_stderr;
x_setbuf( x_stderr, NULL ); 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); POPT_CONTEXT_KEEP_FIRST);
poptSetOtherOptionHelp(pc, "<profilefile>"); poptSetOtherOptionHelp(pc, "<profilefile>");
@ -237,7 +243,7 @@ int main( int argc, char *argv[] )
} }
} }
poptGetArg(pc); poptGetArg(pc);
if (!poptPeekArg(pc)) { if (!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0); poptPrintUsage(pc, stderr, 0);
@ -250,39 +256,48 @@ int main( int argc, char *argv[] )
exit(252); exit(252);
} }
pstrcpy( orig_filename, poptPeekArg(pc) ); orig_filename = talloc_strdup(frame, poptPeekArg(pc));
pstr_sprintf( new_filename, "%s.new", orig_filename ); if (!orig_filename) {
exit(ENOMEM);
if ( !(infile = regfio_open( orig_filename, O_RDONLY, 0 )) ) { }
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, "Failed to open %s!\n", orig_filename );
fprintf( stderr, "Error was (%s)\n", strerror(errno) ); fprintf( stderr, "Error was (%s)\n", strerror(errno) );
exit (1); exit (1);
} }
if ( !(outfile = regfio_open( new_filename, (O_RDWR|O_CREAT|O_TRUNC), (S_IREAD|S_IWRITE) )) ) { 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, "Failed to open new file %s!\n", new_filename );
fprintf( stderr, "Error was (%s)\n", strerror(errno) ); fprintf( stderr, "Error was (%s)\n", strerror(errno) );
exit (1); exit (1);
} }
/* actually do the update now */ /* actually do the update now */
if ((nk = regfio_rootkey( infile )) == NULL) { if ((nk = regfio_rootkey( infile )) == NULL) {
fprintf(stderr, "Could not get rootkey\n"); fprintf(stderr, "Could not get rootkey\n");
exit(3); 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"); fprintf(stderr, "Failed to write updated registry file!\n");
exit(2); exit(2);
} }
/* cleanup */ /* cleanup */
regfio_close( infile ); regfio_close(infile);
regfio_close( outfile ); regfio_close(outfile);
poptFreeContext(pc); poptFreeContext(pc);
return( 0 ); TALLOC_FREE(frame);
return 0;
} }

View File

@ -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, 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; int fnum;
DOM_SID sid; DOM_SID sid;
@ -848,8 +848,8 @@ static struct cli_state *connect_one(const char *server, const char *share)
static char *the_acl = NULL; static char *the_acl = NULL;
enum chown_mode change_mode = REQUEST_NONE; enum chown_mode change_mode = REQUEST_NONE;
int result; int result;
fstring path; char *path;
pstring filename; char *filename = NULL;
poptContext pc; poptContext pc;
struct poptOption long_options[] = { struct poptOption long_options[] = {
POPT_AUTOHELP POPT_AUTOHELP
@ -868,10 +868,8 @@ static struct cli_state *connect_one(const char *server, const char *share)
struct cli_state *cli; struct cli_state *cli;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
pstring owner_username; const char *owner_username = "";
fstring server; char *server;
owner_username[0] = '\0';
load_case_tables(); load_case_tables();
@ -888,7 +886,7 @@ static struct cli_state *connect_one(const char *server, const char *share)
load_interfaces(); load_interfaces();
pc = poptGetContext("smbcacls", argc, argv, long_options, 0); pc = poptGetContext("smbcacls", argc, argv, long_options, 0);
poptSetOtherOptionHelp(pc, "//server1/share1 filename\nACLs look like: " poptSetOtherOptionHelp(pc, "//server1/share1 filename\nACLs look like: "
"'ACL:user:[ALLOWED|DENIED]/flags/permissions'"); "'ACL:user:[ALLOWED|DENIED]/flags/permissions'");
@ -915,35 +913,44 @@ static struct cli_state *connect_one(const char *server, const char *share)
break; break;
case 'C': case 'C':
pstrcpy(owner_username,poptGetOptArg(pc)); owner_username = poptGetOptArg(pc);
change_mode = REQUEST_CHOWN; change_mode = REQUEST_CHOWN;
break; break;
case 'G': case 'G':
pstrcpy(owner_username,poptGetOptArg(pc)); owner_username = poptGetOptArg(pc);
change_mode = REQUEST_CHGRP; change_mode = REQUEST_CHGRP;
break; break;
} }
} }
/* Make connection to server */ /* Make connection to server */
if(!poptPeekArg(pc)) { if(!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0); poptPrintUsage(pc, stderr, 0);
return -1; return -1;
} }
fstrcpy(path, poptGetArg(pc)); path = talloc_strdup(frame, poptGetArg(pc));
if (!path) {
if(!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0);
return -1; return -1;
} }
pstrcpy(filename, poptGetArg(pc));
all_string_sub(path,"/","\\",0); if(!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0);
return -1;
}
fstrcpy(server,path+2); filename = talloc_strdup(frame, poptGetArg(pc));
if (!filename) {
return -1;
}
string_replace(path,'/','\\');
server = talloc_strdup(frame, path+2);
if (!server) {
return -1;
}
share = strchr_m(server,'\\'); share = strchr_m(server,'\\');
if (!share) { if (!share) {
printf("Invalid argument: %s\n", 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) { if (!test_args) {
cli = connect_one(server, share); cli = connect_one(server, share);
if (!cli) { if (!cli) {
TALLOC_FREE(frame);
exit(EXIT_FAILED); exit(EXIT_FAILED);
} }
} else { } else {
exit(0); exit(0);
} }
all_string_sub(filename, "/", "\\", 0); string_replace(filename, '/', '\\');
if (filename[0] != '\\') { if (filename[0] != '\\') {
pstring s; filename = talloc_asprintf(frame,
s[0] = '\\'; "\\%s",
safe_strcpy(&s[1], filename, sizeof(pstring)-2); filename);
pstrcpy(filename, s); if (!filename) {
return -1;
}
} }
/* Perform requested action */ /* Perform requested action */

View File

@ -23,7 +23,7 @@
#include "includes.h" #include "includes.h"
static pstring server; static char *server;
/* numeric is set when the user wants numeric SIDs and ACEs rather /* numeric is set when the user wants numeric SIDs and ACEs rather
than going via LSA calls to resolve them */ than going via LSA calls to resolve them */
@ -54,7 +54,7 @@ static bool cli_open_policy_hnd(void)
return False; return False;
} }
} }
/* Open policy handle */ /* Open policy handle */
if (!got_policy_hnd) { if (!got_policy_hnd) {
@ -134,14 +134,20 @@ static bool StringToSid(DOM_SID *sid, const char *str)
enum {PARSE_FLAGS,PARSE_LIM}; 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; char *p = set_str,*p2;
int todo; int todo;
bool stop = False; bool stop = False;
bool enable = False; bool enable = False;
bool deny = False; bool deny = False;
*pp_username_str = NULL;
if (strnequal(set_str,"UQLIM:",6)) { if (strnequal(set_str,"UQLIM:",6)) {
p += 6; p += 6;
*qtype = SMB_USER_QUOTA_TYPE; *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) { if ((p2=strstr(p,":"))==NULL) {
return -1; return -1;
} }
*p2 = '\0'; *p2 = '\0';
p2++; p2++;
fstrcpy(username_str,p); *pp_username_str = talloc_strdup(ctx, p);
p = p2; p = p2;
} else if (strnequal(set_str,"FSQLIM:",7)) { } else if (strnequal(set_str,"FSQLIM:",7)) {
p +=7; p +=7;
@ -179,7 +185,7 @@ static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA
#endif #endif
return -1; return -1;
} }
break; break;
case PARSE_FLAGS: case PARSE_FLAGS:
while (!stop) { while (!stop) {
@ -211,14 +217,18 @@ static int parse_quota_set(pstring set_str, pstring username_str, enum SMB_QUOTA
} else if (enable) { } else if (enable) {
pqt->qflags |= QUOTAS_ENABLED; pqt->qflags |= QUOTAS_ENABLED;
} }
break; break;
} }
return 0; 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; uint32 fs_attrs = 0;
int quota_fnum = 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)) { if (!(fs_attrs & FILE_VOLUME_QUOTAS)) {
d_printf("Quotas are not supported by the server.\n"); d_printf("Quotas are not supported by the server.\n");
return 0; return 0;
} }
if (!cli_get_quota_handle(cli, &quota_fnum)) { 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); d_printf("StringToSid() failed for [%s]\n",username_str);
return -1; return -1;
} }
switch(cmd) { switch(cmd) {
case QUOTA_GET: case QUOTA_GET:
if (!cli_get_user_quota(cli, quota_fnum, &qt)) { 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; return -1;
} }
dump_ntquota_list(&qtl,verbose,numeric,SidToString); dump_ntquota_list(&qtl,verbose,numeric,SidToString);
free_ntquota_list(&qtl); free_ntquota_list(&qtl);
break; break;
default: default:
d_printf("Unknown Error\n"); d_printf("Unknown Error\n");
return -1; return -1;
} }
break; break;
case SMB_USER_FS_QUOTA_TYPE: case SMB_USER_FS_QUOTA_TYPE:
switch(cmd) { switch(cmd) {
@ -340,7 +350,7 @@ static int do_quota(struct cli_state *cli, enum SMB_QUOTA_TYPE qtype, uint16 cmd
default: default:
d_printf("Unknown Error\n"); d_printf("Unknown Error\n");
return -1; return -1;
} }
break; break;
default: default:
d_printf("Unknown Error\n"); d_printf("Unknown Error\n");
@ -393,9 +403,9 @@ static struct cli_state *connect_one(const char *share)
int opt; int opt;
int result; int result;
int todo = 0; int todo = 0;
pstring username_str = {0}; char *username_str = NULL;
pstring path = {0}; char *path = NULL;
pstring set_str = {0}; char *set_str = NULL;
enum SMB_QUOTA_TYPE qtype = SMB_INVALID_QUOTA_TYPE; enum SMB_QUOTA_TYPE qtype = SMB_INVALID_QUOTA_TYPE;
int cmd = 0; int cmd = 0;
static bool test_args = False; static bool test_args = False;
@ -440,7 +450,7 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
load_interfaces(); load_interfaces();
pc = poptGetContext("smbcquotas", argc, argv, long_options, 0); pc = poptGetContext("smbcquotas", argc, argv, long_options, 0);
poptSetOtherOptionHelp(pc, "//server1/share1"); poptSetOtherOptionHelp(pc, "//server1/share1");
while ((opt = poptGetNextOpt(pc)) != -1) { while ((opt = poptGetNextOpt(pc)) != -1) {
@ -469,23 +479,29 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
} }
todo = FS_QUOTA; todo = FS_QUOTA;
break; break;
case 'u': case 'u':
if (todo != 0) { if (todo != 0) {
d_printf("Please specify only one option of <-L|-F|-S|-u>\n"); d_printf("Please specify only one option of <-L|-F|-S|-u>\n");
exit(EXIT_PARSE_ERROR); 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; todo = USER_QUOTA;
fix_user = True; fix_user = True;
break; break;
case 'S': case 'S':
if (todo != 0) { if (todo != 0) {
d_printf("Please specify only one option of <-L|-F|-S|-u>\n"); d_printf("Please specify only one option of <-L|-F|-S|-u>\n");
exit(EXIT_PARSE_ERROR); 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; todo = SET_QUOTA;
break; break;
} }
@ -494,20 +510,32 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
if (todo == 0) if (todo == 0)
todo = USER_QUOTA; todo = USER_QUOTA;
if (!fix_user) if (!fix_user) {
pstrcpy(username_str,cmdline_auth_info.username); username_str = talloc_strdup(frame, cmdline_auth_info.username);
if (!username_str) {
exit(EXIT_PARSE_ERROR);
}
}
/* Make connection to server */ /* Make connection to server */
if(!poptPeekArg(pc)) { if(!poptPeekArg(pc)) {
poptPrintUsage(pc, stderr, 0); poptPrintUsage(pc, stderr, 0);
exit(EXIT_PARSE_ERROR); 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);
}
pstrcpy(server,path+2); string_replace(path, '/', '\\');
server = SMB_STRDUP(path+2);
if (!server) {
printf("Out of memory\n");
exit(EXIT_PARSE_ERROR);
}
share = strchr_m(server,'\\'); share = strchr_m(server,'\\');
if (!share) { if (!share) {
printf("Invalid argument: %s\n", share); printf("Invalid argument: %s\n", share);
@ -518,7 +546,7 @@ FSQFLAGS:QUOTA_ENABLED/DENY_DISK/LOG_SOFTLIMIT/LOG_HARD_LIMIT", "SETSTRING" },
share++; share++;
if (todo == SET_QUOTA) { 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); printf("Invalid argument: -S %s\n", set_str);
exit(EXIT_PARSE_ERROR); exit(EXIT_PARSE_ERROR);
} }

View File

@ -78,7 +78,7 @@ static void filter_request(char *buf)
{ {
int msg_type = CVAL(buf,0); int msg_type = CVAL(buf,0);
int type = CVAL(buf,smb_com); int type = CVAL(buf,smb_com);
pstring name1,name2; fstring name1,name2;
unsigned x; unsigned x;
if (msg_type) { if (msg_type) {
@ -228,15 +228,15 @@ static void start_filter(char *desthost)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *desthost; char *desthost;
pstring configfile; const char *configfile;
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
load_case_tables(); load_case_tables();
setup_logging(argv[0],True); setup_logging(argv[0],True);
pstrcpy(configfile,dyn_CONFIGFILE); configfile = dyn_CONFIGFILE;
if (argc < 2) { if (argc < 2) {
fprintf(stderr,"smbfilter <desthost> <netbiosname>\n"); fprintf(stderr,"smbfilter <desthost> <netbiosname>\n");
exit(1); exit(1);

View File

@ -83,8 +83,7 @@ static void set_line_buffering(FILE *f)
static int process_options(int argc, char **argv, int local_flags) static int process_options(int argc, char **argv, int local_flags)
{ {
int ch; int ch;
pstring configfile; const char *configfile = dyn_CONFIGFILE;
pstrcpy(configfile, dyn_CONFIGFILE);
local_flags |= LOCAL_SET_PASSWORD; 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; local_flags |= LOCAL_AM_ROOT;
break; break;
case 'c': case 'c':
pstrcpy(configfile,optarg); configfile = optarg;
break; break;
case 'a': case 'a':
local_flags |= LOCAL_ADD_USER; local_flags |= LOCAL_ADD_USER;
@ -163,7 +162,7 @@ static int process_options(int argc, char **argv, int local_flags)
usage(); usage();
} }
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -32,7 +32,7 @@ static enum tree_level level = LEV_SHARE;
struct name_list { struct name_list {
struct name_list *prev, *next; struct name_list *prev, *next;
pstring name, comment; char *name, *comment;
uint32 server_type; uint32 server_type;
}; };
@ -57,10 +57,17 @@ static void add_name(const char *machine_name, uint32 server_type,
ZERO_STRUCTP(new_name); ZERO_STRUCTP(new_name);
pstrcpy(new_name->name, machine_name); new_name->name = SMB_STRDUP(machine_name);
pstrcpy(new_name->comment, comment); new_name->comment = SMB_STRDUP(comment);
new_name->server_type = server_type; 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); 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)) if (get_rpc_shares(cli, add_name, &shares))
return True; return True;
if (!cli_RNetShareEnum(cli, add_name, &shares)) if (!cli_RNetShareEnum(cli, add_name, &shares))
return False; return False;
@ -268,7 +275,7 @@ static bool print_tree(struct user_auth_info *user_info)
POPT_TABLEEND POPT_TABLEEND
}; };
poptContext pc; poptContext pc;
/* Initialise samba stuff */ /* Initialise samba stuff */
load_case_tables(); load_case_tables();
@ -278,7 +285,7 @@ static bool print_tree(struct user_auth_info *user_info)
setup_logging(argv[0],True); 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); POPT_CONTEXT_KEEP_FIRST);
while(poptGetNextOpt(pc) != -1); while(poptGetNextOpt(pc) != -1);
poptFreeContext(pc); poptFreeContext(pc);
@ -291,9 +298,11 @@ static bool print_tree(struct user_auth_info *user_info)
if (!cmdline_auth_info.got_pass) { if (!cmdline_auth_info.got_pass) {
char *pass = getpass("Password: "); char *pass = getpass("Password: ");
if (pass) { 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 */ /* Now do our stuff */

View File

@ -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()) { if((lp_security() == SEC_SERVER || lp_security() >= SEC_DOMAIN) && !lp_passwordserver()) {
pstring sec_setting; const char *sec_setting;
if(lp_security() == SEC_SERVER) if(lp_security() == SEC_SERVER)
pstrcpy(sec_setting, "server"); sec_setting = "server";
else if(lp_security() == SEC_DOMAIN) 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 \ fprintf(stderr, "ERROR: The setting 'security=%s' requires the 'password server' parameter be set \
to a valid password server.\n", sec_setting ); to a valid password server.\n", sec_setting );
ret = 1; ret = 1;
} }
/* /*
* Password chat sanity checks. * Password chat sanity checks.
*/ */
@ -113,16 +114,17 @@ to a valid password server.\n", sec_setting );
parameter.\n" ); parameter.\n" );
ret = 1; ret = 1;
} else { } else {
pstring passwd_prog; const char *passwd_prog;
pstring truncated_prog; char *truncated_prog = NULL;
const char *p; const char *p;
pstrcpy( passwd_prog, lp_passwd_program()); passwd_prog = lp_passwd_program();
p = passwd_prog; p = passwd_prog;
*truncated_prog = '\0'; *truncated_prog = '\0';
next_token(&p, truncated_prog, NULL, sizeof(pstring)); next_token_talloc(talloc_tos(),
&p,
if(access(truncated_prog, F_OK) == -1) { &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) \ 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) ); cannot be executed (error was %s).\n", truncated_prog, strerror(errno) );
ret = 1; ret = 1;