2 * Copyright 2008, François Revol, <revol@free.fr>. All rights reserved.
3 * Distributed under the terms of the MIT License.
19 #include <LaunchRoster.h>
20 #include <RosterPrivate.h>
23 #include "multiuser_utils.h"
26 #include "LoginWindow.h"
27 #include "DesktopWindow.h"
30 #undef B_TRANSLATION_CONTEXT
31 #define B_TRANSLATION_CONTEXT "Login App"
33 const char *kLoginAppSig
= "application/x-vnd.Haiku-Login";
38 BApplication(kLoginAppSig
),
39 fEditShelfMode(false),
51 LoginApp::ReadyToRun()
56 BAlert
* alert
= new BAlert(B_TRANSLATE("Info"), B_TRANSLATE("You can "
57 "customize the desktop shown behind the Login application by "
58 "dropping replicants onto it.\n\n"
59 "When you are finished just quit the application (Cmd-Q)."),
61 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
64 float sizeDelta
= (float)be_plain_font
->Size()/12.0f
;
65 BRect
frame(0, 0, 450 * sizeDelta
, 150 * sizeDelta
);
66 frame
.OffsetBySelf(screen
.Frame().Width()/2 - frame
.Width()/2,
67 screen
.Frame().Height()/2 - frame
.Height()/2);
68 fLoginWindow
= new LoginWindow(frame
);
72 fDesktopWindow
= new DesktopWindow(screen
.Frame(), fEditShelfMode
);
73 fDesktopWindow
->Show();
74 // TODO: add a shelf with Activity Monitor replicant :)
79 LoginApp::MessageReceived(BMessage
*message
)
83 switch (message
->what
) {
94 BRoster::Private
rosterPrivate(roster
);
95 status_t error
= rosterPrivate
.ShutDown(reboot
, false, false);
97 BString
msg(B_TRANSLATE("Error: %1"));
98 msg
.ReplaceFirst("%1", strerror(error
));
99 BAlert
* alert
= new BAlert(("Error"), msg
.String(),
101 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
108 BAlert
* alert
= new BAlert(B_TRANSLATE("Error"),
109 B_TRANSLATE("Unimplemented"), B_TRANSLATE("OK"));
110 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
116 BApplication::MessageReceived(message
);
122 LoginApp::ArgvReceived(int32 argc
, char **argv
)
124 for (int i
= 1; i
< argc
; i
++) {
125 BString
arg(argv
[i
]);
126 //printf("[%d]: %s\n", i, argv[i]);
128 fEditShelfMode
= true;
129 else if (arg
== "--nonmodal")
131 else /*if (arg == "--help")*/ {
132 printf(B_TRANSLATE("Login application for Haiku\nUsage:\n"));
133 printf("%s [--nonmodal] [--edit]\n", argv
[0]);
134 printf(B_TRANSLATE("--nonmodal Do not make the window modal\n"));
135 printf(B_TRANSLATE("--edit Launch in shelf editting mode to "
136 "allow customizing the desktop.\n"));
137 // just return to the shell
138 exit((arg
== "--help") ? 0 : 1);
146 LoginApp::TryLogin(BMessage
*message
)
148 BMessage
reply(kLoginBad
);
149 status_t status
= B_BAD_VALUE
;
152 if (message
->FindString("login", &login
) == B_OK
) {
153 const char* password
= message
->GetString("password");
155 status
= ValidateLogin(login
, password
);
156 if (status
== B_OK
) {
157 status
= BLaunchRoster().StartSession(login
);
162 fprintf(stderr
, "ValidateLogin: %s\n", strerror(status
));
165 if (status
== B_OK
) {
166 reply
.what
= kLoginOk
;
167 message
->SendReply(&reply
);
169 reply
.AddInt32("error", status
);
170 message
->SendReply(&reply
);
176 LoginApp::ValidateLogin(const char *login
, const char *password
)
180 pwd
= getpwnam(login
);
183 if (strcmp(pwd
->pw_name
, login
) != 0)
186 if (verify_password(pwd
, getspnam(login
), password
))
189 return B_PERMISSION_DENIED
;
194 LoginApp::getpty(char *pty
, char *tty
)
196 static const char major
[] = "pqrs";
197 static const char minor
[] = "0123456789abcdef";
201 for (i
= 0; i
< sizeof(major
); i
++)
203 for (j
= 0; j
< sizeof(minor
); j
++)
205 sprintf(pty
, "/dev/pt/%c%c", major
[i
], minor
[j
]);
206 sprintf(tty
, "/dev/tt/%c%c", major
[i
], minor
[j
]);
207 fd
= open(pty
, O_RDWR
|O_NOCTTY
);