File: ArServerUserInfo.h

package info (click to toggle)
libaria 2.8.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,628 kB
  • ctags: 16,574
  • sloc: cpp: 135,490; makefile: 925; python: 597; java: 570; ansic: 182
file content (71 lines) | stat: -rw-r--r-- 2,741 bytes parent folder | download | duplicates (2)
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
#ifndef ARSERVERUSERINFO_H
#define ARSERVERUSERINFO_H

#include "Aria.h"

/// This class holds information about users and loads it from a file
/**
   For a description of the algorithm used to match passwords and keys
   and all look at the documentation for ArServerBase.

   The file format for this class is set up to be easy to make a new
   version of and yet read all the old versions.

   For all of the versions everything after ; or # is ignored.  The
   version information is then the first line of non comments.

   The first version is described as such: The version string is
   '<code>UserInfoVersion1</code>'.  Then there are lines that follow for each user
   which are '<code>user</code> <i>userName password groups</i>'.  The passwords are
   plain text in the file, though they aren't sent that way over the
   network (look at ArServerBase docs for details).  
   To display the groups available use ArServerBase::logCommandGroups().

   There is an example user info file in ArNetworking/examples/serverDemo.userInfo

**/
class ArServerUserInfo
{
public:
  /// Constructor
  AREXPORT ArServerUserInfo(const char *baseDirectory = NULL);
  /// Destructor
  AREXPORT ~ArServerUserInfo();
  /// Loads the file, returns false if it wasn't there
  AREXPORT bool readFile(const char *fileName);
  /// Sets the base directory
  AREXPORT void setBaseDirectory(const char *baseDirectory);
  /// Matchs a user and password, false if user or password is wrong
  AREXPORT bool matchUserPassword(const char *user, unsigned char password[16],
				  const char *passwordKey, 
				  const char *serverKey,
				  bool logFailureVerbosely = false) const;
  AREXPORT bool doNotUse(void) const;
  /// Gets the groups a user is in (returns empty set if no user)
  AREXPORT std::set<std::string, ArStrCaseCmpOp> getUsersGroups(
	  const char *user) const;
  /// Logs the users and groups
  AREXPORT void logUsers(void) const;
protected:
  bool v1HeaderCallback(ArArgumentBuilder * arg);
  bool v1UserCallback(ArArgumentBuilder * arg);
  bool v1DoNotUseCallback(ArArgumentBuilder * arg);
  void removeHandlers(void);
  void logDigest(unsigned char digest[16]) const;

  ArMutex myDataMutex;
  std::map<std::string, std::string, ArStrCaseCmpOp> myPasswords;
  std::map<std::string, std::set<std::string, ArStrCaseCmpOp> *, 
      ArStrCaseCmpOp> myGroups;
  ArRetFunctor1C<bool, ArServerUserInfo, ArArgumentBuilder *> myV1HeaderCB;
  ArRetFunctor1C<bool, ArServerUserInfo, ArArgumentBuilder *> myV1UserCB;
  ArRetFunctor1C<bool, ArServerUserInfo, ArArgumentBuilder *> myV1DoNotUseCB;
  std::string myBaseDirectory;
  ArFileParser myParser;
  bool myGotHeader;
  bool myDoNotUse;
  bool myLogFailureVerbosely;

};

#endif // ARSERVERUSERINFO_H