das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
credentials.h
Go to the documentation of this file.
1/* Copyright (C) 2017-2023 Chris Piker <chris-piker@uiowa.edu>
2 *
3 * This file is part of das2C, the Core Das2 C Library.
4 *
5 * das2C is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 2.1 as published
7 * by the Free Software Foundation.
8 *
9 * das2C is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _das_credmngr_h_
19#define _das_credmngr_h_
20
21#include <stdio.h>
22
23#include <das3/array.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
50typedef bool (*das_prompt)(
51 const char* sServer, const char* sRealm, const char* sDataset,
52 const char* sMessage, char* sUser, char* sPassword
53);
54
55#define DASCRED_SRV_SZ 128
56#define DASCRED_REALM_SZ 128
57#define DASCRED_DSET_SZ 128
58#define DASCRED_HASH_SZ 256
59
61typedef struct das_credential_t{
62 bool bValid;
63 char sServer[DASCRED_SRV_SZ];
64 char sRealm[DASCRED_REALM_SZ];
65 char sDataset[DASCRED_DSET_SZ];
66 char sHash[DASCRED_HASH_SZ];
68
69
91DAS_API bool das_cred_init(
92 das_credential* pCred, const char* sServer, const char* sRealm,
93 const char* sDataset, const char* sHash
94);
95
96#define DASCMGR_FILE_SZ 128
97#define DASCMGR_MSG_SZ 1024
98
103typedef struct das_credmngr{
104 DasAry* pCreds;
105 das_prompt prompt;
106 char sKeyFile[DASCMGR_FILE_SZ];
107 char sLastAuthMsg[DASCMGR_MSG_SZ];
109
121DAS_API DasCredMngr* new_CredMngr(const char* sKeyStore);
122
129DAS_API void del_CredMngr(DasCredMngr* pThis);
130
145DAS_API int CredMngr_addCred(DasCredMngr* pThis, const das_credential* pCred);
146
147
163 DasCredMngr* pThis, const char* sServer, const char* sRealm,
164 const char* sDataset, bool bValidOnly
165);
166
186 DasCredMngr* pThis, const char* sServer, const char* sRealm,
187 const char* sDataset, const char* sUser, const char* sPass
188);
189
203DAS_API const char* CredMngr_getHttpAuth(
204 DasCredMngr* pThis, const char* sServer, const char* sRealm, const char* sDataset
205);
206
222 DasCredMngr* pThis, const char* sServer, const char* sRealm,
223 const char* sDataset, const char* sMsg
224);
225
226
242
261DAS_API int CredMngr_save(DasCredMngr* pThis, const char* sSymKey, const char* sFile);
262
284DAS_API int CredMngr_load(DasCredMngr* pThis, const char* sSymKey, const char* sFile);
285
286
287#ifdef __cplusplus
288}
289#endif
290
291#endif /* _das_credmngr_h_ */
292
A dynamic buffer with multi-dimensional array style access.
DAS_API int CredMngr_addUserPass(DasCredMngr *pThis, const char *sServer, const char *sRealm, const char *sDataset, const char *sUser, const char *sPass)
Manually add a credential to a credentials manager instead of prompting the user.
DAS_API int CredMngr_addCred(DasCredMngr *pThis, const das_credential *pCred)
Manually add a credential to a credentials manager instead of prompting the user.
DAS_API das_credential * CredMngr_getCred(DasCredMngr *pThis, const char *sServer, const char *sRealm, const char *sDataset, bool bValidOnly)
Get direct memory access to a stored credential.
DAS_API bool das_cred_init(das_credential *pCred, const char *sServer, const char *sRealm, const char *sDataset, const char *sHash)
Initialize a credential to be cached in the credentials manager.
bool(* das_prompt)(const char *sServer, const char *sRealm, const char *sDataset, const char *sMessage, char *sUser, char *sPassword)
Function signature for swapping out the user-prompt for credentials acquisition.
Definition credentials.h:50
Dynamic recursive ragged arrays.
Definition array.h:271
Credentials manager Handles a list of login credentials and supplies these as needed for network oper...
Definition credentials.h:103
DAS_API void del_CredMngr(DasCredMngr *pThis)
Delete a credentials manager free'ing it's internal credential store.
DAS_API const char * CredMngr_getHttpAuth(DasCredMngr *pThis, const char *sServer, const char *sRealm, const char *sDataset)
Retrieve an HTTP basic authentication token for a given dataset on a given server.
DAS_API void CredMngr_authFailed(DasCredMngr *pThis, const char *sServer, const char *sRealm, const char *sDataset, const char *sMsg)
Let the credentials manager know that a particular authorization method failed.
DAS_API int CredMngr_load(DasCredMngr *pThis, const char *sSymKey, const char *sFile)
Merge in credentials from the given filename.
DAS_API int CredMngr_save(DasCredMngr *pThis, const char *sSymKey, const char *sFile)
Save the current credentials to the given filename.
DAS_API DasCredMngr * new_CredMngr(const char *sKeyStore)
Initialize a new credentials manager, optionally from a saved list.
DAS_API das_prompt CredMngr_setPrompt(DasCredMngr *pThis, das_prompt new_prompt)
Change the function used to prompt users for das2 server credentials.
A single credential.
Definition credentials.h:61