void winbindd_wins_byname(struct winbindd_cli_state *state) { struct sockaddr_storage *ip_list = NULL; int i, count, maxlen, size; fstring response; char addr[INET6_ADDRSTRLEN]; /* Ensure null termination */ state->request->data.winsreq[sizeof(state->request->data.winsreq)-1]='\0'; DEBUG(3, ("[%5lu]: wins_byname %s\n", (unsigned long)state->pid, state->request->data.winsreq)); *response = '\0'; maxlen = sizeof(response) - 1; ip_list = lookup_byname_backend( state->mem_ctx, state->request->data.winsreq, &count); if (ip_list != NULL){ for (i = count; i ; i--) { print_sockaddr(addr, sizeof(addr), &ip_list[i-1]); size = strlen(addr); if (size > maxlen) { TALLOC_FREE(ip_list); request_error(state); return; } if (i != 0) { /* Clear out the newline character */ /* But only if there is something in there, otherwise we clobber something in the stack */ if (strlen(response)) { response[strlen(response)-1] = ' '; } } fstrcat(response,addr); fstrcat(response,"\t"); } size = strlen(state->request->data.winsreq) + strlen(response); if (size > maxlen) { TALLOC_FREE(ip_list); request_error(state); return; } fstrcat(response,state->request->data.winsreq); fstrcat(response,"\n"); TALLOC_FREE(ip_list); } else { request_error(state); return; } fstrcpy(state->response->data.winsresp,response); request_ok(state); }
enum winbindd_result winbindd_wins_byname(struct winbindd_cli_state *state) { struct in_addr *ip_list; int i, count, maxlen, size; fstring response; char * addr; /* Ensure null termination */ state->request.data.winsreq[sizeof(state->request.data.winsreq)-1]='\0'; DEBUG(3, ("[%5lu]: wins_byname %s\n", (unsigned long)state->pid, state->request.data.winsreq)); *response = '\0'; maxlen = sizeof(response) - 1; if ((ip_list = lookup_byname_backend(state->request.data.winsreq,&count))){ for (i = count; i ; i--) { addr = inet_ntoa(ip_list[i-1]); size = strlen(addr); if (size > maxlen) { SAFE_FREE(ip_list); return WINBINDD_ERROR; } if (i != 0) { /* Clear out the newline character */ /* But only if there is something in there, otherwise we clobber something in the stack */ if (strlen(response)) response[strlen(response)-1] = ' '; } fstrcat(response,addr); fstrcat(response,"\t"); } size = strlen(state->request.data.winsreq) + strlen(response); if (size > maxlen) { SAFE_FREE(ip_list); return WINBINDD_ERROR; } fstrcat(response,state->request.data.winsreq); fstrcat(response,"\n"); SAFE_FREE(ip_list); } else return WINBINDD_ERROR; fstrcpy(state->response.data.winsresp,response); return WINBINDD_OK; }
static int delete_machine_entry (struct pdb_methods *in, const char *machinename) { fstring name; struct samu *samaccount = NULL; if (strlen(machinename) == 0) { fprintf(stderr, "No machine name given\n"); return -1; } fstrcpy(name, machinename); name[15] = '\0'; if (name[strlen(name)-1] != '$') fstrcat (name, "$"); if ( (samaccount = samu_new( NULL )) == NULL ) { return -1; } if (!NT_STATUS_IS_OK(in->getsampwnam(in, samaccount, name))) { fprintf (stderr, "machine %s does not exist in the passdb\n", name); return -1; } if (!NT_STATUS_IS_OK(in->delete_sam_account (in, samaccount))) { fprintf (stderr, "Unable to delete machine %s\n", name); return -1; } return 0; }
char *sid_to_string(fstring sidstr_out, const DOM_SID *sid) { char subauth[16]; int i; uint32 ia; if (!sid) { fstrcpy(sidstr_out, "(NULL SID)"); return sidstr_out; } /* * BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 * in a range of 2^48. */ ia = (sid->id_auth[5]) + (sid->id_auth[4] << 8 ) + (sid->id_auth[3] << 16) + (sid->id_auth[2] << 24); slprintf(sidstr_out, sizeof(fstring) - 1, "S-%u-%lu", (unsigned int)sid->sid_rev_num, (unsigned long)ia); for (i = 0; i < sid->num_auths; i++) { slprintf(subauth, sizeof(subauth)-1, "-%lu", (unsigned long)sid->sub_auths[i]); fstrcat(sidstr_out, subauth); } return sidstr_out; }
static int do_message_op(void) { struct in_addr ip; struct nmb_name called, calling; fstring server_name; char name_type_hex[10]; make_nmb_name(&calling, global_myname(), 0x0); make_nmb_name(&called , desthost, name_type); fstrcpy(server_name, desthost); snprintf(name_type_hex, sizeof(name_type_hex), "#%X", name_type); fstrcat(server_name, name_type_hex); zero_ip(&ip); if (!(cli=cli_initialise(NULL)) || (cli_set_port(cli, port) != port) || !cli_connect(cli, server_name, &ip)) { d_printf("Connection to %s failed\n", desthost); return 1; } if (!cli_session_request(cli, &calling, &called)) { d_printf("session request failed\n"); cli_shutdown(cli); return 1; } send_message(); cli_shutdown(cli); return 0; }
void winbindd_wins_byip(struct winbindd_cli_state *state) { fstring response; int i, count, maxlen, size; struct node_status *status; /* Ensure null termination */ state->request->data.winsreq[sizeof(state->request->data.winsreq)-1]='\0'; DEBUG(3, ("[%5lu]: wins_byip %s\n", (unsigned long)state->pid, state->request->data.winsreq)); *response = '\0'; maxlen = sizeof(response) - 1; if ((status = lookup_byaddr_backend( state->mem_ctx, state->request->data.winsreq, &count))) { size = strlen(state->request->data.winsreq); if (size > maxlen) { TALLOC_FREE(status); request_error(state); return; } fstrcat(response,state->request->data.winsreq); fstrcat(response,"\t"); for (i = 0; i < count; i++) { /* ignore group names */ if (status[i].flags & 0x80) continue; if (status[i].type == 0x20) { size = sizeof(status[i].name) + strlen(response); if (size > maxlen) { TALLOC_FREE(status); request_error(state); return; } fstrcat(response, status[i].name); fstrcat(response, " "); } } /* make last character a newline */ response[strlen(response)-1] = '\n'; TALLOC_FREE(status); } fstrcpy(state->response->data.winsresp,response); request_ok(state); }
/**************************************************************************** interpret a node status response ****************************************************************************/ static void _interpret_node_status(char *p, char *master,char *rname) { int numnames = CVAL(p,0); DEBUG(1,("received %d names\n",numnames)); if (rname) *rname = 0; if (master) *master = 0; p += 1; while (numnames--) { char qname[17]; int type; fstring flags; int i; *flags = 0; StrnCpy(qname,p,15); type = CVAL(p,15); p += 16; fstrcat(flags, (p[0] & 0x80) ? "<GROUP> " : " "); if ((p[0] & 0x60) == 0x00) fstrcat(flags,"B "); if ((p[0] & 0x60) == 0x20) fstrcat(flags,"P "); if ((p[0] & 0x60) == 0x40) fstrcat(flags,"M "); if ((p[0] & 0x60) == 0x60) fstrcat(flags,"H "); if (p[0] & 0x10) fstrcat(flags,"<DEREGISTERING> "); if (p[0] & 0x08) fstrcat(flags,"<CONFLICT> "); if (p[0] & 0x04) fstrcat(flags,"<ACTIVE> "); if (p[0] & 0x02) fstrcat(flags,"<PERMANENT> "); if (master && !*master && type == 0x1d) { StrnCpy(master,qname,15); trim_string(master,NULL," "); } if (rname && !*rname && type == 0x20 && !(p[0]&0x80)) { StrnCpy(rname,qname,15); trim_string(rname,NULL," "); } for (i = strlen( qname) ; --i >= 0 ; ) { if (!isprint((int)qname[i])) qname[i] = '.'; } DEBUG(1,("\t%-15s <%02x> - %s\n",qname,type,flags)); p+=2; } DEBUG(1,("num_good_sends=%d num_good_receives=%d\n", IVAL(p,20),IVAL(p,24))); }
/**************************************************************************** turn a node status flags field into a string ****************************************************************************/ static char *node_status_flags(unsigned char flags) { static fstring ret; fstrcpy(ret,""); fstrcat(ret, (flags & 0x80) ? "<GROUP> " : " "); if ((flags & 0x60) == 0x00) fstrcat(ret,"B "); if ((flags & 0x60) == 0x20) fstrcat(ret,"P "); if ((flags & 0x60) == 0x40) fstrcat(ret,"M "); if ((flags & 0x60) == 0x60) fstrcat(ret,"H "); if (flags & 0x10) fstrcat(ret,"<DEREGISTERING> "); if (flags & 0x08) fstrcat(ret,"<CONFLICT> "); if (flags & 0x04) fstrcat(ret,"<ACTIVE> "); if (flags & 0x02) fstrcat(ret,"<PERMANENT> "); return ret; }
static char *query_flags(int flags) { static fstring ret1; fstrcpy(ret1, ""); if (flags & NM_FLAGS_RS) fstrcat(ret1, "Response "); if (flags & NM_FLAGS_AA) fstrcat(ret1, "Authoritative "); if (flags & NM_FLAGS_TC) fstrcat(ret1, "Truncated "); if (flags & NM_FLAGS_RD) fstrcat(ret1, "Recursion_Desired "); if (flags & NM_FLAGS_RA) fstrcat(ret1, "Recursion_Available "); if (flags & NM_FLAGS_B) fstrcat(ret1, "Broadcast "); return ret1; }
static void dos_mode_debug_print(const char *func, uint32_t mode) { fstring modestr; if (DEBUGLEVEL < DBGLVL_INFO) { return; } modestr[0] = '\0'; if (mode & FILE_ATTRIBUTE_HIDDEN) { fstrcat(modestr, "h"); } if (mode & FILE_ATTRIBUTE_READONLY) { fstrcat(modestr, "r"); } if (mode & FILE_ATTRIBUTE_SYSTEM) { fstrcat(modestr, "s"); } if (mode & FILE_ATTRIBUTE_DIRECTORY) { fstrcat(modestr, "d"); } if (mode & FILE_ATTRIBUTE_ARCHIVE) { fstrcat(modestr, "a"); } if (mode & FILE_ATTRIBUTE_SPARSE) { fstrcat(modestr, "[sparse]"); } if (mode & FILE_ATTRIBUTE_OFFLINE) { fstrcat(modestr, "[offline]"); } if (mode & FILE_ATTRIBUTE_COMPRESSED) { fstrcat(modestr, "[compressed]"); } DBG_INFO("%s returning (0x%x): \"%s\"\n", func, (unsigned)mode, modestr); }
BOOL cli_nt_session_open(struct cli_state *cli, const int pipe_idx) { int fnum; /* At the moment we can't have more than one pipe open over a cli connection. )-: */ SMB_ASSERT(cli->nt_pipe_fnum == 0); /* The pipe index must fall within our array */ SMB_ASSERT((pipe_idx >= 0) && (pipe_idx < PI_MAX_PIPES)); if (cli->capabilities & CAP_NT_SMBS) { if ((fnum = cli_nt_create(cli, &pipe_names[pipe_idx].client_pipe[5], DESIRED_ACCESS_PIPE)) == -1) { DEBUG(0,("cli_nt_session_open: cli_nt_create failed on pipe %s to machine %s. Error was %s\n", &pipe_names[pipe_idx].client_pipe[5], cli->desthost, cli_errstr(cli))); return False; } cli->nt_pipe_fnum = (uint16)fnum; } else { if ((fnum = cli_open(cli, pipe_names[pipe_idx].client_pipe, O_CREAT|O_RDWR, DENY_NONE)) == -1) { DEBUG(1,("cli_nt_session_open: cli_open failed on pipe %s to machine %s. Error was %s\n", pipe_names[pipe_idx].client_pipe, cli->desthost, cli_errstr(cli))); return False; } cli->nt_pipe_fnum = (uint16)fnum; /**************** Set Named Pipe State ***************/ if (!rpc_pipe_set_hnd_state(cli, pipe_names[pipe_idx].client_pipe, 0x4300)) { DEBUG(0,("cli_nt_session_open: pipe hnd state failed. Error was %s\n", cli_errstr(cli))); cli_close(cli, cli->nt_pipe_fnum); cli->nt_pipe_fnum = 0; return False; } } /******************* bind request on pipe *****************/ if (!rpc_pipe_bind(cli, pipe_idx, global_myname())) { DEBUG(2,("cli_nt_session_open: rpc bind to %s failed\n", get_pipe_name_from_index(pipe_idx))); cli_close(cli, cli->nt_pipe_fnum); cli->nt_pipe_fnum = 0; return False; } cli->pipe_idx = pipe_idx; /* * Setup the remote server name prefixed by \ and the machine account name. */ fstrcpy(cli->srv_name_slash, "\\\\"); fstrcat(cli->srv_name_slash, cli->desthost); strupper_m(cli->srv_name_slash); fstrcpy(cli->clnt_name_slash, "\\\\"); fstrcat(cli->clnt_name_slash, global_myname()); strupper_m(cli->clnt_name_slash); fstrcpy(cli->mach_acct, global_myname()); fstrcat(cli->mach_acct, "$"); strupper_m(cli->mach_acct); /* Remember which pipe we're talking to */ fstrcpy(cli->pipe_name, pipe_names[pipe_idx].client_pipe); return True; }
static int print_command(int argc, char **argv) { char *printer; fstring keystr; struct passwd *pw; TDB_DATA value; struct vlp_job job; int i; if (argc < 3) { printf("Usage: print <printername> <jobname>\n"); return 1; } printer = argv[1]; ZERO_STRUCT(job); /* Create a job record */ for (i = 2; i < argc; i++) { fstrcat(job.jobname, argv[i]); if (i < argc - 1) { fstrcat(job.jobname, " "); } } if (!(pw = sys_getpwuid(getuid()))) { return 1; } fstrcpy(job.owner, pw->pw_name); job.jobid = next_jobnum(printer); job.size = 666; job.submit_time = time(NULL); /* Store job entry in queue */ slprintf(keystr, sizeof(keystr) - 1, "LPQ/%s", printer); value = tdb_fetch_by_string(tdb, keystr); if (value.dptr) { /* Add job to end of queue */ value.dptr = realloc(value.dptr, value.dsize + sizeof(struct vlp_job)); if (!value.dptr) return 1; memcpy(value.dptr + value.dsize, &job, sizeof(struct vlp_job)); tdb_store_by_string(tdb, keystr, value.dptr, value.dsize + sizeof(struct vlp_job)); free(value.dptr); } else { /* Create new queue */ tdb_store_by_string(tdb, keystr, &job, sizeof(struct vlp_job)); } return 0; }
static NTSTATUS check_smbserver_security(const struct auth_context *auth_context, void *my_private_data, TALLOC_CTX *mem_ctx, const auth_usersupplied_info *user_info, auth_serversupplied_info **server_info) { struct cli_state *cli; static unsigned char badpass[24]; static fstring baduser; static BOOL tested_password_server = False; static BOOL bad_password_server = False; NTSTATUS nt_status = NT_STATUS_NOT_IMPLEMENTED; BOOL locally_made_cli = False; cli = (struct cli_state *)my_private_data; if (cli) { } else { cli = server_cryptkey(mem_ctx); locally_made_cli = True; } if (!cli || !cli->initialised) { DEBUG(1,("password server is not connected (cli not initilised)\n")); return NT_STATUS_LOGON_FAILURE; } if ((cli->sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) == 0) { if (user_info->encrypted) { DEBUG(1,("password server %s is plaintext, but we are encrypted. This just can't work :-(\n", cli->desthost)); return NT_STATUS_LOGON_FAILURE; } } else { if (memcmp(cli->secblob.data, auth_context->challenge.data, 8) != 0) { DEBUG(1,("the challenge that the password server (%s) supplied us is not the one we gave our client. This just can't work :-(\n", cli->desthost)); return NT_STATUS_LOGON_FAILURE; } } if(badpass[0] == 0) memset(badpass, 0x1f, sizeof(badpass)); if((user_info->nt_resp.length == sizeof(badpass)) && !memcmp(badpass, user_info->nt_resp.data, sizeof(badpass))) { /* * Very unlikely, our random bad password is the same as the users * password. */ memset(badpass, badpass[0]+1, sizeof(badpass)); } if(baduser[0] == 0) { fstrcpy(baduser, INVALID_USER_PREFIX); fstrcat(baduser, global_myname()); } /* * Attempt a session setup with a totally incorrect password. * If this succeeds with the guest bit *NOT* set then the password * server is broken and is not correctly setting the guest bit. We * need to detect this as some versions of NT4.x are broken. JRA. */ /* I sure as hell hope that there aren't servers out there that take * NTLMv2 and have this bug, as we don't test for that... * - [email protected] */ if ((!tested_password_server) && (lp_paranoid_server_security())) { if (NT_STATUS_IS_OK(cli_session_setup(cli, baduser, (char *)badpass, sizeof(badpass), (char *)badpass, sizeof(badpass), user_info->domain))) { /* * We connected to the password server so we * can say we've tested it. */ tested_password_server = True; if ((SVAL(cli->inbuf,smb_vwv2) & 1) == 0) { DEBUG(0,("server_validate: password server %s allows users as non-guest \ with a bad password.\n", cli->desthost)); DEBUG(0,("server_validate: This is broken (and insecure) behaviour. Please do not \ use this machine as the password server.\n")); cli_ulogoff(cli); /* * Password server has the bug. */ bad_password_server = True; return NT_STATUS_LOGON_FAILURE; } cli_ulogoff(cli); }
static NTSTATUS gpo_sync_func(const char *mnt, struct file_info *info, const char *mask, void *state) { NTSTATUS result; struct sync_context *ctx; fstring nt_filename, unix_filename; fstring nt_dir, unix_dir; char *old_nt_dir, *old_unix_dir; ctx = (struct sync_context *)state; if (strequal(info->name, ".") || strequal(info->name, "..")) { return NT_STATUS_OK; } DEBUG(5,("gpo_sync_func: got mask: [%s], name: [%s]\n", mask, info->name)); if (info->mode & FILE_ATTRIBUTE_DIRECTORY) { DEBUG(3,("got dir: [%s]\n", info->name)); fstrcpy(nt_dir, ctx->remote_path); fstrcat(nt_dir, "\\"); fstrcat(nt_dir, info->name); fstrcpy(unix_dir, ctx->local_path); fstrcat(unix_dir, "/"); fstrcat(unix_dir, info->name); result = gpo_copy_dir(unix_dir); if (!NT_STATUS_IS_OK(result)) { DEBUG(1,("failed to copy dir: %s\n", nt_errstr(result))); return result; } old_nt_dir = ctx->remote_path; ctx->remote_path = talloc_strdup(ctx->mem_ctx, nt_dir); old_unix_dir = ctx->local_path; ctx->local_path = talloc_strdup(ctx->mem_ctx, unix_dir); ctx->mask = talloc_asprintf(ctx->mem_ctx, "%s\\*", nt_dir); if (!ctx->local_path || !ctx->mask || !ctx->remote_path) { DEBUG(0,("gpo_sync_func: ENOMEM\n")); return NT_STATUS_NO_MEMORY; } result = gpo_sync_files(ctx); if (!NT_STATUS_IS_OK(result)) { DEBUG(0,("could not sync files\n")); return result; } ctx->remote_path = old_nt_dir; ctx->local_path = old_unix_dir; return NT_STATUS_OK; } DEBUG(3,("got file: [%s]\n", info->name)); fstrcpy(nt_filename, ctx->remote_path); fstrcat(nt_filename, "\\"); fstrcat(nt_filename, info->name); fstrcpy(unix_filename, ctx->local_path); fstrcat(unix_filename, "/"); fstrcat(unix_filename, info->name); result = gpo_copy_file(ctx->mem_ctx, ctx->cli, nt_filename, unix_filename); if (!NT_STATUS_IS_OK(result)) { DEBUG(1,("failed to copy file: %s\n", nt_errstr(result))); } return result; }
/**************************************************************************** nt lsa query ****************************************************************************/ void cmd_lsa_lookup_sids(struct client_info *info) { fstring temp; int i; fstring sid_name; fstring srv_name; DOM_SID sid[10]; DOM_SID *sids[10]; int num_sids = 0; char **names = NULL; int num_names = 0; BOOL res = True; fstrcpy(srv_name, "\\\\"); fstrcat(srv_name, info->myhostname); strupper(srv_name); DEBUG(4,("cmd_lsa_lookup_sids: server: %s\n", srv_name)); while (num_sids < 10 && next_token(NULL, temp, NULL, sizeof(temp))) { if (strnequal("S-", temp, 2)) { fstrcpy(sid_name, temp); } else { sid_to_string(sid_name, &info->dom.level5_sid); if (sid_name[0] == 0) { fprintf(out_hnd, "please use lsaquery first or specify a complete SID\n"); return; } fstrcat(sid_name, "-"); fstrcat(sid_name, temp); } init_dom_sid(&sid[num_sids], sid_name); sids[num_sids] = &sid[num_sids]; num_sids++; } if (num_sids == 0) { fprintf(out_hnd, "lookupsid RID or SID\n"); return; } /* open LSARPC session. */ res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC) : False; /* lookup domain controller; receive a policy handle */ res = res ? do_lsa_open_policy(smb_cli, srv_name, &info->dom.lsa_info_pol, True) : False; /* send lsa lookup sids call */ res = res ? do_lsa_lookup_sids(smb_cli, &info->dom.lsa_info_pol, num_sids, sids, &names, &num_names) : False; res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False; /* close the session */ cli_nt_session_close(smb_cli); if (res) { DEBUG(5,("cmd_lsa_lookup_sids: query succeeded\n")); } else { DEBUG(5,("cmd_lsa_lookup_sids: query failed\n")); } if (names != NULL) { fprintf(out_hnd,"Lookup SIDS:\n"); for (i = 0; i < num_names; i++) { sid_to_string(temp, sids[i]); fprintf(out_hnd, "SID: %s -> %s\n", temp, names[i]); if (names[i] != NULL) { free(names[i]); } } free(names); } }
/**************************************************************************** nt lsa query ****************************************************************************/ void cmd_lsa_query_info(struct client_info *info) { fstring srv_name; BOOL res = True; fstrcpy(info->dom.level3_dom, ""); fstrcpy(info->dom.level5_dom, ""); ZERO_STRUCT(info->dom.level3_sid); ZERO_STRUCT(info->dom.level5_sid); fstrcpy(srv_name, "\\\\"); fstrcat(srv_name, info->myhostname); strupper(srv_name); DEBUG(4,("cmd_lsa_query_info: server:%s\n", srv_name)); DEBUG(5, ("cmd_lsa_query_info: smb_cli->fd:%d\n", smb_cli->fd)); /* open LSARPC session. */ res = res ? cli_nt_session_open(smb_cli, PIPE_LSARPC) : False; /* lookup domain controller; receive a policy handle */ res = res ? do_lsa_open_policy(smb_cli, srv_name, &info->dom.lsa_info_pol, False) : False; /* send client info query, level 3. receive domain name and sid */ res = res ? do_lsa_query_info_pol(smb_cli, &info->dom.lsa_info_pol, 0x03, info->dom.level3_dom, &info->dom.level3_sid) : False; /* send client info query, level 5. receive domain name and sid */ res = res ? do_lsa_query_info_pol(smb_cli, &info->dom.lsa_info_pol, 0x05, info->dom.level5_dom, &info->dom.level5_sid) : False; res = res ? do_lsa_close(smb_cli, &info->dom.lsa_info_pol) : False; /* close the session */ cli_nt_session_close(smb_cli); if (res) { BOOL domain_something = False; fstring sid; DEBUG(5,("cmd_lsa_query_info: query succeeded\n")); fprintf(out_hnd, "LSA Query Info Policy\n"); if (info->dom.level3_dom[0] != 0) { sid_to_string(sid, &info->dom.level3_sid); fprintf(out_hnd, "Domain Member - Domain: %s SID: %s\n", info->dom.level3_dom, sid); domain_something = True; } if (info->dom.level5_dom[0] != 0) { sid_to_string(sid, &info->dom.level5_sid); fprintf(out_hnd, "Domain Controller - Domain: %s SID: %s\n", info->dom.level5_dom, sid); domain_something = True; } if (!domain_something) { fprintf(out_hnd, "%s is not a Domain Member or Controller\n", info->dest_host); } } else { DEBUG(5,("cmd_lsa_query_info: query failed\n")); } }
static int join_domain_byuser(char *domain, const char *remote, char *username, char *password) { /* libsmb variables */ pstring pdc_name; struct nmb_name calling, called; struct ntuser_creds creds; struct cli_state cli; fstring acct_name; struct in_addr dest_ip; TALLOC_CTX *mem_ctx; /* rpc variables */ POLICY_HND lsa_pol, sam_pol, domain_pol, user_pol; DOM_SID domain_sid; uint32 user_rid; /* Password stuff */ char *machine_pwd; int plen = 0; uchar pwbuf[516], ntpw[16], sess_key[16]; SAM_USERINFO_CTR ctr; SAM_USER_INFO_24 p24; SAM_USER_INFO_10 p10; /* Misc */ NTSTATUS result; int retval = 1; pstrcpy(pdc_name, remote ? remote : ""); /* Connect to remote machine */ ZERO_STRUCT(cli); ZERO_STRUCT(creds); ZERO_STRUCT(dest_ip); /* Make sure no nasty surprises */ if (!(mem_ctx = talloc_init())) { DEBUG(0, ("Could not initialise talloc context\n")); goto done; } if (!cli_initialise(&cli)) { DEBUG(0, ("Could not initialise client structure\n")); goto done; } init_rpcclient_creds(&creds, username, domain, password); cli_init_creds(&cli, &creds); /* * If we are given a remote machine assume this is the PDC. */ if(remote == NULL || !strcmp(remote, "*")) { struct in_addr *ip_list; int addr_count; if (!get_dc_list(True /* PDC only*/, domain, &ip_list, &addr_count)) { fprintf(stderr, "Unable to find the domain controller for domain %s.\n", domain); return 1; } if ((addr_count < 1) || (is_zero_ip(ip_list[0]))) { fprintf(stderr, "Incorrect entries returned when finding the domain controller for domain %s.\n", domain); return 1; } if (!lookup_dc_name(global_myname, domain, &ip_list[0], pdc_name)) { fprintf(stderr, "Unable to lookup the name for the domain controller for domain %s.\n", domain); return 1; } dest_ip = ip_list[0]; } make_nmb_name(&called, pdc_name, 0x20); make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0); if (!cli_establish_connection(&cli, pdc_name, &dest_ip, &calling, &called, "IPC$", "IPC", False, True)) { if (!NT_STATUS_IS_OK(cli_nt_error(&cli))) { DEBUG(0, ("Error connecting to %s - %s\n", pdc_name,cli_errstr(&cli))); } else { DEBUG(0, ("Error connecting to %s\n", pdc_name)); } goto done; } /* Fetch domain sid */ if (!cli_nt_session_open(&cli, PIPE_LSARPC)) { DEBUG(0, ("Error connecting to SAM pipe\n")); goto done; } CHECK_RPC_ERR(cli_lsa_open_policy(&cli, mem_ctx, True, SEC_RIGHTS_MAXIMUM_ALLOWED, &lsa_pol), "error opening lsa policy handle"); CHECK_RPC_ERR(cli_lsa_query_info_policy(&cli, mem_ctx, &lsa_pol, 5, domain, &domain_sid), "error querying info policy"); cli_lsa_close(&cli, mem_ctx, &lsa_pol); cli_nt_session_close(&cli); /* Done with this pipe */ /* Create domain user */ if (!cli_nt_session_open(&cli, PIPE_SAMR)) { DEBUG(0, ("Error connecting to SAM pipe\n")); goto done; } CHECK_RPC_ERR(cli_samr_connect(&cli, mem_ctx, SEC_RIGHTS_MAXIMUM_ALLOWED, &sam_pol), "could not connect to SAM database"); CHECK_RPC_ERR(cli_samr_open_domain(&cli, mem_ctx, &sam_pol, SEC_RIGHTS_MAXIMUM_ALLOWED, &domain_sid, &domain_pol), "could not open domain"); /* Create domain user */ fstrcpy(acct_name, global_myname); fstrcat(acct_name, "$"); strlower(acct_name); { uint32 unknown = 0xe005000b; result = cli_samr_create_dom_user(&cli, mem_ctx, &domain_pol, acct_name, ACB_WSTRUST, unknown, &user_pol, &user_rid); } if (NT_STATUS_IS_OK(result)) { /* We *must* do this.... don't ask... */ CHECK_RPC_ERR_DEBUG(cli_samr_close(&cli, mem_ctx, &user_pol), ("error closing user policy")); result = NT_STATUS_USER_EXISTS; } if (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_USER_EXISTS)) { uint32 num_rids, *name_types, *user_rids; uint32 flags = 0x3e8; const char *names; /* Look up existing rid */ names = (char *)&acct_name[0]; CHECK_RPC_ERR_DEBUG( cli_samr_lookup_names(&cli, mem_ctx, &domain_pol, flags, 1, &names, &num_rids, &user_rids, &name_types), ("error looking up rid for user %s: %s\n", acct_name, get_nt_error_msg(result))); if (name_types[0] != SID_NAME_USER) { DEBUG(0, ("%s is not a user account\n", acct_name)); goto done; } user_rid = user_rids[0]; /* Open handle on user */ CHECK_RPC_ERR_DEBUG( cli_samr_open_user(&cli, mem_ctx, &domain_pol, SEC_RIGHTS_MAXIMUM_ALLOWED, user_rid, &user_pol), ("could not re-open existing user %s: %s\n", acct_name, get_nt_error_msg(result))); } else if (!NT_STATUS_IS_OK(result)) { DEBUG(0, ("error creating domain user: %s\n", get_nt_error_msg(result))); goto done; } /* Create a random machine account password */ { UNISTR2 upw; /* Unicode password */ upw.buffer = (uint16 *)talloc_zero(mem_ctx, 0xc * sizeof(uint16)); upw.uni_str_len = 0xc; upw.uni_max_len = 0xc; machine_pwd = (char *)upw.buffer; plen = upw.uni_str_len * 2; generate_random_buffer((unsigned char *)machine_pwd, plen, True); encode_pw_buffer((char *)pwbuf, machine_pwd, plen, False); mdfour( ntpw, (unsigned char *)upw.buffer, plen); } /* Set password on machine account */ ZERO_STRUCT(ctr); ZERO_STRUCT(p24); init_sam_user_info24(&p24, (char *)pwbuf,24); ctr.switch_value = 24; ctr.info.id24 = &p24; /* I don't think this is quite the right place for this calculation. It should be moved somewhere where the credentials are calculated. )-: */ mdfour(sess_key, cli.pwd.smb_nt_pwd, 16); CHECK_RPC_ERR(cli_samr_set_userinfo(&cli, mem_ctx, &user_pol, 24, sess_key, &ctr), "error setting trust account password"); /* Why do we have to try to (re-)set the ACB to be the same as what we passed in the samr_create_dom_user() call? When a NT workstation is joined to a domain by an administrator the acb_info is set to 0x80. For a normal user with "Add workstations to the domain" rights the acb_info is 0x84. I'm not sure whether it is supposed to make a difference or not. NT seems to cope with either value so don't bomb out if the set userinfo2 level 0x10 fails. -tpot */ ZERO_STRUCT(ctr); ctr.switch_value = 0x10; ctr.info.id10 = &p10; init_sam_user_info10(&p10, ACB_WSTRUST); /* Ignoring the return value is necessary for joining a domain as a normal user with "Add workstation to domain" privilege. */ result = cli_samr_set_userinfo2(&cli, mem_ctx, &user_pol, 0x10, sess_key, &ctr); /* Now store the secret in the secrets database */ strupper(domain); if (!secrets_store_domain_sid(domain, &domain_sid) || !secrets_store_trust_account_password(domain, ntpw)) { DEBUG(0, ("error storing domain secrets\n")); goto done; } retval = 0; /* Success! */ done: /* Close down pipe - this will clean up open policy handles */ if (cli.nt_pipe_fnum) cli_nt_session_close(&cli); /* Display success or failure */ if (retval != 0) { trust_password_delete(domain); fprintf(stderr,"Unable to join domain %s.\n",domain); } else { printf("Joined domain %s.\n",domain); } return retval; }
static int new_machine (struct pdb_methods *in, const char *machine_in) { struct samu *sam_pwent=NULL; fstring machinename; fstring machineaccount; struct passwd *pwd = NULL; get_global_sam_sid(); if (strlen(machine_in) == 0) { fprintf(stderr, "No machine name given\n"); return -1; } fstrcpy(machinename, machine_in); machinename[15]= '\0'; if (machinename[strlen (machinename) -1] == '$') machinename[strlen (machinename) -1] = '\0'; strlower_m(machinename); fstrcpy(machineaccount, machinename); fstrcat(machineaccount, "$"); if ((pwd = getpwnam_alloc(NULL, machineaccount))) { if ( (sam_pwent = samu_new( NULL )) == NULL ) { fprintf(stderr, "Memory allocation error!\n"); TALLOC_FREE(pwd); return -1; } if ( !NT_STATUS_IS_OK(samu_set_unix(sam_pwent, pwd )) ) { fprintf(stderr, "Could not init sam from pw\n"); TALLOC_FREE(pwd); return -1; } TALLOC_FREE(pwd); } else { if ( (sam_pwent = samu_new( NULL )) == NULL ) { fprintf(stderr, "Could not init sam from pw\n"); return -1; } } pdb_set_plaintext_passwd (sam_pwent, machinename); pdb_set_username (sam_pwent, machineaccount, PDB_CHANGED); pdb_set_acct_ctrl (sam_pwent, ACB_WSTRUST, PDB_CHANGED); if (NT_STATUS_IS_OK(in->add_sam_account (in, sam_pwent))) { print_user_info (in, machineaccount, True, False); } else { fprintf (stderr, "Unable to add machine! (does it already exist?)\n"); TALLOC_FREE(sam_pwent); return -1; } TALLOC_FREE(sam_pwent); return 0; }
/* * Create Fortran data statement to initialize numeric variable with * values. */ static void f_var_init( int varnum, /* which variable */ void *rec_start /* start of data */ ) { char *val_string; char *charvalp; short *shortvalp; int *intvalp; float *floatvalp; double *doublevalp; unsigned char *ubytevalp; unsigned short *ushortvalp; unsigned int *uintvalp; long long *int64valp; unsigned long long *uint64valp; char stmnt[FORT_MAX_STMNT]; size_t stmnt_len; char s2[FORT_MAX_STMNT]; int ival; /* load variable with data values */ sprintf(stmnt, "data %s /",vars[varnum].lname); stmnt_len = strlen(stmnt); switch (vars[varnum].type) { case NC_BYTE: charvalp = (char *) rec_start; for (ival = 0; ival < var_len-1; ival++) { val_string = fstring(NC_BYTE,(void *)charvalp++,0); sprintf(s2, "%s, ", val_string); fstrcat(stmnt, s2, &stmnt_len); free(val_string); } val_string = fstring(NC_BYTE,(void *)charvalp++,0); fstrcat(stmnt, val_string, &stmnt_len); free(val_string); break; case NC_SHORT: shortvalp = (short *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%d, ", *shortvalp++); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%d", *shortvalp); fstrcat(stmnt, s2, &stmnt_len); break; case NC_INT: intvalp = (int *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%ld, ", (long)*intvalp++); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%ld", (long)*intvalp); fstrcat(stmnt, s2, &stmnt_len); break; case NC_FLOAT: floatvalp = (float *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%.8g, ", *floatvalp++); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%.8g", *floatvalp); fstrcat(stmnt, s2, &stmnt_len); break; case NC_DOUBLE: doublevalp = (double *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%#.16g", *doublevalp++); tztrim(s2); expe2d(s2); /* change 'e' to 'd' in exponent */ fstrcat(s2, ", ", &stmnt_len); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%#.16g", *doublevalp++); tztrim(s2); expe2d(s2); fstrcat(stmnt, s2, &stmnt_len); break; case NC_UBYTE: ubytevalp = (unsigned char *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%hhu, ", (unsigned char)*ubytevalp++); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%hhu", (unsigned char)*ubytevalp); fstrcat(stmnt, s2, &stmnt_len); break; case NC_USHORT: ushortvalp = (unsigned short *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%hu, ", (unsigned short)*ushortvalp++); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%hu", (unsigned short)*ushortvalp); fstrcat(stmnt, s2, &stmnt_len); break; case NC_UINT: uintvalp = (unsigned int *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%u, ", (unsigned int)*uintvalp++); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%u", (unsigned int)*uintvalp); fstrcat(stmnt, s2, &stmnt_len); break; case NC_INT64: int64valp = (long long *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%lld, ", (long long)*int64valp++); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%lld", (long long)*int64valp); fstrcat(stmnt, s2, &stmnt_len); break; case NC_UINT64: uint64valp = (unsigned long long *) rec_start; for (ival = 0; ival < var_len-1; ival++) { sprintf(s2, "%llu, ", (unsigned long long)*uint64valp++); fstrcat(stmnt, s2, &stmnt_len); } sprintf(s2, "%llu", (unsigned long long)*uint64valp); fstrcat(stmnt, s2, &stmnt_len); break; default: derror("fstrstr: bad type"); break; } fstrcat(stmnt, "/", &stmnt_len); /* For record variables, store data statement for later use; otherwise, just print it. */ if (vars[varnum].ndims > 0 && vars[varnum].dims[0] == rec_dim) { char *dup_stmnt = (char*) emalloc(strlen(stmnt)+1); strcpy(dup_stmnt, stmnt); /* ULTRIX missing strdup */ vars[varnum].data_stmnt = dup_stmnt; } else { fline(stmnt); } }
static char *get_server_type_str(uint32 type) { static fstring typestr; int i; if (type == SV_TYPE_ALL) { fstrcpy(typestr, "All"); return typestr; } typestr[0] = 0; for (i = 0; i < 32; i++) { if (type & (1 << i)) { switch (1 << i) { case SV_TYPE_WORKSTATION: fstrcat(typestr, "Wk "); break; case SV_TYPE_SERVER: fstrcat(typestr, "Sv "); break; case SV_TYPE_SQLSERVER: fstrcat(typestr, "Sql "); break; case SV_TYPE_DOMAIN_CTRL: fstrcat(typestr, "PDC "); break; case SV_TYPE_DOMAIN_BAKCTRL: fstrcat(typestr, "BDC "); break; case SV_TYPE_TIME_SOURCE: fstrcat(typestr, "Tim "); break; case SV_TYPE_AFP: fstrcat(typestr, "AFP "); break; case SV_TYPE_NOVELL: fstrcat(typestr, "Nov "); break; case SV_TYPE_DOMAIN_MEMBER: fstrcat(typestr, "Dom "); break; case SV_TYPE_PRINTQ_SERVER: fstrcat(typestr, "PrQ "); break; case SV_TYPE_DIALIN_SERVER: fstrcat(typestr, "Din "); break; case SV_TYPE_SERVER_UNIX: fstrcat(typestr, "Unx "); break; case SV_TYPE_NT: fstrcat(typestr, "NT "); break; case SV_TYPE_WFW: fstrcat(typestr, "Wfw "); break; case SV_TYPE_SERVER_MFPN: fstrcat(typestr, "Mfp "); break; case SV_TYPE_SERVER_NT: fstrcat(typestr, "SNT "); break; case SV_TYPE_POTENTIAL_BROWSER: fstrcat(typestr, "PtB "); break; case SV_TYPE_BACKUP_BROWSER: fstrcat(typestr, "BMB "); break; case SV_TYPE_MASTER_BROWSER: fstrcat(typestr, "LMB "); break; case SV_TYPE_DOMAIN_MASTER: fstrcat(typestr, "DMB "); break; case SV_TYPE_SERVER_OSF: fstrcat(typestr, "OSF "); break; case SV_TYPE_SERVER_VMS: fstrcat(typestr, "VMS "); break; case SV_TYPE_WIN95_PLUS: fstrcat(typestr, "W95 "); break; case SV_TYPE_ALTERNATE_XPORT: fstrcat(typestr, "Xpt "); break; case SV_TYPE_LOCAL_LIST_ONLY: fstrcat(typestr, "Dom "); break; case SV_TYPE_DOMAIN_ENUM: fstrcat(typestr, "Loc "); break; } } } i = strlen(typestr) - 1; if (typestr[i] == ' ') typestr[i] = 0; return typestr; }
int cmd_umount(int argc, char* argv[]) { char *boot_loop; char *root_loop; struct piimg_img simg; FSTR_DECLARE_WRAPPER(mnt_root, argv[0]); FSTR_DECLARE_NULL (mnt_boot); FSTR_DECLARE_NULL (mnt_dev); FSTR_DECLARE_NULL (mnt_proc); FSTR_DECLARE_NULL (mnt_sys); const FSTR_DECLARE_WRAPPER(dir_boot, "/boot"); const FSTR_DECLARE_WRAPPER(dir_dev, "/dev"); const FSTR_DECLARE_WRAPPER(dir_proc, "/proc"); const FSTR_DECLARE_WRAPPER(dir_sys, "/sys"); memset(&simg, 0, sizeof(struct piimg_img)); if(fstrcat(&mnt_boot, &mnt_root, &dir_boot) || fstrcat(&mnt_dev, &mnt_root, &dir_dev) || fstrcat(&mnt_proc, &mnt_root, &dir_proc) || fstrcat(&mnt_sys, &mnt_root, &dir_sys)) { fprintf(stderr, "Failed to construct mount points.\n"); goto error; } printf("Mount Points\n"); printf("============\n"); printf("/ : %s\n", mnt_root.c_str); printf("/boot: %s\n", mnt_boot.c_str); printf("/dev : %s\n", mnt_dev.c_str); printf("/proc: %s\n", mnt_proc.c_str); printf("/sys : %s\n", mnt_sys.c_str); if(escalate()) goto error; if(ui_umount(mnt_sys.c_str) || ui_umount(mnt_proc.c_str) || ui_umount(mnt_boot.c_str) || ui_umount(mnt_dev.c_str) || ui_umount(mnt_root.c_str)) { goto error; } if(drop()) goto error; fstrfree(&mnt_boot); fstrfree(&mnt_dev); fstrfree(&mnt_proc); fstrfree(&mnt_sys); return 0; error: fstrfree(&mnt_boot); fstrfree(&mnt_dev); fstrfree(&mnt_proc); fstrfree(&mnt_sys); /* TODO: Should clean up allocated loop devices too. */ return 1; }
/**************************************************************************** main program ****************************************************************************/ int main(int argc,char *argv[]) { char *pname = argv[0]; int opt; extern FILE *dbf; extern char *optarg; extern int optind; static pstring servicesf = CONFIGFILE; pstring term_code; BOOL got_pass = False; char *cmd_str=""; enum client_action cli_action = CLIENT_NONE; int nprocs = 1; int numops = 100; pstring logfile; struct client_info cli_info; out_hnd = stdout; rpcclient_init(); #ifdef KANJI pstrcpy(term_code, KANJI); #else /* KANJI */ *term_code = 0; #endif /* KANJI */ if (!lp_load(servicesf,True, False, False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } codepage_initialise(lp_client_code_page()); DEBUGLEVEL = 0; cli_info.put_total_size = 0; cli_info.put_total_time_ms = 0; cli_info.get_total_size = 0; cli_info.get_total_time_ms = 0; cli_info.dir_total = 0; cli_info.newer_than = 0; cli_info.archive_level = 0; cli_info.print_mode = 1; cli_info.translation = False; cli_info.recurse_dir = False; cli_info.lowercase = False; cli_info.prompt = True; cli_info.abort_mget = True; cli_info.dest_ip.s_addr = 0; cli_info.name_type = 0x20; pstrcpy(cli_info.cur_dir , "\\"); pstrcpy(cli_info.file_sel, ""); pstrcpy(cli_info.base_dir, ""); pstrcpy(smb_cli->domain, ""); pstrcpy(smb_cli->user_name, ""); pstrcpy(cli_info.myhostname, ""); pstrcpy(cli_info.dest_host, ""); pstrcpy(cli_info.svc_type, "A:"); pstrcpy(cli_info.share, ""); pstrcpy(cli_info.service, ""); ZERO_STRUCT(cli_info.dom.level3_sid); pstrcpy(cli_info.dom.level3_dom, ""); ZERO_STRUCT(cli_info.dom.level5_sid); pstrcpy(cli_info.dom.level5_dom, ""); smb_cli->nt_pipe_fnum = 0xffff; setup_logging(pname, True); TimeInit(); charset_initialise(); if (!get_myname(global_myname)) { fprintf(stderr, "Failed to get my hostname.\n"); } password[0] = 0; if (argc < 2) { usage(pname); exit(1); } if (*argv[1] != '-') { pstrcpy(cli_info.service, argv[1]); /* Convert any '/' characters in the service name to '\' characters */ string_replace( cli_info.service, '/','\\'); argc--; argv++; DEBUG(1,("service: %s\n", cli_info.service)); if (count_chars(cli_info.service,'\\') < 3) { usage(pname); printf("\n%s: Not enough '\\' characters in service\n", cli_info.service); exit(1); } /* if (count_chars(cli_info.service,'\\') > 3) { usage(pname); printf("\n%s: Too many '\\' characters in service\n", cli_info.service); exit(1); } */ if (argc > 1 && (*argv[1] != '-')) { got_pass = True; pstrcpy(password,argv[1]); memset(argv[1],'X',strlen(argv[1])); argc--; argv++; } cli_action = CLIENT_SVC; } while ((opt = getopt(argc, argv,"s:O:M:S:i:N:o:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) { switch (opt) { case 'm': { /* FIXME ... max_protocol seems to be funny here */ int max_protocol = 0; max_protocol = interpret_protocol(optarg,max_protocol); fprintf(stderr, "max protocol not currently supported\n"); break; } case 'O': { pstrcpy(user_socket_options,optarg); break; } case 'S': { pstrcpy(cli_info.dest_host,optarg); strupper(cli_info.dest_host); cli_action = CLIENT_IPC; break; } case 'i': { pstrcpy(scope, optarg); break; } case 'U': { char *lp; pstrcpy(smb_cli->user_name,optarg); if ((lp=strchr(smb_cli->user_name,'%'))) { *lp = 0; pstrcpy(password,lp+1); got_pass = True; memset(strchr(optarg,'%')+1,'X',strlen(password)); } break; } case 'W': { pstrcpy(smb_cli->domain,optarg); break; } case 'E': { dbf = stderr; break; } case 'I': { cli_info.dest_ip = *interpret_addr2(optarg); if (zero_ip(cli_info.dest_ip)) { exit(1); } break; } case 'N': { nprocs = atoi(optarg); break; } case 'o': { numops = atoi(optarg); break; } case 'n': { fstrcpy(global_myname, optarg); break; } case 'd': { if (*optarg == 'A') DEBUGLEVEL = 10000; else DEBUGLEVEL = atoi(optarg); break; } case 'l': { slprintf(logfile, sizeof(logfile)-1, "%s.client",optarg); lp_set_logfile(logfile); break; } case 'c': { cmd_str = optarg; got_pass = True; break; } case 'h': { usage(pname); exit(0); break; } case 's': { pstrcpy(servicesf, optarg); break; } case 't': { pstrcpy(term_code, optarg); break; } default: { usage(pname); exit(1); break; } } } if (cli_action == CLIENT_NONE) { usage(pname); exit(1); } strupper(global_myname); fstrcpy(cli_info.myhostname, global_myname); DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION)); if (*smb_cli->domain == 0) { pstrcpy(smb_cli->domain,lp_workgroup()); } strupper(smb_cli->domain); load_interfaces(); if (cli_action == CLIENT_IPC) { pstrcpy(cli_info.share, "IPC$"); pstrcpy(cli_info.svc_type, "IPC"); } fstrcpy(cli_info.mach_acct, cli_info.myhostname); strupper(cli_info.mach_acct); fstrcat(cli_info.mach_acct, "$"); /* set the password cache info */ if (got_pass) { if (password[0] == 0) { pwd_set_nullpwd(&(smb_cli->pwd)); } else { pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ } } else { char *pwd = getpass("Enter Password:"); safe_strcpy(password, pwd, sizeof(password)); pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ } create_procs(nprocs, numops, &cli_info, smb_cli, run_enums_test); if (password[0] != 0) { create_procs(nprocs, numops, &cli_info, smb_cli, run_ntlogin_test); } fflush(out_hnd); return(0); }
bool torture_utable(int dummy) { struct cli_state *cli; fstring fname, alt_name; uint16_t fnum; smb_ucs2_t c2; int c, len, fd; int chars_allowed=0, alt_allowed=0; uint8 valid[0x10000]; printf("starting utable\n"); if (!torture_open_connection(&cli, 0)) { return False; } memset(valid, 0, sizeof(valid)); cli_mkdir(cli, "\\utable"); cli_unlink(cli, "\\utable\\*", FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); for (c=1; c < 0x10000; c++) { size_t size = 0; char *p; SSVAL(&c2, 0, c); fstrcpy(fname, "\\utable\\x"); p = fname+strlen(fname); if (!convert_string(CH_UTF16LE, CH_UNIX, &c2, 2, p, sizeof(fname)-strlen(fname),&size)) { d_printf("convert_string %s failed !\n", fname); continue; } len = size; p[len] = 0; fstrcat(fname,"_a_long_extension"); if (!NT_STATUS_IS_OK(cli_open(cli, fname, O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum))) { continue; } chars_allowed++; cli_qpathinfo_alt_name(cli, fname, alt_name); if (strncmp(alt_name, "X_A_L", 5) != 0) { alt_allowed++; valid[c] = 1; d_printf("fname=[%s] alt_name=[%s]\n", fname, alt_name); } cli_close(cli, fnum); cli_unlink(cli, fname, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN); if (c % 100 == 0) { printf("%d (%d/%d)\r", c, chars_allowed, alt_allowed); } } printf("%d (%d/%d)\n", c, chars_allowed, alt_allowed); cli_rmdir(cli, "\\utable"); d_printf("%d chars allowed %d alt chars allowed\n", chars_allowed, alt_allowed); fd = open("valid.dat", O_WRONLY|O_CREAT|O_TRUNC, 0644); if (fd == -1) { d_printf("Failed to create valid.dat - %s", strerror(errno)); return False; } if (write(fd, valid, 0x10000) != 0x10000) { d_printf("Failed to create valid.dat - %s", strerror(errno)); close(fd); return false; } close(fd); d_printf("wrote valid.dat\n"); return True; }
/**************************************************************************** convert a security permissions into a string ****************************************************************************/ char *get_sec_mask_str(uint32 type) { static fstring typestr=""; typestr[0] = 0; if (type & GENERIC_ALL_ACCESS) fstrcat(typestr, "Generic all access "); if (type & GENERIC_EXECUTE_ACCESS) fstrcat(typestr, "Generic execute access "); if (type & GENERIC_WRITE_ACCESS) fstrcat(typestr, "Generic write access "); if (type & GENERIC_READ_ACCESS) fstrcat(typestr, "Generic read access "); if (type & MAXIMUM_ALLOWED_ACCESS) fstrcat(typestr, "MAXIMUM_ALLOWED_ACCESS "); if (type & SYSTEM_SECURITY_ACCESS) fstrcat(typestr, "SYSTEM_SECURITY_ACCESS "); if (type & SYNCHRONIZE_ACCESS) fstrcat(typestr, "SYNCHRONIZE_ACCESS "); if (type & WRITE_OWNER_ACCESS) fstrcat(typestr, "WRITE_OWNER_ACCESS "); if (type & WRITE_DAC_ACCESS) fstrcat(typestr, "WRITE_DAC_ACCESS "); if (type & READ_CONTROL_ACCESS) fstrcat(typestr, "READ_CONTROL_ACCESS "); if (type & DELETE_ACCESS) fstrcat(typestr, "DELETE_ACCESS "); printf("\t\tSpecific bits: 0x%lx\n", type&SPECIFIC_RIGHTS_MASK); return typestr; }
static void gpo_sync_func(const char *mnt, file_info *info, const char *mask, void *state) { NTSTATUS result; struct sync_context *ctx; fstring nt_filename, unix_filename; fstring nt_dir, unix_dir; char *old_nt_dir, *old_unix_dir; ctx = (struct sync_context *)state; if (strequal(info->name, ".") || strequal(info->name, "..")) { return; } DEBUG(5,("gpo_sync_func: got mask: [%s], name: [%s]\n", mask, info->name)); if (info->mode & aDIR) { DEBUG(3,("got dir: [%s]\n", info->name)); fstrcpy(nt_dir, ctx->remote_path); fstrcat(nt_dir, "\\"); fstrcat(nt_dir, info->name); fstrcpy(unix_dir, ctx->local_path); fstrcat(unix_dir, "/"); fstrcat(unix_dir, info->name); result = gpo_copy_dir(unix_dir); if (!NT_STATUS_IS_OK(result)) { DEBUG(1,("failed to copy dir: %s\n", nt_errstr(result))); } old_nt_dir = ctx->remote_path; ctx->remote_path = nt_dir; old_unix_dir = ctx->local_path; ctx->local_path = talloc_strdup(ctx->mem_ctx, unix_dir); pstrcpy(ctx->mask, nt_dir); pstrcat(ctx->mask, "\\*"); if (!gpo_sync_files(ctx)) { DEBUG(0,("could not sync files\n")); } ctx->remote_path = old_nt_dir; ctx->local_path = old_unix_dir; return; } DEBUG(3,("got file: [%s]\n", info->name)); fstrcpy(nt_filename, ctx->remote_path); fstrcat(nt_filename, "\\"); fstrcat(nt_filename, info->name); fstrcpy(unix_filename, ctx->local_path); fstrcat(unix_filename, "/"); fstrcat(unix_filename, info->name); result = gpo_copy_file(ctx->mem_ctx, ctx->cli, nt_filename, unix_filename); if (!NT_STATUS_IS_OK(result)) { DEBUG(1,("failed to copy file: %s\n", nt_errstr(result))); } }
/**************************************************************************** main program ****************************************************************************/ int main(int argc,char *argv[]) { BOOL interactive = True; int opt; extern FILE *dbf; extern char *optarg; extern int optind; static pstring servicesf = CONFIGFILE; pstring term_code; char *p; BOOL got_pass = False; char *cmd_str=""; mode_t myumask = 0755; enum client_action cli_action = CLIENT_NONE; struct client_info cli_info; pstring password; /* local copy only, if one is entered */ out_hnd = stdout; fstrcpy(debugf, argv[0]); rpcclient_init(); #ifdef KANJI pstrcpy(term_code, KANJI); #else /* KANJI */ *term_code = 0; #endif /* KANJI */ DEBUGLEVEL = 2; cli_info.put_total_size = 0; cli_info.put_total_time_ms = 0; cli_info.get_total_size = 0; cli_info.get_total_time_ms = 0; cli_info.dir_total = 0; cli_info.newer_than = 0; cli_info.archive_level = 0; cli_info.print_mode = 1; cli_info.translation = False; cli_info.recurse_dir = False; cli_info.lowercase = False; cli_info.prompt = True; cli_info.abort_mget = True; cli_info.dest_ip.s_addr = 0; cli_info.name_type = 0x20; pstrcpy(cli_info.cur_dir , "\\"); pstrcpy(cli_info.file_sel, ""); pstrcpy(cli_info.base_dir, ""); pstrcpy(smb_cli->domain, ""); pstrcpy(smb_cli->user_name, ""); pstrcpy(cli_info.myhostname, ""); pstrcpy(cli_info.dest_host, ""); pstrcpy(cli_info.svc_type, "A:"); pstrcpy(cli_info.share, ""); pstrcpy(cli_info.service, ""); ZERO_STRUCT(cli_info.dom.level3_sid); ZERO_STRUCT(cli_info.dom.level5_sid); fstrcpy(cli_info.dom.level3_dom, ""); fstrcpy(cli_info.dom.level5_dom, ""); smb_cli->nt_pipe_fnum = 0xffff; TimeInit(); charset_initialise(); myumask = umask(0); umask(myumask); if (!get_myname(global_myname)) { fprintf(stderr, "Failed to get my hostname.\n"); } if (getenv("USER")) { pstrcpy(smb_cli->user_name,getenv("USER")); /* modification to support userid%passwd syntax in the USER var 25.Aug.97, [email protected] */ if ((p=strchr(smb_cli->user_name,'%'))) { *p = 0; pstrcpy(password,p+1); got_pass = True; memset(strchr(getenv("USER"),'%')+1,'X',strlen(password)); } strupper(smb_cli->user_name); } password[0] = 0; /* modification to support PASSWD environmental var 25.Aug.97, [email protected] */ if (getenv("PASSWD")) { pstrcpy(password,getenv("PASSWD")); } if (*smb_cli->user_name == 0 && getenv("LOGNAME")) { pstrcpy(smb_cli->user_name,getenv("LOGNAME")); strupper(smb_cli->user_name); } if (argc < 2) { usage(argv[0]); exit(1); } if (*argv[1] != '-') { pstrcpy(cli_info.service, argv[1]); /* Convert any '/' characters in the service name to '\' characters */ string_replace( cli_info.service, '/','\\'); argc--; argv++; fprintf(out_hnd, "service: %s\n", cli_info.service); if (count_chars(cli_info.service,'\\') < 3) { usage(argv[0]); printf("\n%s: Not enough '\\' characters in service\n", cli_info.service); exit(1); } /* if (count_chars(cli_info.service,'\\') > 3) { usage(pname); printf("\n%s: Too many '\\' characters in service\n", cli_info.service); exit(1); } */ if (argc > 1 && (*argv[1] != '-')) { got_pass = True; pstrcpy(password,argv[1]); memset(argv[1],'X',strlen(argv[1])); argc--; argv++; } cli_action = CLIENT_SVC; } while ((opt = getopt(argc, argv,"s:O:M:S:i:N:n:d:l:hI:EB:U:L:t:m:W:T:D:c:")) != EOF) { switch (opt) { case 'm': { /* FIXME ... max_protocol seems to be funny here */ int max_protocol = 0; max_protocol = interpret_protocol(optarg,max_protocol); fprintf(stderr, "max protocol not currently supported\n"); break; } case 'O': { pstrcpy(user_socket_options,optarg); break; } case 'S': { pstrcpy(cli_info.dest_host,optarg); strupper(cli_info.dest_host); cli_action = CLIENT_IPC; break; } case 'i': { extern pstring global_scope; pstrcpy(global_scope, optarg); strupper(global_scope); break; } case 'U': { char *lp; pstrcpy(smb_cli->user_name,optarg); if ((lp=strchr(smb_cli->user_name,'%'))) { *lp = 0; pstrcpy(password,lp+1); got_pass = True; memset(strchr(optarg,'%')+1,'X',strlen(password)); } break; } case 'W': { pstrcpy(smb_cli->domain,optarg); break; } case 'E': { dbf = stderr; break; } case 'I': { cli_info.dest_ip = *interpret_addr2(optarg); if (zero_ip(cli_info.dest_ip)) { exit(1); } break; } case 'n': { fstrcpy(global_myname, optarg); break; } case 'N': { got_pass = True; break; } case 'd': { if (*optarg == 'A') DEBUGLEVEL = 10000; else DEBUGLEVEL = atoi(optarg); break; } case 'l': { slprintf(debugf, sizeof(debugf)-1, "%s.client", optarg); interactive = False; break; } case 'c': { cmd_str = optarg; got_pass = True; break; } case 'h': { usage(argv[0]); exit(0); break; } case 's': { pstrcpy(servicesf, optarg); break; } case 't': { pstrcpy(term_code, optarg); break; } default: { usage(argv[0]); exit(1); break; } } } setup_logging(debugf, interactive); if (cli_action == CLIENT_NONE) { usage(argv[0]); exit(1); } strupper(global_myname); fstrcpy(cli_info.myhostname, global_myname); DEBUG(3,("%s client started (version %s)\n",timestring(False),VERSION)); if (!lp_load(servicesf,True, False, False)) { fprintf(stderr, "Can't load %s - run testparm to debug it\n", servicesf); } codepage_initialise(lp_client_code_page()); if (*smb_cli->domain == 0) pstrcpy(smb_cli->domain,lp_workgroup()); load_interfaces(); if (cli_action == CLIENT_IPC) { pstrcpy(cli_info.share, "IPC$"); pstrcpy(cli_info.svc_type, "IPC"); } fstrcpy(cli_info.mach_acct, cli_info.myhostname); strupper(cli_info.mach_acct); fstrcat(cli_info.mach_acct, "$"); /* set the password cache info */ if (got_pass) { if (password[0] == 0) { pwd_set_nullpwd(&(smb_cli->pwd)); } else { pwd_make_lm_nt_16(&(smb_cli->pwd), password); /* generate 16 byte hashes */ } } else { pwd_read(&(smb_cli->pwd), "Enter Password:"******"rpcclient_connect: smb_cli->fd:%d\n", smb_cli->fd)); if (smb_cli->fd <= 0) { fprintf(stderr, "warning: connection could not be established to %s<%02x>\n", cli_info.dest_host, cli_info.name_type); fprintf(stderr, "this version of smbclient may crash if you proceed\n"); exit(-1); } switch (cli_action) { case CLIENT_IPC: { process(&cli_info, cmd_str); break; } default: { fprintf(stderr, "unknown client action requested\n"); break; } } rpcclient_stop(); return(0); }