Exemplo n.º 1
0
func milterGetSession(ctx uintptr, keep bool, returnNil bool) *milterSession {
	var u [16]byte
	res := m.GetPriv(ctx, &u)
	if res != 0 {
		// We purposefully do not act on errors. For some reason, the FreeBSD build always
		// returns an error. Also, in practice it never fails. Famous last words...
		//  panic("Could not get data from libmilter")
	}
	if keep {
		res := m.SetPriv(ctx, u)
		if res != 0 {
			panic(fmt.Sprintf("Session %d could not be stored in milterDataIndex", u))
		}
	}

	MilterDataIndex.mu.Lock()
	defer MilterDataIndex.mu.Unlock()

	out := MilterDataIndex.sessions[u]
	if out == nil && !returnNil {
		panic(fmt.Sprintf("Session %d could not be found in milterDataIndex", u))
	}

	return out
}
Exemplo n.º 2
0
func (milter *milter) Connect(ctx uintptr, hostname string, ip net.IP) (sfsistat int8) {
	defer milterHandleError(ctx, &sfsistat)

	sess := &milterSession{
		id:        milterGetNewSessionId(),
		timeStart: time.Now(),
		persisted: false,
	}
	sess.Hostname = hostname
	sess.Ip = ip.String()
	sess.MtaHostName = m.GetSymVal(ctx, "j")
	sess.MtaDaemonName = m.GetSymVal(ctx, "{daemon_name}")

	if reverse, _ := net.LookupAddr(ip.String()); len(reverse) != 0 {
		sess.ReverseDns = reverse[0]
	}

	MilterDataIndex.addNewSession(sess)
	sessId := sess.getId()
	res := m.SetPriv(ctx, sessId)
	if res != 0 {
		panic(fmt.Sprintf("Session could not be stored in milterDataIndex"))
	}

	StatsCounters["MilterCallbackConnect"].increase(1)
	Log.Debug("%s Milter.Connect() called: ip = %s, hostname = %s", sess.milterGetDisplayId(), ip, sess.ReverseDns)

	return m.Continue
}
Exemplo n.º 3
0
func milterGetSession(ctx uintptr, keep bool, returnNil bool) *milterSession {
	var u uint64
	m.GetPriv(ctx, &u)
	if keep {
		m.SetPriv(ctx, u)
	}

	MilterDataIndex.mu.Lock()
	defer MilterDataIndex.mu.Unlock()

	out := MilterDataIndex.sessions[u]
	if out == nil && !returnNil {
		panic(fmt.Sprintf("Session %d could not be found in milterDataIndex", u))
	}

	return out
}
Exemplo n.º 4
0
func (milter *milter) Connect(ctx uintptr, hostname string, ip net.IP) (sfsistat int8) {
	defer milterHandleError(ctx, &sfsistat)

	sess := &milterSession{timeStart: time.Now()}
	sess.Hostname = hostname
	sess.Ip = ip.String()
	sess.ReverseDns = m.GetSymVal(ctx, "{client_ptr}")
	sess.MtaHostName = m.GetSymVal(ctx, "j")
	sess.MtaDaemonName = m.GetSymVal(ctx, "{daemon_name}")
	MilterDataIndex.getNewSession(sess)
	m.SetPriv(ctx, sess.getId())

	StatsCounters["MilterCallbackConnect"].increase(1)
	Log.Debug("%d Milter.Connect() called: ip = %s, hostname = %s", sess.getId(), ip, hostname)

	return m.Continue
}