/** strdup_upper with a talloc */ char *talloc_strdup_upper(TALLOC_CTX *t, const char *p) { char *r; if (p) { char *q = strdup_upper(p); if (q) { r = talloc_strdup(t, q); SAFE_FREE(q); return r; } else { return NULL; } } else { return NULL; } }
static bool test_plaintext(enum ntlm_break break_which) { NTSTATUS nt_status; uint32 flags = 0; DATA_BLOB nt_response = data_blob_null; DATA_BLOB lm_response = data_blob_null; char *password; smb_ucs2_t *nt_response_ucs2; size_t converted_size; uchar user_session_key[16]; uchar lm_key[16]; static const uchar zeros[8] = { 0, }; DATA_BLOB chall = data_blob(zeros, sizeof(zeros)); char *error_string; ZERO_STRUCT(user_session_key); flags |= WBFLAG_PAM_LMKEY; flags |= WBFLAG_PAM_USER_SESSION_KEY; if (!push_ucs2_allocate(&nt_response_ucs2, opt_password, &converted_size)) { DEBUG(0, ("push_ucs2_allocate failed!\n")); exit(1); } nt_response.data = (unsigned char *)nt_response_ucs2; nt_response.length = strlen_w(nt_response_ucs2)*sizeof(smb_ucs2_t); if ((password = strdup_upper(opt_password)) == NULL) { DEBUG(0, ("strdup_upper failed!\n")); exit(1); } if (!convert_string_allocate(NULL, CH_UNIX, CH_DOS, password, strlen(password)+1, &lm_response.data, &lm_response.length, True)) { DEBUG(0, ("convert_string_allocate failed!\n")); exit(1); } SAFE_FREE(password); switch (break_which) { case BREAK_NONE: break; case BREAK_LM: lm_response.data[0]++; break; case BREAK_NT: nt_response.data[0]++; break; case NO_LM: SAFE_FREE(lm_response.data); lm_response.length = 0; break; case NO_NT: SAFE_FREE(nt_response.data); nt_response.length = 0; break; } nt_status = contact_winbind_auth_crap(opt_username, opt_domain, opt_workstation, &chall, &lm_response, &nt_response, flags, lm_key, user_session_key, &error_string, NULL); SAFE_FREE(nt_response.data); SAFE_FREE(lm_response.data); data_blob_free(&chall); if (!NT_STATUS_IS_OK(nt_status)) { d_printf("%s (0x%x)\n", error_string, NT_STATUS_V(nt_status)); SAFE_FREE(error_string); return break_which == BREAK_NT; } return break_which != BREAK_NT; }
char *alloc_sub_basic(const char *smb_name, const char *str) { char *b, *p, *s, *t, *r, *a_string; fstring pidstr; struct passwd *pass; const char *local_machine_name = get_local_machine_name(); /* workaround to prevent a crash while lookinf at bug #687 */ if ( !str ) { DEBUG(0,("alloc_sub_basic: NULL source string! This should not happen\n")); return NULL; } a_string = strdup(str); if (a_string == NULL) { DEBUG(0, ("alloc_sub_specified: Out of memory!\n")); return NULL; } for (b = s = a_string; (p = strchr_m(s, '%')); s = a_string + (p - b)) { r = NULL; b = t = a_string; switch (*(p+1)) { case 'U' : r = strdup_lower(smb_name); if (r == NULL) goto error; t = realloc_string_sub(t, "%U", r); break; case 'G' : r = strdup(smb_name); if (r == NULL) goto error; if ((pass = Get_Pwnam(r))!=NULL) { t = realloc_string_sub(t, "%G", gidtoname(pass->pw_gid)); } break; case 'D' : r = strdup_upper(current_user_info.domain); if (r == NULL) goto error; t = realloc_string_sub(t, "%D", r); break; case 'I' : t = realloc_string_sub(t, "%I", client_addr()); break; case 'L' : if (local_machine_name && *local_machine_name) t = realloc_string_sub(t, "%L", local_machine_name); else t = realloc_string_sub(t, "%L", global_myname()); break; case 'N': t = realloc_string_sub(t, "%N", automount_server(smb_name)); break; case 'M' : t = realloc_string_sub(t, "%M", client_name()); break; case 'R' : t = realloc_string_sub(t, "%R", remote_proto); break; case 'T' : t = realloc_string_sub(t, "%T", timestring(False)); break; case 'a' : t = realloc_string_sub(t, "%a", remote_arch); break; case 'd' : slprintf(pidstr,sizeof(pidstr)-1, "%d",(int)sys_getpid()); t = realloc_string_sub(t, "%d", pidstr); break; case 'h' : t = realloc_string_sub(t, "%h", myhostname()); break; case 'm' : t = realloc_string_sub(t, "%m", remote_machine); break; case 'v' : t = realloc_string_sub(t, "%v", SAMBA_VERSION_STRING); break; case '$' : t = realloc_expand_env_var(t, p); /* Expand environment variables */ break; default: break; } p++; SAFE_FREE(r); if (t == NULL) goto error; a_string = t; } return a_string; error: SAFE_FREE(a_string); return NULL; }