reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
UserStore.cxx
Go to the documentation of this file.
1
2
3#include "rutil/ResipAssert.h"
4
5#include "rutil/Data.hxx"
10#include "rutil/Logger.hxx"
13
14#include "repro/UserStore.hxx"
15#include "repro/AbstractDb.hxx"
17
18
19using namespace resip;
20using namespace repro;
21using namespace std;
22
23#define RESIPROCATE_SUBSYSTEM Subsystem::REPRO
24
25const resip::Data UserStore::SEPARATOR("@");
26
28{
29}
30
34
36UserStore::getUserInfo( const Key& key ) const
37{
38 return mDb.getUser(key);
39}
40
41Data
43 const resip::Data& realm ) const
44{
45 Key key = buildKey(user, realm);
46 return mDb.getUserAuthInfo( key );
47}
48
49bool
50UserStore::addUser( const Data& username,
51 const Data& domain,
52 const Data& realm,
53 const Data& password,
54 bool applyA1HashToPassword,
55 const Data& fullName,
56 const Data& emailAddress,
57 const Data& passwordHashAlt)
58{
60 rec.user = username;
61 rec.domain = domain;
62 rec.realm = realm;
63 if(applyA1HashToPassword)
64 {
65 rec.passwordHash = Helper::createResipA1HashString(username, realm, password);
66
67 // Some UAs might calculate A1
68 // using user@domain:realm:password
69 // so we store the hash of that permutation too
70 Data userAtDomain = username + Symbols::AT_SIGN + domain;
71 rec.passwordHashAlt = Helper::createResipA1HashString(userAtDomain, realm, password);
72 }
73 else
74 {
75 rec.passwordHash = password;
76 rec.passwordHashAlt = passwordHashAlt;
77 }
78 rec.name = fullName;
79 rec.email = emailAddress;
81
82 return mDb.addUser( buildKey(username,domain), rec);
83}
84
85void
87{
88 mDb.eraseUser( key );
89}
90
91bool
92UserStore::updateUser( const Key& originalKey,
93 const resip::Data& user,
94 const resip::Data& domain,
95 const resip::Data& realm,
96 const resip::Data& password,
97 bool applyA1HashToPassword,
98 const resip::Data& fullName,
99 const resip::Data& emailAddress,
100 const resip::Data& passwordHashAlt)
101{
102 Key newkey = buildKey(user, domain);
103
104 bool ret = addUser(user, domain, realm, password, applyA1HashToPassword, fullName, emailAddress, passwordHashAlt);
105 if ( newkey != originalKey )
106 {
107 eraseUser(originalKey);
108 }
109 return ret;
110}
111
114{
115 return mDb.firstUserKey();
116}
117
120{
121 return mDb.nextUserKey();
122}
123
125UserStore::buildKey( const resip::Data& user, const resip::Data& realm)
126{
127 Data ret = user + Data(SEPARATOR) + realm;
128 return ret;
129}
130
131void
133{
134 ParseBuffer pb(key);
135 const char* start = pb.position();
136 pb.skipToOneOf(SEPARATOR);
137 pb.data(user, start);
138 const char* anchor = pb.skipChar();
139 pb.skipToEnd();
140 pb.data(domain, anchor);
141}
142
143
144/* ====================================================================
145 * The Vovida Software License, Version 1.0
146 *
147 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
148 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
149 *
150 * Redistribution and use in source and binary forms, with or without
151 * modification, are permitted provided that the following conditions
152 * are met:
153 *
154 * 1. Redistributions of source code must retain the above copyright
155 * notice, this list of conditions and the following disclaimer.
156 *
157 * 2. Redistributions in binary form must reproduce the above copyright
158 * notice, this list of conditions and the following disclaimer in
159 * the documentation and/or other materials provided with the
160 * distribution.
161 *
162 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
163 * and "Vovida Open Communication Application Library (VOCAL)" must
164 * not be used to endorse or promote products derived from this
165 * software without prior written permission. For written
166 * permission, please contact vocal@vovida.org.
167 *
168 * 4. Products derived from this software may not be called "VOCAL", nor
169 * may "VOCAL" appear in their name, without prior written
170 * permission of Vovida Networks, Inc.
171 *
172 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
173 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
174 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
175 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
176 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
177 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
178 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
179 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
180 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
181 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
182 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
183 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
184 * DAMAGE.
185 *
186 * ====================================================================
187 *
188 * This software consists of voluntary contributions made by Vovida
189 * Networks, Inc. and many individuals on behalf of Vovida Networks,
190 * Inc. For more information on Vovida Networks, Inc., please see
191 * <http://www.vovida.org/>.
192 *
193 */
virtual Key nextUserKey()
virtual Key firstUserKey()
virtual void eraseUser(const Key &key)
virtual resip::Data getUserAuthInfo(const Key &key) const
virtual bool addUser(const Key &key, const UserRecord &rec)
virtual UserRecord getUser(const Key &key) const
virtual ~UserStore()
Definition UserStore.cxx:31
static Key buildKey(const resip::Data &user, const resip::Data &domain)
static void getUserAndDomainFromKey(const AbstractDb::Key &key, resip::Data &user, resip::Data &domain)
bool addUser(const resip::Data &user, const resip::Data &domain, const resip::Data &realm, const resip::Data &password, bool applyA1HashToPassword, const resip::Data &fullName, const resip::Data &emailAddress, const resip::Data &passwordHashAlt=resip::Data::Empty)
Definition UserStore.cxx:50
UserStore(AbstractDb &db)
Definition UserStore.cxx:27
resip::Data getUserAuthInfo(const resip::Data &user, const resip::Data &realm) const
Definition UserStore.cxx:42
void eraseUser(const Key &key)
Definition UserStore.cxx:86
bool updateUser(const Key &originalKey, const resip::Data &user, const resip::Data &domain, const resip::Data &realm, const resip::Data &password, bool applyA1HashToPassword, const resip::Data &fullName, const resip::Data &emailAddress, const resip::Data &passwordHashAlt=resip::Data::Empty)
Definition UserStore.cxx:92
AbstractDb::UserRecord getUserInfo(const Key &key) const
Definition UserStore.cxx:36
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
static const Data Empty
Constant that represents a zero-length data.
Definition Data.hxx:882
static Data createResipA1HashString(const Data &username, const Data &realm, const Data &password)
Definition Helper.cxx:783
Provides string-parsing functionality with protection from buffer overflow.
CurrentPosition skipToEnd()
CurrentPosition position() const
CurrentPosition skipToOneOf(const char *cs)
CurrentPosition skipChar()
void data(Data &data, const char *start) const
make the passed in data share memory with the buffer (uses Data::Share)
static const char * AT_SIGN
Definition Symbols.hxx:14
This Class is used to implement a primitive form of RPC using loose XML formatting.
dcm! – add UnusedChecking(_enum) below;