📄 winbind.c
字号:
if (full_username) { char *b64_full_username = base64_encode(full_username); fprintf(pipe_in, "Full-Username:: %s\n", b64_full_username); free(b64_full_username); } if (plaintext_password) { char *b64_plaintext_password = base64_encode(plaintext_password); fprintf(pipe_in, "Password:: %s\n", b64_plaintext_password); free(b64_plaintext_password); } if (challenge_length) { fprintf(pipe_in, "Request-User-Session-Key: yes\n"); challenge_hex = malloc(challenge_length*2+1); for (i = 0; i < challenge_length; i++) sprintf(challenge_hex + i * 2, "%02X", challenge[i]); fprintf(pipe_in, "LANMAN-Challenge: %s\n", challenge_hex); free(challenge_hex); } if (lm_response_length) { lm_hex_hash = malloc(lm_response_length*2+1); for (i = 0; i < lm_response_length; i++) sprintf(lm_hex_hash + i * 2, "%02X", lm_response[i]); fprintf(pipe_in, "LANMAN-response: %s\n", lm_hex_hash); free(lm_hex_hash); } if (nt_response_length) { nt_hex_hash = malloc(nt_response_length*2+1); for (i = 0; i < nt_response_length; i++) sprintf(nt_hex_hash + i * 2, "%02X", nt_response[i]); fprintf(pipe_in, "NT-response: %s\n", nt_hex_hash); free(nt_hex_hash); } fprintf(pipe_in, ".\n"); fflush(pipe_in); while (fgets(buffer, sizeof(buffer)-1, pipe_out) != NULL) { char *message, *parameter; if (buffer[strlen(buffer)-1] != '\n') { break; } buffer[strlen(buffer)-1] = '\0'; message = buffer; if (!(parameter = strstr(buffer, ": "))) { break; } parameter[0] = '\0'; parameter++; parameter[0] = '\0'; parameter++; if (strcmp(message, ".") == 0) { /* end of sequence */ break; } else if (strcasecmp(message, "Authenticated") == 0) { if (strcasecmp(parameter, "Yes") == 0) { authenticated = AUTHENTICATED; } else { notice("Winbind has declined authentication for user!"); authenticated = NOT_AUTHENTICATED; } } else if (strcasecmp(message, "User-session-key") == 0) { /* length is the number of characters to parse */ if (nt_key) { if (strhex_to_str(nt_key, 32, parameter) == 16) { got_user_session_key = 1; } else { notice("NT session key for user was not 16 bytes!"); } } } else if (strcasecmp(message, "Error") == 0) { authenticated = NOT_AUTHENTICATED; if (error_string) *error_string = strdup(parameter); } else if (strcasecmp(message, "Authentication-Error") == 0) { authenticated = NOT_AUTHENTICATED; if (error_string) *error_string = strdup(parameter); } else { notice("unrecognised input from ntlm_auth helper - %s: %s", message, parameter); } } /* parent */ if (close(child_out[0]) == -1) { notice("error closing pipe?!? for child OUT[0]"); return NOT_AUTHENTICATED; } /* parent */ if (close(child_in[1]) == -1) { notice("error closing pipe?!? for child IN[1]"); return NOT_AUTHENTICATED; } while ((wait(&status) == -1) && errno == EINTR) ; if ((authenticated == AUTHENTICATED) && nt_key && !got_user_session_key) { notice("Did not get user session key, despite being authenticated!"); return NOT_AUTHENTICATED; } return authenticated;}/*********************************************************************** %FUNCTION: winbind_secret_check* %ARGUMENTS:* None* %RETURNS:* 0 if we don't have an ntlm_auth program to run, otherwise 1.* %DESCRIPTION:* Tells pppd that we will try to authenticate the peer, and not to* worry about looking in /etc/ppp/ *-secrets***********************************************************************/static intwinbind_secret_check(void){ return ntlm_auth != NULL;}/*********************************************************************** %FUNCTION: winbind_pap_auth* %ARGUMENTS:* user -- user-name of peer* passwd -- password supplied by peer* msgp -- Message which will be sent in PAP response* paddrs -- set to a list of possible peer IP addresses* popts -- set to a list of additional pppd options* %RETURNS:* 1 if we can authenticate, -1 if we cannot.* %DESCRIPTION:* Performs PAP authentication using WINBIND***********************************************************************/static intwinbind_pap_auth(char *user, char *password, char **msgp, struct wordlist **paddrs, struct wordlist **popts){ if (run_ntlm_auth(NULL, NULL, user, password, NULL, 0, NULL, 0, NULL, 0, NULL, msgp) == AUTHENTICATED) { return 1; } return -1;}/*********************************************************************** %FUNCTION: winbind_chap_auth* %ARGUMENTS:* user -- user-name of peer* remmd -- hash received from peer* remmd_len -- length of remmd* cstate -- pppd's chap_state structure* %RETURNS:* AUTHENTICATED (1) if we can authenticate, NOT_AUTHENTICATED (0) if we cannot.* %DESCRIPTION:* Performs MS-CHAP and MS-CHAPv2 authentication using WINBIND.***********************************************************************/static int winbind_chap_verify(char *user, char *ourname, int id, struct chap_digest_type *digest, unsigned char *challenge, unsigned char *response, char *message, int message_space){ int challenge_len, response_len; char domainname[256]; char *domain; char *username; char *p; char saresponse[MS_AUTH_RESPONSE_LENGTH+1]; /* The first byte of each of these strings contains their length */ challenge_len = *challenge++; response_len = *response++; /* remove domain from "domain\username" */ if ((username = strrchr(user, '\\')) != NULL) ++username; else username = user; strlcpy(domainname, user, sizeof(domainname)); /* remove domain from "domain\username" */ if ((p = strrchr(domainname, '\\')) != NULL) { *p = '\0'; domain = domainname; } else { domain = NULL; } /* generate MD based on negotiated type */ switch (digest->code) { case CHAP_MICROSOFT: { char *error_string = NULL; u_char *nt_response = NULL; u_char *lm_response = NULL; int nt_response_size = 0; int lm_response_size = 0; u_char session_key[16]; if (response_len != MS_CHAP_RESPONSE_LEN) break; /* not even the right length */ /* Determine which part of response to verify against */ if (response[MS_CHAP_USENT]) { nt_response = &response[MS_CHAP_NTRESP]; nt_response_size = MS_CHAP_NTRESP_LEN; } else {#ifdef MSLANMAN lm_response = &response[MS_CHAP_LANMANRESP]; lm_response_size = MS_CHAP_LANMANRESP_LEN;#else /* Should really propagate this into the error packet. */ notice("Peer request for LANMAN auth not supported"); return NOT_AUTHENTICATED;#endif /* MSLANMAN */ } /* ship off to winbind, and check */ if (run_ntlm_auth(username, domain, NULL, NULL, challenge, challenge_len, lm_response, lm_response_size, nt_response, nt_response_size, session_key, &error_string) == AUTHENTICATED) { mppe_set_keys(challenge, session_key); slprintf(message, message_space, "Access granted"); return AUTHENTICATED; } else { if (error_string) { notice(error_string); free(error_string); } slprintf(message, message_space, "E=691 R=1 C=%0.*B V=0", challenge_len, challenge); return NOT_AUTHENTICATED; } break; } case CHAP_MICROSOFT_V2: { u_char Challenge[8]; u_char session_key[MD4_SIGNATURE_SIZE]; char *error_string = NULL; if (response_len != MS_CHAP2_RESPONSE_LEN) break; /* not even the right length */ ChallengeHash(&response[MS_CHAP2_PEER_CHALLENGE], challenge, user, Challenge); /* ship off to winbind, and check */ if (run_ntlm_auth(username, domain, NULL, NULL, Challenge, 8, NULL, 0, &response[MS_CHAP2_NTRESP], MS_CHAP2_NTRESP_LEN, session_key, &error_string) == AUTHENTICATED) { GenerateAuthenticatorResponse(session_key, &response[MS_CHAP2_NTRESP], &response[MS_CHAP2_PEER_CHALLENGE], challenge, user, saresponse); mppe_set_keys2(session_key, &response[MS_CHAP2_NTRESP], MS_CHAP2_AUTHENTICATOR); if (response[MS_CHAP2_FLAGS]) { slprintf(message, message_space, "S=%s", saresponse); } else { slprintf(message, message_space, "S=%s M=%s", saresponse, "Access granted"); } return AUTHENTICATED; } else { if (error_string) { notice(error_string); slprintf(message, message_space, "E=691 R=1 C=%0.*B V=0 M=%s", challenge_len, challenge, error_string); free(error_string); } else { slprintf(message, message_space, "E=691 R=1 C=%0.*B V=0 M=%s", challenge_len, challenge, "Access denied"); } return NOT_AUTHENTICATED; } break; } default: error("WINBIND: Challenge type %u unsupported", digest->code); } return NOT_AUTHENTICATED;}static int winbind_allowed_address(u_int32_t addr) { ipcp_options *wo = &ipcp_wantoptions[0]; if (wo->hisaddr !=0 && wo->hisaddr == addr) { return 1; } return -1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -