libfossil
auth.h
Go to the documentation of this file.
1/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* vim: set ts=2 et sw=2 tw=80: */
3#if !defined(ORG_FOSSIL_SCM_FSL_AUTH_H_INCLUDED)
4#define ORG_FOSSIL_SCM_FSL_AUTH_H_INCLUDED
5/*
6 Copyright 2013-2021 The Libfossil Authors, see LICENSES/BSD-2-Clause.txt
7
8 SPDX-License-Identifier: BSD-2-Clause-FreeBSD
9 SPDX-FileCopyrightText: 2021 The Libfossil Authors
10 SPDX-FileType: Code
11
12 Heavily indebted to the Fossil SCM project (https://fossil-scm.org).
13
14 ******************************************************************************
15 This file declares public APIs for handling fossil
16 authentication-related tasks.
17*/
18
19#include "core.h"
20
21#if defined(__cplusplus)
22extern "C" {
23#endif
24
25/**
26 If f has an opened repository, this function forms a hash from:
27
28 "zProjectCode/zLoginName/zPw"
29
30 (without the quotes)
31
32 where zProjectCode is typically a repository-dependent series of
33 random bytes. If zProjCode is 0 then fsl_repo_project_code() is
34 used to fetch it. (The project code is stored in the repository's
35 config table under the key 'project-code'.)
36
37 The returned string is owned by the caller, who must eventually
38 fsl_free() it.
39
40 All arguments must be non-NULL or behavior is undefined.
41
42 Potential TODO:
43
44 - in fossil(1), this function generates a different result (it
45 returns a copy of zPw) if the project code is not set, under
46 the assumption that this is "the first xfer request of a
47 clone." Whether or not that will apply at this level to
48 libfossil remains to be seen.
49*/
50
51FSL_EXPORT char * fsl_sha1_shared_secret2( fsl_cx * const f, char const * zLoginName,
52 char const * zPw, char const * zProjCode );
53
54/**
55 Equivalent to fsl_sha1_shared_secret2(f,zLoginName,zPw,NULL).
56*/
57FSL_EXPORT char * fsl_sha1_shared_secret( fsl_cx * const f, char const * zLoginName,
58 char const * zPw );
59
60/**
61 Fetches the login group name (if any) for the given context's
62 current repositorty db. If f has no opened repo, 0 is returned.
63
64 If the repo belongs to a login group, its name is returned in the
65 form of a NUL-terminated string. The returned value (which may be
66 0) is owned by the caller, who must eventually fsl_free() it. The
67 value (unlike in fossil(1)) is not cached because it may change
68 via modification of the login group.
69*/
71
72/**
73 Fetches the login cookie name associated with the current repository
74 db, or 0 if no repository is opened.
75
76 The returned (NUL-terminated) string is owned by the caller, who
77 must eventually fsl_free() it. The value is not cached in f because
78 it may change during the lifetime of a repo (if a login group is
79 set or removed).
80
81 The login cookie name is a string in the form "fossil-XXX", where
82 XXX is the first 16 hex digits of either the repo's
83 'login-group-code' or 'project-code' config values (in that order).
84*/
86
87/**
88 Searches for a user ID (from the repo.user.uid DB field) for a given
89 username and password. The password may be either its hashed form or
90 non-hashed form (if it is not exactly 40 bytes long, that is!).
91
92 On success, 0 is returned and *pId holds the ID of the
93 user found (if any). *pId will be set to 0 if no match for the
94 name/password was found, or positive if a match was found.
95
96 If any of the arguments are NULL, FSL_RC_MISUSE is returned. f must
97 have an opened repo, else FSL_RC_NOT_A_REPO is returned.
98
99*/
100FSL_EXPORT int fsl_repo_login_search_uid(fsl_cx * const f, char const * zUsername,
101 char const * zPasswd, fsl_id_t * pId);
102
103/**
104 Clears all login state for the given user ID. If the ID is <=0 then
105 ALL logins are cleared. Has no effect on the built-in pseudo-users.
106
107 Returns non-0 on error, and not finding a matching user ID is not
108 considered an error.
109
110 f must have an opened repo, or FSL_RC_NOT_A_REPO is returned.
111
112 TODO: there are currently no APIs for _setting_ the state this
113 function clears!
114*/
116
117
118#if defined(__cplusplus)
119} /*extern "C"*/
120#endif
121#endif
122/* ORG_FOSSIL_SCM_FSL_AUTH_H_INCLUDED */
FSL_EXPORT char * fsl_repo_login_group_name(fsl_cx *const f)
Fetches the login group name (if any) for the given context's current repositorty db.
FSL_EXPORT char * fsl_sha1_shared_secret(fsl_cx *const f, char const *zLoginName, char const *zPw)
Equivalent to fsl_sha1_shared_secret2(f,zLoginName,zPw,NULL).
FSL_EXPORT char * fsl_repo_login_cookie_name(fsl_cx *const f)
Fetches the login cookie name associated with the current repository db, or 0 if no repository is ope...
FSL_EXPORT int fsl_repo_login_clear(fsl_cx *const f, fsl_id_t userId)
Clears all login state for the given user ID.
FSL_EXPORT int fsl_repo_login_search_uid(fsl_cx *const f, char const *zUsername, char const *zPasswd, fsl_id_t *pId)
Searches for a user ID (from the repo.user.uid DB field) for a given username and password.
FSL_EXPORT char * fsl_sha1_shared_secret2(fsl_cx *const f, char const *zLoginName, char const *zPw, char const *zProjCode)
If f has an opened repository, this function forms a hash from:
int32_t fsl_id_t
fsl_id_t is a signed integer type used to store database record IDs.
Definition config.h:271
#define FSL_EXPORT
Definition config.h:66
This file declares the core SCM-related public APIs.
The main Fossil "context" type.
Definition internal.h:400