A simple login app for testing.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23400 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2008-01-11 14:33:31 +00:00
parent 5e53d38a62
commit 648110193d
9 changed files with 447 additions and 0 deletions

17
src/apps/login/Jamfile Normal file
View File

@ -0,0 +1,17 @@
SubDir HAIKU_TOP src apps login ;
SetSubDirSupportedPlatformsBeOSCompatible ;
#UsePrivateHeaders shared ;
#UsePrivateHeaders tracker ;
#SubDirHdrs $(HAIKU_TOP) src kits tracker ;
Application Login :
LoginApp.cpp
LoginWindow.cpp
LoginView.cpp
main.cpp
: be tracker
: Login.rdef
;

128
src/apps/login/Login.rdef Normal file
View File

@ -0,0 +1,128 @@
resource app_signature "application/x-vnd.Haiku-Login";
resource app_version {
major = 5,
middle = 2,
minor = 1,
variety = B_APPV_FINAL,
internal = 0,
short_info = "Tracker",
long_info = "Tracker 5.2.1 ©1991-2001 Be, Inc.,\n"
"©2006-2007 Haiku, Inc."
};
resource app_flags B_SINGLE_LAUNCH;
/*resource file_types message {
"types" = "application/x-vnd.Be-symlink",
"types" = "application/x-vnd.Be-directory",
"types" = "application/x-vnd.Be-query",
"types" = "application/x-vnd.Be-volume",
"types" = "application/x-vnd.Be-queryTemplate",
"types" = "application/x-vnd.Be-root",
"types" = "application/x-vnd.Be-elfexecutable",
"types" = "application/x-vnd.Be.printer",
"types" = "application/octet-stream"
};*/
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
resource vector_icon {
$"6E636966120500040068020106023ECFFF0000000000003EFFFF486000474000"
$"00DDA771FEA97644020006033C0564379BD6B9B4043E12EF49C94948FD140087"
$"5B2FFFC58A50C4A97644020006023AA0B4B6910F3840E83C4EA54A20CC3C5E02"
$"00F4C597FFDAA47003D7A26E03DAA470020006033AC3B134D937B81B9A3E0BAC"
$"4B13774865BC00C28D59FFB6783BDCA26C3803A4703E020106023B46923A3AF8"
$"BC79A03DA299463C564592D600FDD6ABFFC48B540399632D03F8CCA102000602"
$"38586D38586DB9279239279249CD5B46BF4E00D4975BFFA06F40020016023AA1"
$"AE3A9018BAE9A13AAE8E491D7E4A50B500EDFFA505FF020016023228D0398DC3"
$"BD46803591CA48EEC34A35750091FFB5020016023A05CA3C319CBEA5C93C305F"
$"4A55B949E8F800FFFFE9020006023375F8391697BA971434E7134759DA498BDF"
$"00FFEA00FFFFB83017060BEA4B08335A3D594260525E4B61595B604DCD01C7B3"
$"5E425248464C4C4354380604AE302628262D24B418B63A222E2C2C0A05B639BC"
$"B92B372B36263426350605BA03342E38284030BF44B77141343E3838323A3436"
$"300608EEEE342E38323630BCFBBA973E3840304134BF44B77138284230C027B7"
$"0443363F3A38343A36363206033E5A224A26542A4A264C274C27592C06033BC5"
$"64B639C564B6395A305A22C48AB5CB592CC48AB5CB06156F6BEBB8BC03343038"
$"2A3036303E303A304232445234582A583C583846404A56425E345E4A5E444248"
$"3E4E424C425042525448584E4C4E604E563E545434543854B9B2C564B639C736"
$"B7B45A305A224A26542AC165B4740609BEFB02483E4E3EC431BF54513D523452"
$"36522EC564B639452749263D29353340314031C17ABADA463A4638463C444206"
$"0ADBDA0E4031C17ABADA4031303D3F3541333F37433846404A56425E345E4A5E"
$"4442463A463C46380606B60B32445234582A583C58384635413743333F303F06"
$"0BCFB83C5234522E52364E3E513DC431BF54484E424C425042525448584E4C4E"
$"604E563E545434543854B9B2C564B639C736B7B4C564B6390605BB033430382A"
$"3430353445273DB6954926C564B6394A264A26C165B4740204BE31B7FBBE31B7"
$"FBBE6BB89E3C32BE6EB958BDDCBB0FBC2FBC93BD1EBBE6BC2FBC93352F363135"
$"2F02063426B796B443BC88B5E9BE31B7FB3BB6C6BE31B7FB352F352F3631BC2F"
$"BC93BC2FBC93BADFBD862C3CB92D3C263C2632B4C7BC9D282A0204292CB6CE2C"
$"B65D2C28B8C728B83A28B9532931B65D31B6CE312BB8C72BB9532BB83A020430"
$"30B9D030B8EF302E322EB9BB2EBA9C3034B8EF34B9D034323232BA9C32B9BB0A"
$"06224C385738452C402C3C22380A04223C224C385738450A063451264A244B36"
$"54364634470A06243E244B264A2641344736460A042642264A345134480A0422"
$"38223C2C402C3C190A010100000A0001071001178402040A0200000A03010900"
$"0A020108000A05010A000A07010B000A04010C000A060105000A070106000A00"
$"01011001178402040A0B0101000A00020D0E1001178402040A09010E000A0A01"
$"0D000A000104000A0C0103000A000102000A00020F10000A0001111001178400"
$"040A0D0112000A0E0113000A0F0114000A100115000A11011600"
};
#else // HAIKU_TARGET_PLATFORM_HAIKU
resource large_icon array {
$"FFFF000000FFFFFFFFFFFFFFFFFFFFFF0000000000000000000000FFFFFFFFFF"
$"FF00D9D9D900FFFFFFFFFFFFFFFF0000838383838383008383D9D900FFFFFFFF"
$"00D9D98383000000000000FFFF00838383838383838383010000D9D900FFFFFF"
$"00D9838383D9D9D9D9D9D90000AA00008383D9D9838383AAAA0183D900FFFFFF"
$"00D90083D9D9D983838383D9D900D9D901D9D9D9D9D983AAAA00AAD900FFFFFF"
$"00D900D90000D98383838383D9D9D9D900D9D9D9838383AAAAAA018300FFFFFF"
$"00D900D90083838383000083D90083D983008383838383AAAAAA01AA00FFFFFF"
$"0000D9D98383838383008383D9AA00D983008383838383AAAAAA01AA00FFFFFF"
$"FF0083AAAAAAAAD9D9838383D9AA00D983008383838383AAAAAA01AAD900FFFF"
$"FFAA00AAD983838383D9D9D9D90083D983008383838383AAAAAA01AA83D900FF"
$"FF00D9D98383D98383AAAAD98300D9D983008383830083AAAAAA0100AA83D900"
$"FF00D900D9D9AAAAAAAAAAD9AA00D9D983008383008383AAAAAA01FF00AAAA00"
$"00D9000000AAAAAAAAAAD9AAAA00D983AA0083AA008383AAAAAA00FFFF0000FF"
$"0000D900AAAA00000000D9AA0000AAAA008383AA008383AAAAAA00FFFFFFFFFF"
$"00FA00000000008383AAAA00AAAA0000838300AA00838383AAAAAA00FFFFFFFF"
$"00170FF8F8FA0000000000AAAAAAAAAA838300000083838383AAAA00FFFFFFFF"
$"00170F0F0FF81B000000AAAAAAAA00AA838301FFFF00000000AAAAAA00FFFFFF"
$"00170F3F3F0E0F3F3F3F0000AAAA00AA838300FFFFFFFFFFFF00AAAA00FFFFFF"
$"00170F3F3F3F3F0E0F0F3F1900AAAA00838300FFFFFFFFFFFFFF00AAAA00FFFF"
$"00170F3F3F3F3F3F3F3F0E180000000083AA00FFFFFFFFFFFF00D9AAAA000FFF"
$"00170F3F3F3F3F3F3F3F3F1700FFFF00838300FFFFFFFFFFFF00D9AAAA000F0E"
$"001C173F3F3F3F3F3F3F3F1700FFFF008383AA00FFFFFFFFFF000000000E0F0F"
$"001C17183F3F3F3F3F3F3F1700FFFF008383AA00FFFFFFFFFF0E0F0F0F0F0F0F"
$"00003F3F17173F3F3F3F3F1700FFFF008383AA00FFFFFFFFFFFFFFFFFFFFFFFF"
$"1BFF00003F3F17173F3F3F1700FFFF00838300FFFFFFFFFFFFFFFFFFFFFFFFFF"
$"1B1C00FF00003F3F17173F1700FFFF00838300FFFFFFFFFFFFFFFFFFFFFFFFFF"
$"1B0083AAAA0000003F3F171700FFFF00838300FFFFFFFFFFFFFFFFFFFFFFFFFF"
$"00AAAAAAAA000EFF00003F3F00FF0083838300FFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FF000000000E0F0F0F0F000000FF008383AA000F0F0E0F0F0F0F0FFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFF00FFFF0000000E0F0F0F0F0F0FFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
$"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
};
resource mini_icon array {
$"FF0000FFFFFFFFFF000000000000FFFF"
$"00D900000000FF008383D900838300FF"
$"00D98383838300D900D983AA00AA00FF"
$"00D900830083AAD9008383AAAA0000FF"
$"00AAAAAA83830083008383AAAA0000FF"
$"FF00008383AA008300830083AA008300"
$"0000000000AA0000AAAA0083AA000000"
$"00F800000000AAAAD90000D9AA00FFFF"
$"00F8F8F817170000D9000000D9AA01FF"
$"00173F3F3F3F1700D900FFFF00AA00FF"
$"00173F3F3F3F1700D900FFFF00AA000E"
$"00183F3F3F3F17008300FFFF0000000E"
$"0000003F3F3F17008300FFFFFFFFFFFF"
$"FF008300003F17008300FFFFFFFFFFFF"
$"00000000FF000083AA000F0E0F0FFFFF"
$"FFFFFFFFFFFFFF00000E0F0F0FFFFFFF"
};
#endif // HAIKU_TARGET_PLATFORM_HAIKU

