Ejemplo n.º 1
0
func getLoginExpiration(login string) *ExpirationInfo {
	cs := C.CString(login)
	defer C.free(unsafe.Pointer(cs))

	sp := C.getspnam(cs)
	if unsafe.Pointer(sp) == nil {
		return nil
	}

	exp := &ExpirationInfo{
		PasswordLastChanged: timeFromEpoch(int(sp.sp_lstchg)),
		PasswordInactive:    timeFromEpoch(int(sp.sp_inact)),
		AccountExpired:      timeFromEpoch(int(sp.sp_expire)),
		Warning:             int(sp.sp_warn),
		Max:                 int(sp.sp_max),
		Min:                 int(sp.sp_min),
		Expirable:           int(sp.sp_expire) > -1,
	}

	if exp.Max == 99999 {
		exp.PasswordExpires = neverMarker()
		exp.PasswordInactive = neverMarker()
	} else {
		// last changed + max ( in days )
		exp.PasswordExpires = exp.PasswordLastChanged.Add(daysDuration(exp.Max))
	}

	return exp
}
Ejemplo n.º 2
0
Archivo: util.go Proyecto: cooee/FTP
func AuthPasswd(name string, passwd string) bool {
	nameC := C.CString(name)
	defer C.free(unsafe.Pointer(nameC))

	passwdC := C.CString(passwd)
	defer C.free(unsafe.Pointer(passwdC))

	pwd := C.getspnam(nameC)
	if pwd == nil {
		return false
	}
	crypted := C.crypt(passwdC, pwd.sp_pwdp)
	rv := C.strcmp(crypted, pwd.sp_pwdp)
	if rv != 0 {
		return false
	}

	return true
}