Debian Codegraph @

src/ws/cockpitauth.h

raw
1 /*
2 * Copyright (C) 2013 Red Hat, Inc.
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6 #ifndef __COCKPIT_AUTH_H__
7 #define __COCKPIT_AUTH_H__
8
9 #include <pwd.h>
10 #include <gio/gio.h>
11
12 #include "cockpitcreds.h"
13 #include "cockpitwebservice.h"
14
15 #include "cockpitpipe.h"
16 #include "cockpittransport.h"
17 #include "cockpitwebserver.h"
18
19 G_BEGIN_DECLS
20
21 typedef enum {
22 COCKPIT_AUTH_NONE = 0,
23 COCKPIT_AUTH_FOR_TLS_PROXY = 1 << 0,
24 } CockpitAuthFlags;
25
26 #define MAX_AUTH_TIMEOUT 900
27 #define MIN_AUTH_TIMEOUT 1
28
29 #define COCKPIT_TYPE_AUTH (cockpit_auth_get_type ())
30 #define COCKPIT_AUTH(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), COCKPIT_TYPE_AUTH, CockpitAuth))
31 #define COCKPIT_IS_AUTH(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), COCKPIT_TYPE_AUTH))
32 #define COCKPIT_AUTH_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), COCKPIT_TYPE_AUTH, CockpitAuthClass))
33 #define COCKPIT_IS_AUTH_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), COCKPIT_TYPE_AUTH))
34
35 typedef struct _CockpitAuth CockpitAuth;
36 typedef struct _CockpitAuthClass CockpitAuthClass;
37
38 struct _CockpitAuth
39 {
40 GObject parent_instance;
41
42 CockpitAuthFlags flags;
43 GBytes *key;
44 GHashTable *sessions;
45 GHashTable *conversations;
46
47 guint64 nonce_seed;
48 gboolean login_loopback;
49 gulong timeout_tag;
50 guint startups;
51 guint max_startups;
52 guint max_startups_begin;
53 guint max_startups_rate;
54 };
55
56 struct _CockpitAuthClass
57 {
58 GObjectClass parent_class;
59 };
60
61 GType cockpit_auth_get_type (void) G_GNUC_CONST;
62
63 CockpitAuth * cockpit_auth_new (gboolean login_loopback, CockpitAuthFlags flags);
64
65 void cockpit_auth_login_async (CockpitAuth *self,
66 CockpitWebRequest *request,
67 GAsyncReadyCallback callback,
68 gpointer user_data);
69
70 JsonObject * cockpit_auth_login_finish (CockpitAuth *self,
71 GAsyncResult *result,
72 GIOStream *connection,
73 GHashTable *out_headers,
74 GError **error);
75
76 void cockpit_auth_local_async (CockpitAuth *self,
77 const gchar *user,
78 CockpitPipe *pipe,
79 GAsyncReadyCallback callback,
80 gpointer user_data);
81
82 CockpitWebService * cockpit_auth_check_cookie (CockpitAuth *self,
83 CockpitWebRequest *request);
84
85 gboolean cockpit_auth_is_valid_cookie_value (CockpitAuth *self,
86 const gchar *cookie_value);
87
88 gchar * cockpit_auth_parse_application (const gchar *path,
89 gboolean *is_host);
90
91 gchar * cockpit_auth_empty_cookie_value (const gchar *path,
92 gboolean secure);
93
94 G_END_DECLS
95
96 #endif