142
src/apps/login/LoginApp.cpp Normal file
View File

@ -0,0 +1,142 @@
#include <Screen.h>
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
#include "LoginApp.h"
#include "LoginWindow.h"
const char *kLoginAppSig = "application/x-vnd.Haiku-Login";
LoginApp::LoginApp()
: BApplication(kLoginAppSig)
{
}
LoginApp::~LoginApp()
{
}
void
LoginApp::ReadyToRun()
{
BScreen s;
BRect frame(0, 0, 300, 100);
frame.OffsetBySelf(s.Frame().Width()/2 - frame.Width()/2,
s.Frame().Height()/2 - frame.Height()/2);
LoginWindow *w = new LoginWindow(frame);
w->Show();
}
void
LoginApp::MessageReceived(BMessage *message)
{
switch (message->what) {
case kMsgOpenFilePanel:
break;
default:
BApplication::MessageReceived(message);
}
}
void TryLogin(BMessage *message);
status_t ValidateLogin(const char *login, const char *password/*, bool force = false*/);
void
LoginApp::TryLogin(BMessage *message)
{
status_t err;
const char *login;
const char *password;
BMessage reply(B_REPLY);
if (message->FindString("login", &login) == B_OK) {
if (message->FindString("password", &password) < B_OK)
password = NULL;
err = ValidateLogin(login, password);
if (err == B_OK) {
reply.AddInt32("error", B_OK);
message->SendReply(reply, NULL);
if (password == NULL)
return;
// start a session
//kSetProgress
StartUserSession(login);
} else {
reply.AddInt32("error", err);
message->SendReply(reply, NULL);
return;
}
} else {
reply.AddInt32("error", EINVAL);
message->SendReply(reply, NULL);
return;
}
}
status_t
LoginApp::ValidateLogin(const char *login, const char *password/*, bool force = false*/)
{
struct passwd *pwd;
pwd = getpwnam(login);
if (!pwd)
return ENOENT;
if (strcmp(pwd->pw_name, login))
return ENOENT;
if (password == NULL) {
// we only want to check is login exists.
return B_OK;
}
// XXX: check for shadow pass
if (strcmp(crypt(password, pwd->pw_passwd), pwd->pw_passwd))
return B_NOT_ALLOWED;
return B_OK;
}
status_t
LoginApp::StartUserSession(const char *login)
{
return B_ERROR;
}
int
LoginApp::getpty(char *pty, char *tty)
{
static const char major[] = "pqrs";
static const char minor[] = "0123456789abcdef";
uint32 i, j;
int32 fd = -1;
for (i = 0; i < sizeof(major); i++)
{
for (j = 0; j < sizeof(minor); j++)
{
sprintf(pty, "/dev/pt/%c%c", major[i], minor[j]);
sprintf(tty, "/dev/tt/%c%c", major[i], minor[j]);
fd = open(pty, O_RDWR|O_NOCTTY);
if (fd >= 0)
{
return fd;
}
}
}
return fd;
}

