1 /*
2  * wzdftpd - a modular and cool ftp server
3  * Copyright (C) 2002-2004  Pierre Chifflier
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18  *
19  * As a special exemption, Pierre Chifflier
20  * and other respective copyright holders give permission to link this program
21  * with OpenSSL, and distribute the resulting executable, without including
22  * the source code for OpenSSL in the source distribution.
23  */
24 
25 #ifndef __WZD_GROUP_H__
26 #define __WZD_GROUP_H__
27 
28 /** @brief Group definition */
29 struct wzd_group_t {
30   gid_t                  gid;
31   u16_t                  backend_id;
32   char                   groupname[HARD_GROUPNAME_LENGTH];
33   char                   tagline[MAX_TAGLINE_LENGTH];
34   wzd_perm_t             groupperms;
35   u32_t                  max_idle_time;
36   unsigned short         num_logins;     /**< number of simultaneous logins allowed */
37   u32_t                  max_ul_speed;
38   u32_t                  max_dl_speed;
39   unsigned int           ratio;
40   struct wzd_ip_list_t * ip_list;
41   char                   defaultpath[WZD_MAX_PATH];
42 };
43 
44 /** \brief Allocate a new empty structure for a group
45  */
46 wzd_group_t * group_allocate(void);
47 
48 /** \brief Initialize members of struct \a group
49  */
50 void group_init_struct(wzd_group_t * group);
51 
52 /** \brief Free memory used by a \a group structure
53  */
54 void group_free(wzd_group_t * group);
55 
56 /** \brief Create a new group, giving default parameters
57  * \return The new group, or NULL. If \a err is provided, set it to
58  * the error code.
59  */
60 wzd_group_t * group_create(const char * groupname, wzd_context_t * context, wzd_config_t * config, int * err);
61 
62 /** \brief Register a group to the main server
63  * \return The gid of the registered group, or -1 on error
64  */
65 gid_t group_register(wzd_group_t * group, u16_t backend_id);
66 
67 /** \brief Update a registered group atomically. Datas are copied,
68  * and old group is freed.
69  * A pointer to the old group is still valid (change is done in-place)
70  * If the gid had changed, the group will be moved
71  * \return 0 if ok
72  */
73 int group_update(gid_t gid, wzd_group_t * new_group);
74 
75 /** \brief Unregister a group to the main server
76  * The \a group struct must be freed using group_free()
77  * \return The unregistered group structure, or NULL on error
78  */
79 wzd_group_t * group_unregister(gid_t gid);
80 
81 /** \brief Free memory used to register groups
82  * \warning Also free ALL registered groups !
83  */
84 void group_free_registry(void);
85 
86 /** \brief Get registered group using the \a gid
87  * \return The group, or NULL
88  */
89 wzd_group_t * group_get_by_id(gid_t gid);
90 
91 /** \brief Get registered group using the \a name
92  * \return The group, or NULL
93  */
94 wzd_group_t * group_get_by_name(const char * groupname);
95 
96 /** \brief Get list or groups register for a specific backend
97  * The returned list is terminated by -1, and must be freed with wzd_free()
98  */
99 gid_t * group_get_list(u16_t backend_id);
100 
101 /** \brief Find the first free gid, starting from \a start
102  */
103 gid_t group_find_free_gid(gid_t start);
104 
105 /** \brief Add an ip to the list of authorized/forbidden ips
106  * \return 0 if ok
107  */
108 int group_ip_add(wzd_group_t * group, const char * ip, int is_authorized);
109 
110 #endif /* __WZD_GROUP_H__ */
111