summaryrefslogtreecommitdiffstats
path: root/src/responder/secrets/secsrv_private.h
blob: 4b55f645a140e7650750196f7706ba183765efb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
   SSSD

   Secrets Responder, private header file

   Copyright (C) Simo Sorce <ssorce@redhat.com>	2016

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef __SECSRV_PRIVATE_H__
#define __SECSRV_PRIVATE_H__

#include "config.h"
#include "responder/common/responder.h"
#include <http_parser.h>

struct sec_kvp {
    char *name;
    char *value;
};

struct sec_data {
    char *data;
    size_t length;
};

enum sec_http_status_codes {
    STATUS_200 = 0,
    STATUS_400,
    STATUS_401,
    STATUS_403,
    STATUS_404,
    STATUS_405,
    STATUS_406,
    STATUS_409,
    STATUS_500,
};

struct sec_proto_ctx {
    http_parser_settings callbacks;
    http_parser parser;
};

struct sec_url {
    char *schema;
    char *host;
    int port;
    char *path;
    char *fragment;
    char *userinfo;
    char *query;
};

struct sec_req_ctx {
    struct cli_ctx *cctx;
    const char *cfg_section;
    bool complete;

    size_t total_size;

    char *request_url;
    char *mapped_path;

    uint8_t method;
    struct sec_url parsed_url;
    struct sec_kvp *headers;
    int num_headers;
    struct sec_data body;

    struct sec_data reply;
};

typedef struct tevent_req *(*sec_provider_req_t)(TALLOC_CTX *mem_ctx,
                                                 struct tevent_context *ev,
                                                 void *provider_ctx,
                                                 struct sec_req_ctx *secreq);

struct provider_handle {
    sec_provider_req_t fn;
    void *context;
};

#define SEC_BASEPATH "/secrets/"

/* providers.c */
int sec_req_routing(TALLOC_CTX *mem_ctx, struct sec_req_ctx *secreq,
                    struct provider_handle **handle);
int sec_provider_recv(struct tevent_req *subreq);

int sec_http_status_reply(TALLOC_CTX *mem_ctx, struct sec_data *reply,
                          enum sec_http_status_codes code);
int sec_http_reply_with_body(TALLOC_CTX *mem_ctx, struct sec_data *reply,
                             enum sec_http_status_codes code,
                             const char *content_type,
                             struct sec_data *body);
enum sec_http_status_codes sec_errno_to_http_status(errno_t err);

int sec_json_to_simple_secret(TALLOC_CTX *mem_ctx,
                              const char *input,
                              char **secret);
int sec_simple_secret_to_json(TALLOC_CTX *mem_ctx,
                              const char *secret,
                              char **output);

int sec_array_to_json(TALLOC_CTX *mem_ctx,
                      char **array, int count,
                      char **output);

#endif /* __SECSRV_PRIVATE_H__ */