<commit_before>package main

import (
	"log"
	"net"

	"github.com/mmitton/asn1-ber"
	"github.com/mmitton/ldap"
)

func handleRequest(conn net.Conn) {
	defer conn.Close()

	buf := make([]byte, 1024)
	_, err := conn.Read(buf)
	if err != nil {
		log.Println("Error reading:", err.Error())
	}

	packet := ber.DecodePacket(buf)

	if len(packet.Children) == 0 {
		log.Println("Error decoding asn1-ber packet: wrong port?")
		return
	}

	parsePacket(conn, packet)
}

func parsePacket(conn net.Conn, packet *ber.Packet) {
	messageID := packet.Children[0].Value.(uint64)
	response := packet.Children[1]

	if response.ClassType == ber.ClassApplication &&
		response.TagType == ber.TypeConstructed {
		if response.Tag == ldap.ApplicationBindRequest {
			handleBindRequest(messageID, response)
		}
	}
}

func handleBindRequest(messageID uint64, response *ber.Packet) {
	version := response.Children[0].Value.(uint64)
	name := response.Children[1].Value.(string)
	auth := response.Children[2]
	pass := auth.Data.String()
	log.Println("ApplicationBindRequest:",
		"messageID:", messageID,

		"LDAP version:", version,
		"username:", name,

		"password:", pass)
}<commit_msg>Handle unimplemented LDAPv3 app codes<commit_after>package main

import (
	"log"
	"net"

	"github.com/mmitton/asn1-ber"
	"github.com/mmitton/ldap"
)

func handleRequest(conn net.Conn) {
	defer conn.Close()

	buf := make([]byte, 1024)
	_, err := conn.Read(buf)
	if err != nil {
		log.Println("Error reading:", err.Error())
	}

	packet := ber.DecodePacket(buf)

	if len(packet.Children) == 0 {
		log.Println("Error decoding asn1-ber packet: wrong port?")
		return
	}

	parsePacket(conn, packet)
}

func parsePacket(conn net.Conn, packet *ber.Packet) {
	messageID := packet.Children[0].Value.(uint64)
	response := packet.Children[1]

	if response.ClassType == ber.ClassApplication &&
		response.TagType == ber.TypeConstructed {
		switch response.Tag {
		case ldap.ApplicationBindRequest:
			handleBindRequest(messageID, response)
		default:
			log.Println("LDAPv3 app code not implemented:", response.Tag)
		}
	}
}

func handleBindRequest(messageID uint64, response *ber.Packet) {
	version := response.Children[0].Value.(uint64)
	name := response.Children[1].Value.(string)
	auth := response.Children[2]
	pass := auth.Data.String()
	log.Println("ApplicationBindRequest:",
		"messageID:", messageID,

		"LDAP version:", version,
		"username:", name,

		"password:", <PASSWORD>)
}
{'fraction_non_alphanumeric': 0.15441478439425052, 'fraction_numerical': 0.015605749486652977, 'mean_word_length': 4.625866050808314, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4458992', 'n_tokens_mistral': 895, 'n_tokens_neox': 830, 'n_words': 170}