libfossil
fossil-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(NET_FOSSIL_SCM_FSL_AUTH_H_INCLUDED)
4 #define NET_FOSSIL_SCM_FSL_AUTH_H_INCLUDED
5 /*
6  Copyright (c) 2014 D. Richard Hipp
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the Simplified BSD License (also
10  known as the "2-Clause License" or "FreeBSD License".)
11 
12  This program is distributed in the hope that it will be useful,
13  but without any warranty; without even the implied warranty of
14  merchantability or fitness for a particular purpose.
15 
16  Author contact information:
17  drh@hwaci.com
18  http://www.hwaci.com/drh/
19 
20  ******************************************************************************
21  This file declares public APIs for handling fossil authentication-related
22  tasks.
23 */
24 
25 #include "fossil-core.h"
26 
27 #if defined(__cplusplus)
28 extern "C" {
29 #endif
30 
31 /**
32  If f has an opened repository, this function forms a hash from:
33 
34  "ProjectCode/zLoginName/zPw"
35 
36  (without the quotes)
37 
38  where ProjectCode is a repository-instance-dependent series of
39  random bytes. The returned string is owned by the caller, who
40  must eventually fsl_free() it. The project code is stored in
41  the repository's config table under the key 'project-code', and
42  this routine fetches that key if necessary.
43 
44  Potential TODO:
45 
46  - in fossil(1), this function generates a different result (it
47  returns a copy of zPw) if the project code is not set, under
48  the assumption that this is "the first xfer request of a
49  clone." Whether or not that will apply at this level to
50  libfossil remains to be seen.
51 */
52 FSL_EXPORT char * fsl_sha1_shared_secret( fsl_cx * f, char const * zLoginName, char const * zPw );
53 
54 /**
55  Fetches the login group name (if any) for the given context's
56  current repositorty db. If f has no opened repo, 0 is returned.
57 
58  If the repo belongs to a login group, its name is returned in the
59  form of a NUL-terminated string. The returned value (which may be
60  0) is owned by the caller, who must eventually fsl_free() it. The
61  value (unlike in fossil(1)) is not cached because it may change
62  via modification of the login group.
63 */
65 
66 /**
67  Fetches the login cookie name associated with the current repository
68  db, or 0 if no repository is opened.
69 
70  The returned (NUL-terminated) string is owned by the caller, who
71  must eventually fsl_free() it. The value is not cached in f because
72  it may change during the lifetime of a repo (if a login group is
73  set or removed).
74 
75  The login cookie name is a string in the form "fossil-XXX", where
76  XXX is the first 16 hex digits of either the repo's
77  'login-group-code' or 'project-code' config values (in that order).
78 */
80 
81 /**
82  Searches for a user ID (from the repo.user.uid DB field) for a given
83  username and password. The password may be either its hashed form or
84  non-hashed form (if it is not exactly 40 bytes long, that is!).
85 
86  On success, 0 is returned and *pId holds the ID of the
87  user found (if any). *pId will be set to 0 if no match for the
88  name/password was found, or positive if a match was found.
89 
90  If any of the arguments are NULL, FSL_RC_MISUSE is returned. f must
91  have an opened repo, else FSL_RC_NOT_A_REPO is returned.
92 
93 */
94 FSL_EXPORT int fsl_repo_login_search_uid(fsl_cx * f, char const * zUsername,
95  char const * zPasswd, fsl_id_t * pId);
96 
97 /**
98  Clears all login state for the given user ID. If the ID is <=0 then
99  ALL logins are cleared. Has no effect on the built-in pseudo-users.
100 
101  Returns non-0 on error, and not finding a matching user ID is not
102  considered an error.
103 
104  f must have an opened repo, or FSL_RC_NOT_A_REPO is returned.
105 
106  TODO: there are currently no APIs for _setting_ the state this
107  function clears!
108 */
110 
111 
112 #if defined(__cplusplus)
113 } /*extern "C"*/
114 #endif
115 #endif
116 /* NET_FOSSIL_SCM_FSL_AUTH_H_INCLUDED */
FSL_EXPORT int fsl_repo_login_search_uid(fsl_cx *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...
The main Fossil "context" type.
#define FSL_EXPORT
Definition: fossil-config.h:19
FSL_EXPORT char * fsl_repo_login_group_name(fsl_cx *f)
Fetches the login group name (if any) for the given context's current repositorty db...
fsl_int32_t fsl_id_t
fsl_id_t is a signed integer type used to store database record IDs.
FSL_EXPORT char * fsl_sha1_shared_secret(fsl_cx *f, char const *zLoginName, char const *zPw)
If f has an opened repository, this function forms a hash from:
FSL_EXPORT char * fsl_repo_login_cookie_name(fsl_cx *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 *f, fsl_id_t userId)
Clears all login state for the given user ID.