73
80
Definitions for all names.
74
81
***********************************************************************/
76
static char *smb_myname;
77
static char *smb_myworkgroup;
78
83
static char *smb_scope;
79
84
static int smb_num_netbios_names;
80
85
static char **smb_my_netbios_names;
82
87
/***********************************************************************
83
Allocate and set myname. Ensure upper case.
84
***********************************************************************/
86
bool set_global_myname(const char *myname)
88
SAFE_FREE(smb_myname);
89
smb_myname = SMB_STRDUP(myname);
92
strupper_m(smb_myname);
96
const char *global_myname(void)
101
/***********************************************************************
102
Allocate and set myworkgroup. Ensure upper case.
103
***********************************************************************/
105
bool set_global_myworkgroup(const char *myworkgroup)
107
SAFE_FREE(smb_myworkgroup);
108
smb_myworkgroup = SMB_STRDUP(myworkgroup);
109
if (!smb_myworkgroup)
111
strupper_m(smb_myworkgroup);
115
const char *lp_workgroup(void)
117
return smb_myworkgroup;
120
/***********************************************************************
121
88
Allocate and set scope. Ensure upper case.
122
89
***********************************************************************/
285
/**************************************************************************n
286
Code to cope with username/password auth options from the commandline.
287
Used mainly in client tools.
288
****************************************************************************/
290
struct user_auth_info *user_auth_info_init(TALLOC_CTX *mem_ctx)
292
struct user_auth_info *result;
294
result = TALLOC_ZERO_P(mem_ctx, struct user_auth_info);
295
if (result == NULL) {
299
result->signing_state = Undefined;
303
const char *get_cmdline_auth_info_username(const struct user_auth_info *auth_info)
305
if (!auth_info->username) {
308
return auth_info->username;
311
void set_cmdline_auth_info_username(struct user_auth_info *auth_info,
312
const char *username)
314
TALLOC_FREE(auth_info->username);
315
auth_info->username = talloc_strdup(auth_info, username);
316
if (!auth_info->username) {
321
const char *get_cmdline_auth_info_domain(const struct user_auth_info *auth_info)
323
if (!auth_info->domain) {
326
return auth_info->domain;
329
void set_cmdline_auth_info_domain(struct user_auth_info *auth_info,
332
TALLOC_FREE(auth_info->domain);
333
auth_info->domain = talloc_strdup(auth_info, domain);
334
if (!auth_info->domain) {
339
const char *get_cmdline_auth_info_password(const struct user_auth_info *auth_info)
341
if (!auth_info->password) {
344
return auth_info->password;
347
void set_cmdline_auth_info_password(struct user_auth_info *auth_info,
348
const char *password)
350
TALLOC_FREE(auth_info->password);
351
if (password == NULL) {
354
auth_info->password = talloc_strdup(auth_info, password);
355
if (!auth_info->password) {
358
auth_info->got_pass = true;
361
bool set_cmdline_auth_info_signing_state(struct user_auth_info *auth_info,
364
auth_info->signing_state = -1;
365
if (strequal(arg, "off") || strequal(arg, "no") ||
366
strequal(arg, "false")) {
367
auth_info->signing_state = false;
368
} else if (strequal(arg, "on") || strequal(arg, "yes") ||
369
strequal(arg, "true") || strequal(arg, "auto")) {
370
auth_info->signing_state = true;
371
} else if (strequal(arg, "force") || strequal(arg, "required") ||
372
strequal(arg, "forced")) {
373
auth_info->signing_state = Required;
380
int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info)
382
return auth_info->signing_state;
385
void set_cmdline_auth_info_use_ccache(struct user_auth_info *auth_info, bool b)
387
auth_info->use_ccache = b;
390
bool get_cmdline_auth_info_use_ccache(const struct user_auth_info *auth_info)
392
return auth_info->use_ccache;
395
void set_cmdline_auth_info_use_kerberos(struct user_auth_info *auth_info,
398
auth_info->use_kerberos = b;
401
bool get_cmdline_auth_info_use_kerberos(const struct user_auth_info *auth_info)
403
return auth_info->use_kerberos;
406
void set_cmdline_auth_info_fallback_after_kerberos(struct user_auth_info *auth_info,
409
auth_info->fallback_after_kerberos = b;
412
bool get_cmdline_auth_info_fallback_after_kerberos(const struct user_auth_info *auth_info)
414
return auth_info->fallback_after_kerberos;
417
/* This should only be used by lib/popt_common.c JRA */
418
void set_cmdline_auth_info_use_krb5_ticket(struct user_auth_info *auth_info)
420
auth_info->use_kerberos = true;
421
auth_info->got_pass = true;
424
/* This should only be used by lib/popt_common.c JRA */
425
void set_cmdline_auth_info_smb_encrypt(struct user_auth_info *auth_info)
427
auth_info->smb_encrypt = true;
430
void set_cmdline_auth_info_use_machine_account(struct user_auth_info *auth_info)
432
auth_info->use_machine_account = true;
435
bool get_cmdline_auth_info_got_pass(const struct user_auth_info *auth_info)
437
return auth_info->got_pass;
440
bool get_cmdline_auth_info_smb_encrypt(const struct user_auth_info *auth_info)
442
return auth_info->smb_encrypt;
445
bool get_cmdline_auth_info_use_machine_account(const struct user_auth_info *auth_info)
447
return auth_info->use_machine_account;
450
struct user_auth_info *get_cmdline_auth_info_copy(TALLOC_CTX *mem_ctx,
451
const struct user_auth_info *src)
453
struct user_auth_info *result;
455
result = user_auth_info_init(mem_ctx);
456
if (result == NULL) {
462
result->username = talloc_strdup(
463
result, get_cmdline_auth_info_username(src));
464
result->password = talloc_strdup(
465
result, get_cmdline_auth_info_password(src));
466
if ((result->username == NULL) || (result->password == NULL)) {
474
bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_info)
477
char *account = NULL;
479
if (!get_cmdline_auth_info_use_machine_account(auth_info)) {
483
if (!secrets_init()) {
484
d_printf("ERROR: Unable to open secrets database\n");
488
if (asprintf(&account, "%s$@%s", global_myname(), lp_realm()) < 0) {
492
pass = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
494
d_printf("ERROR: Unable to fetch machine password for "
496
account, lp_workgroup());
501
set_cmdline_auth_info_username(auth_info, account);
502
set_cmdline_auth_info_password(auth_info, pass);
510
/****************************************************************************
511
Ensure we have a password if one not given.
512
****************************************************************************/
514
void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info)
520
if (get_cmdline_auth_info_got_pass(auth_info) ||
521
get_cmdline_auth_info_use_kerberos(auth_info)) {
522
/* Already got one... */
526
frame = talloc_stackframe();
527
label = talloc_asprintf(frame, "Enter %s's password: ",
528
get_cmdline_auth_info_username(auth_info));
529
pass = getpass(label);
531
set_cmdline_auth_info_password(auth_info, pass);
536
251
/*******************************************************************
537
252
Check if a file exists - call vfs_file_exist for samba files.
538
253
********************************************************************/
865
/*******************************************************************
866
Sleep for a specified number of milliseconds.
867
********************************************************************/
869
void smb_msleep(unsigned int t)
871
#if defined(HAVE_NANOSLEEP)
872
struct timespec tval;
875
tval.tv_sec = t/1000;
876
tval.tv_nsec = 1000000*(t%1000);
880
ret = nanosleep(&tval, &tval);
881
} while (ret < 0 && errno == EINTR && (tval.tv_sec > 0 || tval.tv_nsec > 0));
883
unsigned int tdiff=0;
884
struct timeval tval,t1,t2;
891
tval.tv_sec = (t-tdiff)/1000;
892
tval.tv_usec = 1000*((t-tdiff)%1000);
894
/* Never wait for more than 1 sec. */
895
if (tval.tv_sec > 1) {
902
sys_select_intr(0,&fds,NULL,NULL,&tval);
905
if (t2.tv_sec < t1.tv_sec) {
906
/* Someone adjusted time... */
910
tdiff = TvalDiff(&t1,&t2);
915
581
NTSTATUS reinit_after_fork(struct messaging_context *msg_ctx,
916
struct event_context *ev_ctx,
917
bool parent_longlived)
582
struct event_context *ev_ctx,
584
bool parent_longlived)
919
586
NTSTATUS status = NT_STATUS_OK;
2675
bool any_nt_status_not_ok(NTSTATUS err1, NTSTATUS err2, NTSTATUS *result)
2677
if (!NT_STATUS_IS_OK(err1)) {
2681
if (!NT_STATUS_IS_OK(err2)) {
2688
int timeval_to_msec(struct timeval t)
2690
return t.tv_sec * 1000 + (t.tv_usec+999) / 1000;
2693
/*******************************************************************
2694
Check a given DOS pathname is valid for a share.
2695
********************************************************************/
2697
char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname)
2701
if (!dos_pathname) {
2705
ptr = talloc_strdup(ctx, dos_pathname);
2709
/* Convert any '\' paths to '/' */
2711
ptr = unix_clean_name(ctx, ptr);
2716
/* NT is braindead - it wants a C: prefix to a pathname ! So strip it. */
2717
if (strlen(ptr) > 2 && ptr[1] == ':' && ptr[0] != '/')
2720
/* Only absolute paths allowed. */
2727
/*******************************************************************
2728
Return True if the filename is one of the special executable types.
2729
********************************************************************/
2731
bool is_executable(const char *fname)
2733
if ((fname = strrchr_m(fname,'.'))) {
2734
if (strequal(fname,".com") ||
2735
strequal(fname,".dll") ||
2736
strequal(fname,".exe") ||
2737
strequal(fname,".sym")) {
2744
/****************************************************************************
2745
Open a file with a share mode - old openX method - map into NTCreate.
2746
****************************************************************************/
2748
bool map_open_params_to_ntcreate(const char *smb_base_fname,
2749
int deny_mode, int open_func,
2750
uint32 *paccess_mask,
2751
uint32 *pshare_mode,
2752
uint32 *pcreate_disposition,
2753
uint32 *pcreate_options,
2754
uint32_t *pprivate_flags)
2758
uint32 create_disposition;
2759
uint32 create_options = FILE_NON_DIRECTORY_FILE;
2760
uint32_t private_flags = 0;
2762
DEBUG(10,("map_open_params_to_ntcreate: fname = %s, deny_mode = 0x%x, "
2763
"open_func = 0x%x\n",
2764
smb_base_fname, (unsigned int)deny_mode,
2765
(unsigned int)open_func ));
2767
/* Create the NT compatible access_mask. */
2768
switch (GET_OPENX_MODE(deny_mode)) {
2769
case DOS_OPEN_EXEC: /* Implies read-only - used to be FILE_READ_DATA */
2770
case DOS_OPEN_RDONLY:
2771
access_mask = FILE_GENERIC_READ;
2773
case DOS_OPEN_WRONLY:
2774
access_mask = FILE_GENERIC_WRITE;
2778
access_mask = FILE_GENERIC_READ|FILE_GENERIC_WRITE;
2781
DEBUG(10,("map_open_params_to_ntcreate: bad open mode = 0x%x\n",
2782
(unsigned int)GET_OPENX_MODE(deny_mode)));
2786
/* Create the NT compatible create_disposition. */
2787
switch (open_func) {
2788
case OPENX_FILE_EXISTS_FAIL|OPENX_FILE_CREATE_IF_NOT_EXIST:
2789
create_disposition = FILE_CREATE;
2792
case OPENX_FILE_EXISTS_OPEN:
2793
create_disposition = FILE_OPEN;
2796
case OPENX_FILE_EXISTS_OPEN|OPENX_FILE_CREATE_IF_NOT_EXIST:
2797
create_disposition = FILE_OPEN_IF;
2800
case OPENX_FILE_EXISTS_TRUNCATE:
2801
create_disposition = FILE_OVERWRITE;
2804
case OPENX_FILE_EXISTS_TRUNCATE|OPENX_FILE_CREATE_IF_NOT_EXIST:
2805
create_disposition = FILE_OVERWRITE_IF;
2809
/* From samba4 - to be confirmed. */
2810
if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_EXEC) {
2811
create_disposition = FILE_CREATE;
2814
DEBUG(10,("map_open_params_to_ntcreate: bad "
2815
"open_func 0x%x\n", (unsigned int)open_func));
2819
/* Create the NT compatible share modes. */
2820
switch (GET_DENY_MODE(deny_mode)) {
2822
share_mode = FILE_SHARE_NONE;
2826
share_mode = FILE_SHARE_READ;
2830
share_mode = FILE_SHARE_WRITE;
2834
share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE;
2838
private_flags |= NTCREATEX_OPTIONS_PRIVATE_DENY_DOS;
2839
if (is_executable(smb_base_fname)) {
2840
share_mode = FILE_SHARE_READ|FILE_SHARE_WRITE;
2842
if (GET_OPENX_MODE(deny_mode) == DOS_OPEN_RDONLY) {
2843
share_mode = FILE_SHARE_READ;
2845
share_mode = FILE_SHARE_NONE;
2851
private_flags |= NTCREATEX_OPTIONS_PRIVATE_DENY_FCB;
2852
share_mode = FILE_SHARE_NONE;
2856
DEBUG(10,("map_open_params_to_ntcreate: bad deny_mode 0x%x\n",
2857
(unsigned int)GET_DENY_MODE(deny_mode) ));
2861
DEBUG(10,("map_open_params_to_ntcreate: file %s, access_mask = 0x%x, "
2862
"share_mode = 0x%x, create_disposition = 0x%x, "
2863
"create_options = 0x%x private_flags = 0x%x\n",
2865
(unsigned int)access_mask,
2866
(unsigned int)share_mode,
2867
(unsigned int)create_disposition,
2868
(unsigned int)create_options,
2869
(unsigned int)private_flags));
2872
*paccess_mask = access_mask;
2875
*pshare_mode = share_mode;
2877
if (pcreate_disposition) {
2878
*pcreate_disposition = create_disposition;
2880
if (pcreate_options) {
2881
*pcreate_options = create_options;
2883
if (pprivate_flags) {
2884
*pprivate_flags = private_flags;