19
src/apps/login/LoginApp.h Normal file
View File

@ -0,0 +1,19 @@
#include <Application.h>
/* try loging in a user */
const uint32 kMsgOpenFilePanel = 'logi';
class LoginApp : public BApplication {
public:
LoginApp();
virtual ~LoginApp();
void ReadyToRun();
void MessageReceived(BMessage *message);
private:
void TryLogin(BMessage *message);
status_t ValidateLogin(const char *login, const char *password/*, bool force = false*/);
status_t StartUserSession(const char *login);
int getpty(char *pty, char *tty);
};

View File

@ -0,0 +1,82 @@
#include <ScrollView.h>
#include <pwd.h>
#include "LoginView.h"
#define CSEP 15
LoginView::LoginView(BRect frame)
: BView(frame, "LoginView", B_FOLLOW_ALL, 0)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetLowColor(ViewColor());
BRect r;
r.Set(CSEP, CSEP, 80, Bounds().Height() - 2 * CSEP);
fUserList = new BListView(r, "users");
BScrollView *sv = new BScrollView("userssv", fUserList);
AddChild(sv);
r.Set(100, Bounds().top + CSEP, Bounds().right - CSEP, Bounds().top + CSEP + CSEP);
fLoginControl = new BTextControl(r, "login", "login:", "", new BMessage(kLoginEdited));
AddChild(fLoginControl);
r.OffsetBySelf(0, CSEP + CSEP);
fPasswordControl = new BTextControl(r, "password", "password:", "", new BMessage(kPasswordEdited));
AddChild(fPasswordControl);
}
LoginView::~LoginView()
{
}
void
LoginView::AttachedToWindow()
{
fLoginControl->MakeFocus();
// populate user list
BMessenger(this).SendMessage(kAddNextUser);
}
void
LoginView::MessageReceived(BMessage *message)
{
switch (message->what) {
case kSetProgress:
break;
case kAddNextUser:
AddNextUser();
break;
default:
BView::MessageReceived(message);
}
}
void
LoginView::AddNextUser()
{
struct passwd *pwd;
if (fUserList->CountItems() < 1)
setpwent();
pwd = getpwent();
if (pwd && pwd->pw_shell &&
strcmp(pwd->pw_shell, "false") &&
strcmp(pwd->pw_shell, "true") &&
strcmp(pwd->pw_shell, "/bin/false") &&
strcmp(pwd->pw_shell, "/bin/true")) {
// not disabled
BStringItem *item = new BStringItem(pwd->pw_name);
fUserList->AddItem(item);
}
if (pwd)
BMessenger(this).SendMessage(kAddNextUser);
else
endpwent();
}

