/********************************************************* Start here. **********************************************************/ int main(int argc, char **argv) { TALLOC_CTX *frame = talloc_stackframe(); int local_flags = 0; int ret; #if defined(HAVE_SET_AUTH_PARAMETERS) set_auth_parameters(argc, argv); #endif /* HAVE_SET_AUTH_PARAMETERS */ if (getuid() == 0) { local_flags = LOCAL_AM_ROOT; } smb_init_locale(); local_flags = process_options(argc, argv, local_flags); setup_logging("smbpasswd", DEBUG_STDERR); /* * Set the machine NETBIOS name if not already * set from the config file. */ if (!init_names()) return 1; /* Check the effective uid - make sure we are not setuid */ if (is_setuid_root()) { fprintf(stderr, "smbpasswd must *NOT* be setuid root.\n"); exit(1); } if (local_flags & LOCAL_AM_ROOT) { bool ok; ok = secrets_init(); if (!ok) { return 1; } ret = process_root(local_flags); } else { ret = process_nonroot(local_flags); } TALLOC_FREE(frame); return ret; }
/********************************************************* Start here. **********************************************************/ int main(int argc, char **argv) { int local_flags = 0; AllowDebugChange = False; #if defined(HAVE_SET_AUTH_PARAMETERS) set_auth_parameters(argc, argv); #endif /* HAVE_SET_AUTH_PARAMETERS */ if (getuid() == 0) { local_flags = LOCAL_AM_ROOT; } load_case_tables(); local_flags = process_options(argc, argv, local_flags); setup_logging("smbpasswd", True); /* * Set the machine NETBIOS name if not already * set from the config file. */ if (!init_names()) return 1; /* Check the effective uid - make sure we are not setuid */ if (is_setuid_root()) { fprintf(stderr, "smbpasswd must *NOT* be setuid root.\n"); exit(1); } if (local_flags & LOCAL_AM_ROOT) { secrets_init(); return process_root(local_flags); } return process_nonroot(local_flags); }
struct cli_state *cli_initialise(struct cli_state *cli) { BOOL alloced_cli = False; /* Check the effective uid - make sure we are not setuid */ if (is_setuid_root()) { DEBUG(0,("libsmb based programs must *NOT* be setuid root.\n")); return NULL; } if (!cli) { cli = (struct cli_state *)malloc(sizeof(*cli)); if (!cli) return NULL; ZERO_STRUCTP(cli); alloced_cli = True; } if (cli->initialised) cli_close_connection(cli); ZERO_STRUCTP(cli); cli->port = 0; cli->fd = -1; cli->cnum = -1; cli->pid = (uint16)sys_getpid(); cli->mid = 1; cli->vuid = UID_FIELD_INVALID; cli->protocol = PROTOCOL_NT1; cli->timeout = 20000; /* Timeout is in milliseconds. */ cli->bufsize = CLI_BUFFER_SIZE+4; cli->max_xmit = cli->bufsize; cli->outbuf = (char *)malloc(cli->bufsize); cli->inbuf = (char *)malloc(cli->bufsize); cli->oplock_handler = cli_oplock_ack; /* Set the CLI_FORCE_DOSERR environment variable to test client routines using DOS errors instead of STATUS32 ones. This intended only as a temporary hack. */ if (getenv("CLI_FORCE_DOSERR")) cli->force_dos_errors = True; if (!cli->outbuf || !cli->inbuf) goto error; if ((cli->mem_ctx = talloc_init()) == NULL) goto error; memset(cli->outbuf, 0, cli->bufsize); memset(cli->inbuf, 0, cli->bufsize); cli->nt_pipe_fnum = 0; cli->initialised = 1; cli->allocated = alloced_cli; return cli; /* Clean up after malloc() error */ error: SAFE_FREE(cli->inbuf); SAFE_FREE(cli->outbuf); if (alloced_cli) SAFE_FREE(cli); return NULL; }
struct cli_state *cli_initialise_ex(int signing_state) { struct cli_state *cli = NULL; bool allow_smb_signing = false; bool mandatory_signing = false; /* Check the effective uid - make sure we are not setuid */ if (is_setuid_root()) { DEBUG(0,("libsmb based programs must *NOT* be setuid root.\n")); return NULL; } cli = TALLOC_ZERO_P(NULL, struct cli_state); if (!cli) { return NULL; } cli->dfs_mountpoint = talloc_strdup(cli, ""); if (!cli->dfs_mountpoint) { goto error; } cli->port = 0; cli->fd = -1; cli->cnum = -1; cli->pid = (uint16)sys_getpid(); cli->mid = 1; cli->vuid = UID_FIELD_INVALID; cli->protocol = PROTOCOL_NT1; cli->timeout = 20000; /* Timeout is in milliseconds. */ cli->bufsize = CLI_BUFFER_SIZE+4; cli->max_xmit = cli->bufsize; cli->outbuf = (char *)SMB_MALLOC(cli->bufsize+SAFETY_MARGIN); cli->seqnum = 0; cli->inbuf = (char *)SMB_MALLOC(cli->bufsize+SAFETY_MARGIN); cli->oplock_handler = cli_oplock_ack; cli->case_sensitive = false; cli->smb_rw_error = SMB_READ_OK; cli->use_spnego = lp_client_use_spnego(); cli->capabilities = CAP_UNICODE | CAP_STATUS32 | CAP_DFS; /* Set the CLI_FORCE_DOSERR environment variable to test client routines using DOS errors instead of STATUS32 ones. This intended only as a temporary hack. */ if (getenv("CLI_FORCE_DOSERR")) cli->force_dos_errors = true; if (lp_client_signing()) { allow_smb_signing = true; } if (lp_client_signing() == Required) { mandatory_signing = true; } if (signing_state != Undefined) { allow_smb_signing = true; } if (signing_state == false) { allow_smb_signing = false; mandatory_signing = false; } if (signing_state == Required) { mandatory_signing = true; } if (!cli->outbuf || !cli->inbuf) goto error; memset(cli->outbuf, 0, cli->bufsize); memset(cli->inbuf, 0, cli->bufsize); #if defined(DEVELOPER) /* just because we over-allocate, doesn't mean it's right to use it */ clobber_region(FUNCTION_MACRO, __LINE__, cli->outbuf+cli->bufsize, SAFETY_MARGIN); clobber_region(FUNCTION_MACRO, __LINE__, cli->inbuf+cli->bufsize, SAFETY_MARGIN); #endif /* initialise signing */ cli->signing_state = smb_signing_init(cli, allow_smb_signing, mandatory_signing); if (!cli->signing_state) { goto error; } cli->outgoing = tevent_queue_create(cli, "cli_outgoing"); if (cli->outgoing == NULL) { goto error; } cli->pending = NULL; cli->initialised = 1; return cli; /* Clean up after malloc() error */ error: SAFE_FREE(cli->inbuf); SAFE_FREE(cli->outbuf); TALLOC_FREE(cli); return NULL; }
struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx, int fd, const char *remote_name, const char *remote_realm, int signing_state, int flags) { struct cli_state *cli = NULL; bool use_spnego = lp_client_use_spnego(); bool force_dos_errors = false; bool force_ascii = false; bool use_level_II_oplocks = false; uint32_t smb1_capabilities = 0; uint32_t smb2_capabilities = 0; struct GUID client_guid = GUID_random(); /* Check the effective uid - make sure we are not setuid */ if (is_setuid_root()) { DEBUG(0,("libsmb based programs must *NOT* be setuid root.\n")); return NULL; } cli = talloc_zero(mem_ctx, struct cli_state); if (!cli) { return NULL; } cli->server_domain = talloc_strdup(cli, ""); if (!cli->server_domain) { goto error; } cli->server_os = talloc_strdup(cli, ""); if (!cli->server_os) { goto error; } cli->server_type = talloc_strdup(cli, ""); if (!cli->server_type) { goto error; } cli->dfs_mountpoint = talloc_strdup(cli, ""); if (!cli->dfs_mountpoint) { goto error; } cli->raw_status = NT_STATUS_INTERNAL_ERROR; cli->map_dos_errors = true; /* remove this */ cli->timeout = CLIENT_TIMEOUT; cli->case_sensitive = false; /* Set the CLI_FORCE_DOSERR environment variable to test client routines using DOS errors instead of STATUS32 ones. This intended only as a temporary hack. */ if (getenv("CLI_FORCE_DOSERR")) { force_dos_errors = true; } if (flags & CLI_FULL_CONNECTION_FORCE_DOS_ERRORS) { force_dos_errors = true; } if (getenv("CLI_FORCE_ASCII")) { force_ascii = true; } if (!lp_unicode()) { force_ascii = true; } if (flags & CLI_FULL_CONNECTION_FORCE_ASCII) { force_ascii = true; } if (flags & CLI_FULL_CONNECTION_DONT_SPNEGO) { use_spnego = false; } else if (flags & CLI_FULL_CONNECTION_USE_KERBEROS) { cli->use_kerberos = true; } if ((flags & CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS) && cli->use_kerberos) { cli->fallback_after_kerberos = true; } if (flags & CLI_FULL_CONNECTION_USE_CCACHE) { cli->use_ccache = true; } if (flags & CLI_FULL_CONNECTION_USE_NT_HASH) { cli->pw_nt_hash = true; } if (flags & CLI_FULL_CONNECTION_OPLOCKS) { cli->use_oplocks = true; } if (flags & CLI_FULL_CONNECTION_LEVEL_II_OPLOCKS) { use_level_II_oplocks = true; } if (signing_state == SMB_SIGNING_DEFAULT) { signing_state = lp_client_signing(); } smb1_capabilities = 0; smb1_capabilities |= CAP_LARGE_FILES; smb1_capabilities |= CAP_NT_SMBS | CAP_RPC_REMOTE_APIS; smb1_capabilities |= CAP_LOCK_AND_READ | CAP_NT_FIND; smb1_capabilities |= CAP_DFS | CAP_W2K_SMBS; smb1_capabilities |= CAP_LARGE_READX|CAP_LARGE_WRITEX; smb1_capabilities |= CAP_LWIO; if (!force_dos_errors) { smb1_capabilities |= CAP_STATUS32; } if (!force_ascii) { smb1_capabilities |= CAP_UNICODE; } if (use_spnego) { smb1_capabilities |= CAP_EXTENDED_SECURITY; } if (use_level_II_oplocks) { smb1_capabilities |= CAP_LEVEL_II_OPLOCKS; } smb2_capabilities = SMB2_CAP_ALL; if (remote_realm) { cli->remote_realm = talloc_strdup(cli, remote_realm); if (cli->remote_realm == NULL) { goto error; } } cli->conn = smbXcli_conn_create(cli, fd, remote_name, signing_state, smb1_capabilities, &client_guid, smb2_capabilities); if (cli->conn == NULL) { goto error; } cli->smb1.pid = (uint16_t)getpid(); cli->smb1.vc_num = cli->smb1.pid; cli->smb1.tcon = smbXcli_tcon_create(cli); if (cli->smb1.tcon == NULL) { goto error; } smb1cli_tcon_set_id(cli->smb1.tcon, UINT16_MAX); cli->smb1.session = smbXcli_session_create(cli, cli->conn); if (cli->smb1.session == NULL) { goto error; } cli->initialised = 1; return cli; /* Clean up after malloc() error */ error: TALLOC_FREE(cli); return NULL; }