1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 #ifndef CCNET_USER_MGR_H
4 #define CCNET_USER_MGR_H
5 
6 #include <glib.h>
7 #include <glib-object.h>
8 
9 #define CCNET_TYPE_USER_MANAGER                  (ccnet_user_manager_get_type ())
10 #define CCNET_USER_MANAGER(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), CCNET_TYPE_USER_MANAGER, CcnetUserManager))
11 #define CCNET_IS_USER_MANAGER(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CCNET_TYPE_USER_MANAGER))
12 #define CCNET_USER_MANAGER_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), CCNET_TYPE_USER_MANAGER, CcnetUserManagerClass))
13 #define CCNET_IS_USER_MANAGER_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), CCNET_TYPE_USER_MANAGER))
14 #define CCNET_USER_MANAGER_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), CCNET_TYPE_USER_MANAGER, CcnetUserManagerClass))
15 
16 
17 typedef struct _SeafileSession SeafileSession;
18 typedef struct _CcnetUserManager CcnetUserManager;
19 typedef struct _CcnetUserManagerClass CcnetUserManagerClass;
20 
21 typedef struct CcnetUserManagerPriv CcnetUserManagerPriv;
22 
23 
24 struct _CcnetUserManager
25 {
26     GObject         parent_instance;
27 
28     SeafileSession   *session;
29 
30     char           *userdb_path;
31     GHashTable     *user_hash;
32 
33 #ifdef HAVE_LDAP
34     /* LDAP related */
35     gboolean        use_ldap;
36     char           *ldap_host;
37 #ifdef WIN32
38     gboolean        use_ssl;
39 #endif
40     char           **base_list;  /* base DN from where all users can be reached */
41     char           *filter;     /* Additional search filter */
42     char           *user_dn;    /* DN of the admin user */
43     char           *password;   /* password for admin user */
44     char           *login_attr;  /* attribute name used for login */
45     gboolean        follow_referrals; /* Follow referrals returned by the server. */
46 #endif
47 
48     int passwd_hash_iter;
49 
50     CcnetUserManagerPriv *priv;
51 };
52 
53 struct _CcnetUserManagerClass
54 {
55     GObjectClass    parent_class;
56 };
57 
58 GType ccnet_user_manager_get_type  (void);
59 
60 CcnetUserManager* ccnet_user_manager_new (SeafileSession *);
61 int ccnet_user_manager_prepare (CcnetUserManager *manager);
62 
63 void ccnet_user_manager_free (CcnetUserManager *manager);
64 
65 void ccnet_user_manager_start (CcnetUserManager *manager);
66 
67 void
68 ccnet_user_manager_set_max_users (CcnetUserManager *manager, gint64 max_users);
69 
70 int
71 ccnet_user_manager_add_emailuser (CcnetUserManager *manager,
72                                   const char *email,
73                                   const char *encry_passwd,
74                                   int is_staff, int is_active);
75 
76 int
77 ccnet_user_manager_remove_emailuser (CcnetUserManager *manager,
78                                      const char *source,
79                                      const char *email);
80 
81 int
82 ccnet_user_manager_validate_emailuser (CcnetUserManager *manager,
83                                        const char *email,
84                                        const char *passwd);
85 
86 CcnetEmailUser*
87 ccnet_user_manager_get_emailuser (CcnetUserManager *manager, const char *email);
88 
89 CcnetEmailUser*
90 ccnet_user_manager_get_emailuser_with_import (CcnetUserManager *manager,
91                                               const char *email);
92 CcnetEmailUser*
93 ccnet_user_manager_get_emailuser_by_id (CcnetUserManager *manager, int id);
94 
95 /*
96  * @source: "DB" or "LDAP".
97  * @status: "", "active", or "inactive". returns all users when this argument is "".
98  */
99 GList*
100 ccnet_user_manager_get_emailusers (CcnetUserManager *manager,
101                                    const char *source,
102                                    int start, int limit,
103                                    const char *status);
104 
105 GList*
106 ccnet_user_manager_search_emailusers (CcnetUserManager *manager,
107                                       const char *source,
108                                       const char *keyword,
109                                       int start, int limit);
110 
111 GList*
112 ccnet_user_manager_search_ldapusers (CcnetUserManager *manager,
113                                      const char *keyword,
114                                      int start, int limit);
115 
116 gint64
117 ccnet_user_manager_count_emailusers (CcnetUserManager *manager, const char *source);
118 
119 gint64
120 ccnet_user_manager_count_inactive_emailusers (CcnetUserManager *manager, const char *source);
121 
122 GList*
123 ccnet_user_manager_filter_emailusers_by_emails(CcnetUserManager *manager,
124                                                const char *emails);
125 
126 int
127 ccnet_user_manager_update_emailuser (CcnetUserManager *manager,
128                                      const char *source,
129                                      int id, const char* passwd,
130                                      int is_staff, int is_active);
131 
132 int
133 ccnet_user_manager_update_role_emailuser (CcnetUserManager *manager,
134                                      const char* email, const char* role);
135 
136 GList*
137 ccnet_user_manager_get_superusers(CcnetUserManager *manager);
138 
139 int
140 ccnet_user_manager_add_binding (CcnetUserManager *manager, const char *email,
141                                 const char *peer_id);
142 
143 /* Remove all bindings to an email */
144 int
145 ccnet_user_manager_remove_binding (CcnetUserManager *manager, const char *email);
146 
147 /* Remove one specific peer-id binding to an email */
148 int
149 ccnet_user_manager_remove_one_binding (CcnetUserManager *manager,
150                                        const char *email,
151                                        const char *peer_id);
152 
153 char *
154 ccnet_user_manager_get_binding_email (CcnetUserManager *manager, const char *peer_id);
155 
156 GList *
157 ccnet_user_manager_get_binding_peerids (CcnetUserManager *manager, const char *email);
158 
159 int
160 ccnet_user_manager_set_reference_id (CcnetUserManager *manager,
161                                      const char *primary_id,
162                                      const char *reference_id,
163                                      GError **error);
164 
165 char *
166 ccnet_user_manager_get_primary_id (CcnetUserManager *manager,
167                                    const char *email);
168 
169 char *
170 ccnet_user_manager_get_login_id (CcnetUserManager *manager,
171                                  const char *primary_id);
172 
173 GList *
174 ccnet_user_manager_get_emailusers_in_list (CcnetUserManager *manager,
175                                            const char *source,
176                                            const char *user_list,
177                                            GError **error);
178 
179 int
180 ccnet_user_manager_update_emailuser_id (CcnetUserManager *manager,
181                                         const char *old_email,
182                                         const char *new_email,
183                                         GError **error);
184 #endif
185