View File

@ -0,0 +1,23 @@
#include <View.h>
#include <ListItem.h>
#include <ListView.h>
#include <TextControl.h>
const uint32 kLoginEdited = 'logc';
const uint32 kPasswordEdited = 'pasc';
const uint32 kAddNextUser = 'adnu';
const uint32 kSetProgress = 'setp';
class LoginView : public BView {
public:
LoginView(BRect frame);
virtual ~LoginView();
void AttachedToWindow();
void MessageReceived(BMessage *message);
private:
void AddNextUser();
BTextControl *fLoginControl;
BTextControl *fPasswordControl;
BListView *fUserList;
};

View File

@ -0,0 +1,19 @@
#include "LoginWindow.h"
#include "LoginView.h"
LoginWindow::LoginWindow(BRect frame)
: BWindow(frame, /*"Login"*/"Welcome to Haiku", B_TITLED_WINDOW_LOOK,
B_NORMAL_WINDOW_FEEL/*B_FLOATING_ALL_WINDOW_FEEL*/,
B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE |
B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS)
{
LoginView *v = new LoginView(Bounds());
AddChild(v);
}
LoginWindow::~LoginWindow()
{
}

View File

@ -0,0 +1,8 @@
#include <Window.h>
class LoginWindow : public BWindow {
public:
LoginWindow(BRect frame);
virtual ~LoginWindow();
};

9
src/apps/login/main.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "LoginApp.h"
int main(int , char **)
{
LoginApp app;
app.Run();
return 0;
}