BOOL cli_credentials_parse_file(struct cli_credentials *cred, const char *file, enum credentials_obtained obtained) { uint16_t len = 0; char *ptr, *val, *param; char **lines; int i, numlines; lines = file_lines_load(file, &numlines, NULL); if (lines == NULL) { /* fail if we can't open the credentials file */ d_printf("ERROR: Unable to open credentials file!\n"); return False; } for (i = 0; i < numlines; i++) { len = strlen(lines[i]); if (len == 0) continue; /* break up the line into parameter & value. * will need to eat a little whitespace possibly */ param = lines[i]; if (!(ptr = strchr_m (lines[i], '='))) continue; val = ptr+1; *ptr = '\0'; /* eat leading white space */ while ((*val!='\0') && ((*val==' ') || (*val=='\t'))) val++; if (strwicmp("password", param) == 0) { cli_credentials_set_password(cred, val, obtained); } else if (strwicmp("username", param) == 0) { cli_credentials_set_username(cred, val, obtained); } else if (strwicmp("domain", param) == 0) { cli_credentials_set_domain(cred, val, obtained); } else if (strwicmp("realm", param) == 0) { cli_credentials_set_realm(cred, val, obtained); } memset(lines[i], 0, len); } talloc_free(lines); return True; }
/* load a msg file into the tdb */ static bool load_msg(const char *msg_file) { char **lines; int num_lines, i; char *msgid, *msgstr; TDB_DATA data; lines = file_lines_load(msg_file, &num_lines, 0, NULL); if (!lines) { return False; } if (tdb_lockall(tdb) != 0) { TALLOC_FREE(lines); return False; } /* wipe the db */ tdb_wipe_all(tdb); msgid = NULL; for (i=0;i<num_lines;i++) { if (strncmp(lines[i], "msgid \"", 7) == 0) { msgid = lines[i] + 7; } if (msgid && strncmp(lines[i], "msgstr \"", 8) == 0) { msgstr = lines[i] + 8; trim_char(msgid, '\0', '\"'); trim_char(msgstr, '\0', '\"'); if (*msgstr == 0) { msgstr = msgid; } all_string_sub(msgid, "\\n", "\n", 0); all_string_sub(msgstr, "\\n", "\n", 0); data = string_term_tdb_data(msgstr); tdb_store_bystring(tdb, msgid, data, 0); msgid = NULL; } } TALLOC_FREE(lines); tdb_unlockall(tdb); return True; }
/* load a msg file into the tdb */ static BOOL load_msg(const char *msg_file) { char **lines; int num_lines, i; char *msgid, *msgstr; TDB_DATA key, data; lines = file_lines_load(msg_file, &num_lines); if (!lines) { return False; } if (tdb_lockall(tdb) != 0) return False; /* wipe the db */ tdb_traverse(tdb, tdb_traverse_delete_fn, NULL); msgid = NULL; for (i=0;i<num_lines;i++) { if (strncmp(lines[i], "msgid \"", 7) == 0) { msgid = lines[i] + 7; } if (msgid && strncmp(lines[i], "msgstr \"", 8) == 0) { msgstr = lines[i] + 8; trim_char(msgid, '\0', '\"'); trim_char(msgstr, '\0', '\"'); if (*msgstr == 0) { msgstr = msgid; } all_string_sub(msgid, "\\n", "\n", 0); all_string_sub(msgstr, "\\n", "\n", 0); key.dptr = msgid; key.dsize = strlen(msgid)+1; data.dptr = msgstr; data.dsize = strlen(msgstr)+1; tdb_store(tdb, key, data, 0); msgid = NULL; } } file_lines_free(lines); tdb_unlockall(tdb); return True; }
static bool read_sid_from_file(const char *fname, struct dom_sid *sid) { char **lines; int numlines; bool ret; lines = file_lines_load(fname, &numlines,0, NULL); if (!lines || numlines < 1) { TALLOC_FREE(lines); return False; } ret = string_to_sid(sid, lines[0]); TALLOC_FREE(lines); return ret; }
/**************************************************************************** Read a SID from a file. This is for compatibility with the old MACHINE.SID style of SID storage ****************************************************************************/ static BOOL read_sid_from_file(const char *fname, DOM_SID *sid) { char **lines; int numlines; BOOL ret; lines = file_lines_load(fname, &numlines); if (!lines || numlines < 1) { if (lines) file_lines_free(lines); return False; } ret = string_to_sid(sid, lines[0]); file_lines_free(lines); return ret; }
static BOOL read_sid_from_file(char *fname, DOM_SID *sid) { char **lines; int numlines; BOOL ret; lines = file_lines_load(fname, &numlines, False); if (!lines || numlines < 1) { if (lines) file_lines_free(lines); return False; } ret = string_to_sid(sid, lines[0]); if (!ret) DEBUG(0,("read_sid_from_file: Failed to convert machine SID. (%s)\n", lines[0])); file_lines_free(lines); return ret; }
/***************************************************** return a connection to a server *******************************************************/ static struct smbcli_state *connect_one(struct tevent_context *ev, struct loadparm_context *lp_ctx, TALLOC_CTX *mem_ctx, char *share, int snum, int conn) { struct smbcli_state *c; char *server, *myname; NTSTATUS status; int retries = 10; struct smbcli_options options; struct smbcli_session_options session_options; lp_smbcli_options(lp_ctx, &options); lp_smbcli_session_options(lp_ctx, &session_options); printf("connect_one(%s, %d, %d)\n", share, snum, conn); server = talloc_strdup(mem_ctx, share+2); share = strchr_m(server,'\\'); if (!share) return NULL; *share = 0; share++; if (snum == 0) { char **unc_list = NULL; int num_unc_names; const char *p; p = lp_parm_string(lp_ctx, NULL, "torture", "unclist"); if (p) { char *h, *s; unc_list = file_lines_load(p, &num_unc_names, 0, NULL); if (!unc_list || num_unc_names <= 0) { printf("Failed to load unc names list from '%s'\n", p); exit(1); } if (!smbcli_parse_unc(unc_list[conn % num_unc_names], NULL, &h, &s)) { printf("Failed to parse UNC name %s\n", unc_list[conn % num_unc_names]); exit(1); } server = talloc_strdup(mem_ctx, h); share = talloc_strdup(mem_ctx, s); } } myname = talloc_asprintf(mem_ctx, "lock-%u-%u", getpid(), snum); cli_credentials_set_workstation(servers[snum], myname, CRED_SPECIFIED); do { printf("\\\\%s\\%s\n", server, share); status = smbcli_full_connection(NULL, &c, server, lp_smb_ports(lp_ctx), share, NULL, lp_socket_options(lp_ctx), servers[snum], lp_resolve_context(lp_ctx), ev, &options, &session_options, lp_iconv_convenience(lp_ctx), lp_gensec_settings(mem_ctx, lp_ctx)); if (!NT_STATUS_IS_OK(status)) { sleep(2); } } while (!NT_STATUS_IS_OK(status) && retries--); if (!NT_STATUS_IS_OK(status)) { return NULL; } return c; }
/** * @internal * * @brief Map a Windows driver to a OS/2 driver. * * @param[in] mem_ctx The memory context to use. * * @param[in,out] pdrivername The drivername of Windows to remap. * * @return WERR_OK on success, a corresponding WERROR on failure. */ WERROR spoolss_map_to_os2_driver(TALLOC_CTX *mem_ctx, const char **pdrivername) { const char *mapfile = lp_os2_driver_map(talloc_tos()); char **lines = NULL; const char *drivername; int numlines = 0; int i; if (pdrivername == NULL || *pdrivername == NULL || *pdrivername[0] == '\0') { return WERR_INVALID_PARAMETER; } drivername = *pdrivername; if (mapfile[0] == '\0') { return WERR_BADFILE; } if (strequal(drivername, get_win_driver())) { DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n", drivername, get_os2_driver())); drivername = talloc_strdup(mem_ctx, get_os2_driver()); if (drivername == NULL) { return WERR_NOMEM; } *pdrivername = drivername; return WERR_OK; } lines = file_lines_load(mapfile, &numlines, 0, NULL); if (numlines == 0 || lines == NULL) { DEBUG(0,("No entries in OS/2 driver map %s\n", mapfile)); TALLOC_FREE(lines); return WERR_EMPTY; } DEBUG(4,("Scanning OS/2 driver map %s\n",mapfile)); for( i = 0; i < numlines; i++) { char *nt_name = lines[i]; char *os2_name = strchr(nt_name, '='); if (os2_name == NULL) { continue; } *os2_name++ = '\0'; while (isspace(*nt_name)) { nt_name++; } if (*nt_name == '\0' || strchr("#;", *nt_name)) { continue; } { int l = strlen(nt_name); while (l && isspace(nt_name[l - 1])) { nt_name[l - 1] = 0; l--; } } while (isspace(*os2_name)) { os2_name++; } { int l = strlen(os2_name); while (l && isspace(os2_name[l-1])) { os2_name[l-1] = 0; l--; } } if (strequal(nt_name, drivername)) { DEBUG(3,("Mapped Windows driver %s to OS/2 driver %s\n",drivername,os2_name)); set_driver_mapping(drivername, os2_name); drivername = talloc_strdup(mem_ctx, os2_name); TALLOC_FREE(lines); if (drivername == NULL) { return WERR_NOMEM; } *pdrivername = drivername; return WERR_OK; } } TALLOC_FREE(lines); return WERR_OK; }