Example #1
0
// Start initiates a new PAM transaction.  serviceName is treated identically
// to how pam_start internally treats it.  The same applies to user, except that
// the empty string is passed to PAM as nil; therefore the empty string should be
// used to signal that no username is being provided.
//
// All application calls to PAM begin with Start().  The returned *Transaction
// provides an interface to the remainder of the API.
//
// The returned status int may be ABORT, BUF_ERR, SUCCESS, or SYSTEM_ERR, as per
// the official PAM documentation.
func Start(serviceName, user string, handler ConversationHandler) (*Transaction, int) {
	t := &Transaction{}
	t.conv = newConversation(handler)
	var status C.int
	if len(user) == 0 {
		status = C.pam_start(C.CString(serviceName), nil, t.conv.cconv, &t.handle)
	} else {
		status = C.pam_start(C.CString(serviceName), C.CString(user), t.conv.cconv, &t.handle)
	}

	if status != SUCCESS {
		C.free(unsafe.Pointer(t.conv.cconv))
		return nil, int(status)
	}

	return t, int(status)
}
Example #2
0
// Start initiates a new PAM transaction. Service is treated identically to
// how pam_start treats it internally.
//
// All application calls to PAM begin with Start (or StartFunc). The returned
// transaction provides an interface to the remainder of the API.
func Start(service, user string, handler ConversationHandler) (*Transaction, error) {
	t := &Transaction{
		conv: &C.struct_pam_conv{},
		c:    cbAdd(handler),
	}
	C.init_pam_conv(t.conv, C.long(t.c))
	runtime.SetFinalizer(t, transactionFinalizer)
	s := C.CString(service)
	defer C.free(unsafe.Pointer(s))
	var u *C.char
	if len(user) != 0 {
		u = C.CString(user)
		defer C.free(unsafe.Pointer(u))
	}
	t.status = C.pam_start(s, u, t.conv, &t.handle)
	if t.status != C.PAM_SUCCESS {
		return nil, t
	}
	return t, nil
}
Example #3
0
// Start initiates a new PAM transaction. Service is treated identically to
// how pam_start treats it internally.
//
// All application calls to PAM begin with Start (or StartFunc). The returned
// transaction provides an interface to the remainder of the API.
func Start(service, user string, handler ConversationHandler) (*Transaction, error) {
	t := &Transaction{}
	t.conv, t.status = newConversation(handler)
	if t.status != C.PAM_SUCCESS {
		return nil, t
	}
	s := C.CString(service)
	defer C.free(unsafe.Pointer(s))
	var u *C.char
	if len(user) != 0 {
		u = C.CString(user)
		defer C.free(unsafe.Pointer(u))
	}
	t.status = C.pam_start(s, u, t.conv.conv, &t.handle)
	if t.status != C.PAM_SUCCESS {
		C.free(unsafe.Pointer(t.conv.conv))
		return nil, t
	}
	runtime.SetFinalizer(t, transactionFinalizer)
	return t, nil
}