-
-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/child-second-parameter
- Loading branch information
Showing
18 changed files
with
426 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import App from '../app.js'; | ||
import Service from '../service.js'; | ||
import GLib from 'gi://GLib'; | ||
import Gio from 'gi://Gio'; | ||
|
||
Gio._promisify(Gio.InputStream.prototype, 'read_bytes_async'); | ||
const SOCK = GLib.getenv('GREETD_SOCK'); | ||
|
||
type Request = { | ||
create_session: { | ||
username: string | ||
} | ||
post_auth_message_response: { | ||
response?: string | ||
} | ||
start_session: { | ||
cmd: string[] | ||
env: string[] | ||
} | ||
cancel_session: Record<never, never> | ||
} | ||
|
||
type Response = { | ||
type: 'success' | ||
} | { | ||
type: 'error' | ||
error_type: 'auth_error' | 'error' | ||
description: string | ||
} | { | ||
type: 'auth_message' | ||
auth_message_type: 'visible' | 'secret' | 'info' | 'error' | ||
auth_message: string | ||
} | ||
|
||
export class Greetd extends Service { | ||
static { Service.register(this); } | ||
|
||
private _decoder = new TextDecoder; | ||
|
||
async login( | ||
username: string, | ||
password: string, | ||
cmd: string[] | string, | ||
env: string[] = [], | ||
) { | ||
const session = await this.createSession(username); | ||
if (session.type !== 'auth_message') { | ||
this.cancelSession(); | ||
throw session; | ||
} | ||
|
||
const auth = await this.postAuth(password); | ||
if (auth.type !== 'success') { | ||
this.cancelSession(); | ||
throw auth; | ||
} | ||
|
||
const start = await this.startSession(cmd, env); | ||
if (start.type !== 'success') { | ||
this.cancelSession(); | ||
throw start; | ||
} | ||
|
||
App.quit(); | ||
} | ||
|
||
createSession(username: string) { | ||
return this._send('create_session', { username }); | ||
} | ||
|
||
postAuth(response?: string) { | ||
return this._send('post_auth_message_response', { response }); | ||
} | ||
|
||
startSession(cmd: string[] | string, env: string[] = []) { | ||
const cmdv = Array.isArray(cmd) | ||
? cmd | ||
: GLib.shell_parse_argv(cmd)[1]; | ||
|
||
return this._send('start_session', { cmd: cmdv, env }); | ||
} | ||
|
||
cancelSession() { | ||
return this._send('cancel_session', {}); | ||
} | ||
|
||
private async _send<R extends keyof Request>(req: R, payload: Request[R]): Promise<Response> { | ||
const connection = new Gio.SocketClient() | ||
.connect(new Gio.UnixSocketAddress({ path: SOCK }), null); | ||
|
||
try { | ||
const json = JSON.stringify({ type: req, ...payload }); | ||
const ostream = new Gio.DataOutputStream({ | ||
close_base_stream: true, | ||
base_stream: connection.get_output_stream(), | ||
byte_order: Gio.DataStreamByteOrder.HOST_ENDIAN, | ||
}); | ||
|
||
const istream = connection.get_input_stream(); | ||
|
||
ostream.put_int32(json.length, null); | ||
ostream.put_string(json, null); | ||
|
||
const data = await istream.read_bytes_async(4, GLib.PRIORITY_DEFAULT, null); | ||
const length = new Uint32Array(data.get_data()?.buffer || [0])[0]; | ||
const res = await istream.read_bytes_async(length, GLib.PRIORITY_DEFAULT, null); | ||
return JSON.parse(this._decoder.decode(res.get_data()!)) as Response; | ||
} finally { | ||
connection.close(null); | ||
} | ||
} | ||
} | ||
|
||
export const greetd = new Greetd; | ||
export default greetd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//@ts-expect-error missing types | ||
import GUtils from 'gi://GUtils'; | ||
import Gio from 'gi://Gio'; | ||
|
||
export function authenticate(password: string) { | ||
return new Promise((resolve, reject) => { | ||
GUtils.authenticate(password, 0, null, (_: unknown, res: Gio.AsyncResult) => { | ||
try { | ||
resolve(GUtils.authenticate_finish(res)); | ||
} | ||
catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
export function authenticateUser(username: string, password: string) { | ||
return new Promise((resolve, reject) => { | ||
GUtils.authenticate_user( | ||
username, password, 0, null, (_: unknown, res: Gio.AsyncResult) => { | ||
try { | ||
resolve(GUtils.authenticate_finish(res)); | ||
} | ||
catch (e) { | ||
reject(e); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# PAM configuration file for ags. By default, it includes | ||
# the 'login' configuration file (see /etc/pam.d/login) | ||
|
||
auth include login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
project('pam', 'c') | ||
|
||
pkglibdir = get_option('pkglibdir') | ||
pkgdatadir = get_option('pkgdatadir') | ||
|
||
cc = meson.get_compiler('c') | ||
|
||
libsources = ['pam.c', 'pam.h'] | ||
|
||
deps = [ | ||
dependency('gobject-2.0'), | ||
dependency('gio-2.0'), | ||
dependency('pam') | ||
] | ||
|
||
girlib = shared_library( | ||
'gutils', | ||
sources: libsources, | ||
dependencies: deps, | ||
install: true | ||
) | ||
|
||
gnome = import('gnome') | ||
gnome.generate_gir( | ||
girlib, | ||
sources: libsources, | ||
nsversion: '1.0', | ||
namespace: 'GUtils', | ||
symbol_prefix: 'gutils', | ||
identifier_prefix: 'GUtils', | ||
includes: ['GObject-2.0', 'Gio-2.0'], | ||
install_dir_gir: pkgdatadir, | ||
install_dir_typelib: pkglibdir, | ||
install: true | ||
) | ||
|
||
install_data( | ||
'ags', | ||
install_dir: get_option('sysconfdir') / 'pam.d' | ||
) |
Oops, something went wrong.