Debian Codegraph @

pam-extensions/gdm-custom-json-pam-extension.h

raw symbols SCIP
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2023 Canonical Ltd.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * Author: Marco Trevisan (TreviƱo) <[email protected]>
20 *
21 */
22
23 #pragma once
24
25 #include "gdm-pam-extensions-common.h"
26
27 typedef struct {
28 GdmPamExtensionMessage header;
29
30 const char protocol_name[64];
31 unsigned int version;
32 char *json;
33 } GdmPamExtensionJSONProtocol;
34
35 #define GDM_PAM_EXTENSION_CUSTOM_JSON "org.gnome.DisplayManager.UserVerifier.CustomJSON"
36 #define GDM_PAM_EXTENSION_CUSTOM_JSON_SIZE sizeof (GdmPamExtensionJSONProtocol)
37
38 #define GDM_PAM_EXTENSION_CUSTOM_JSON_REQUEST_INIT(request, proto_name, proto_version, json_str) \
39 { \
40 size_t proto_len = strnlen ((proto_name), sizeof ((request)->protocol_name) - 1); \
41 GDM_PAM_EXTENSION_LOOK_UP_TYPE (GDM_PAM_EXTENSION_CUSTOM_JSON, &((request)->header.type)); \
42 (request)->header.length = htobe32 (GDM_PAM_EXTENSION_CUSTOM_JSON_SIZE); \
43 memcpy ((char *)(request)->protocol_name, (proto_name), proto_len); \
44 ((char *)((request)->protocol_name))[proto_len] = '\0'; \
45 (request)->version = (proto_version); \
46 (request)->json = (char *) (json_str); \
47 }
48
49 #define GDM_PAM_EXTENSION_CUSTOM_JSON_RESPONSE_INIT(response, proto_name, proto_version) \
50 { \
51 size_t proto_len = strnlen ((proto_name), sizeof ((response)->protocol_name) - 1); \
52 GDM_PAM_EXTENSION_LOOK_UP_TYPE (GDM_PAM_EXTENSION_CUSTOM_JSON, &((response)->header.type)); \
53 (response)->header.length = htobe32 (GDM_PAM_EXTENSION_CUSTOM_JSON_SIZE); \
54 memcpy ((char *)(response)->protocol_name, (proto_name), proto_len); \
55 ((char *)((response)->protocol_name))[proto_len] = '\0'; \
56 (response)->version = (proto_version); \
57 (response)->json = NULL; \
58 }
59
60 #define GDM_PAM_EXTENSION_REPLY_TO_CUSTOM_JSON_RESPONSE(reply) \
61 ((GdmPamExtensionJSONProtocol *) (void *) reply->resp)