~ubuntu-branches/ubuntu/hardy/steam/hardy

« back to all changes in this revision

Viewing changes to server/factories/UserFactory.pike

  • Committer: Bazaar Package Importer
  • Author(s): Alain Schroeder
  • Date: 2006-11-21 16:03:12 UTC
  • mfrom: (2.1.4 feisty)
  • Revision ID: james.westby@ubuntu.com-20061121160312-nf96y6nihzsyd2uv
Tags: 2.2.31-3
Add patch to prevent inconsistent data after shutdown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000-2004  Thomas Bopp, Thorsten Hampel, Ludger Merkens
 
1
/* Copyright (C) 2000-2006  Thomas Bopp, Thorsten Hampel, Ludger Merkens
2
2
 *
3
3
 *  This program is free software; you can redistribute it and/or modify
4
4
 *  it under the terms of the GNU General Public License as published by
14
14
 *  along with this program; if not, write to the Free Software
15
15
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
16
 * 
17
 
 * $Id: UserFactory.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $
 
17
 * $Id: UserFactory.pike,v 1.4 2006/08/10 08:08:50 astra Exp $
18
18
 */
19
19
 
20
 
constant cvs_version="$Id: UserFactory.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $";
 
20
constant cvs_version="$Id: UserFactory.pike,v 1.4 2006/08/10 08:08:50 astra Exp $";
21
21
 
22
22
inherit "/factories/ContainerFactory";
23
23
 
75
75
                         0, EVENT_ATTRIBUTES_CHANGE, 0,
76
76
                         CONTROL_ATTR_USER, ({ }) );
77
77
    init_class_attribute(USER_CALENDAR, CMD_TYPE_OBJECT, "calendar", 0,
78
 
                         EVENT_ATTRIBUTES_CHANGE, 0, CONTROL_ATTR_USER,0);
 
78
                         EVENT_ATTRIBUTES_CHANGE, 0, CONTROL_ATTR_SERVER,0);
 
79
    init_class_attribute(USER_MONITOR, CMD_TYPE_OBJECT, "monitor", 0,
 
80
                         EVENT_ATTRIBUTES_CHANGE, 0, CONTROL_ATTR_SERVER,0);
 
81
    init_class_attribute(USER_ID, CMD_TYPE_STRING, "user id",
 
82
                         EVENT_ATTRIBUTES_QUERY,
 
83
                         EVENT_ATTRIBUTES_CHANGE, 
 
84
                         0,CONTROL_ATTR_USER, "");
79
85
}
80
86
 
81
87
/**
93
99
 */
94
100
object execute(mapping vars)
95
101
{
 
102
   string name;
 
103
   object  obj;
 
104
 
 
105
   if ( stringp(vars["nickname"]) )
 
106
       name = lower_case(vars["nickname"]);
 
107
   else
 
108
       name = vars["name"];
 
109
   
 
110
   obj = MODULE_USERS->lookup(name);
 
111
   if ( objectp(obj) ) 
 
112
       steam_error("user_create(): User does already exist.");
 
113
   obj = MODULE_GROUPS->lookup(name);
 
114
   if ( objectp(obj) ) 
 
115
       steam_error("user_create(): Group with this name already exist.");
 
116
 
 
117
   mixed err = catch {
 
118
       object ouid = seteuid(USER("root"));
 
119
       obj = user_create(vars);
 
120
       seteuid(ouid);
 
121
   };
 
122
   if ( err ) {
 
123
       // try to find the user and remove
 
124
       obj = MODULE_USERS->lookup(name);
 
125
       if ( objectp(obj) ) {
 
126
           obj->delete();
 
127
       }
 
128
       throw(err);
 
129
   }
 
130
   return obj;
 
131
}
 
132
 
 
133
private static object user_create(mapping vars)
 
134
{
96
135
    int       i;
97
136
    object  obj;
98
137
 
116
155
    if ( stringp(vars->firstname) && !xml.utf8_check(vars->firstname) )
117
156
      steam_error("Failed utf8-check for firstname or fullname !");
118
157
 
119
 
    obj = MODULE_USERS->lookup(name);
120
 
    if ( objectp(obj) ) 
121
 
        steam_error("user_create(): User does already exist.");
122
 
    obj = MODULE_GROUPS->lookup(name);
123
 
    if ( objectp(obj) ) {
124
 
        SECURITY_LOG("user_create(): Group with this name already exist.");
125
 
        return null;
126
 
    }
127
158
    obj = object_create(name, CLASS_NAME_USER, 0, vars["attributes"],
128
159
                vars["attributesAcquired"], vars["attributesLocked"]); 
129
160
    obj->lock_attribute(OBJ_NAME);
144
175
    if (stringp(language)) obj->set_attribute(USER_LANGUAGE, language);
145
176
    obj->set_creator(_ROOT);
146
177
    obj->set_acquire(0);
 
178
    if ( objectp(this_user()) && this_user() != _GUEST )
 
179
      obj->sanction_object(this_user(), SANCTION_ALL);
147
180
 
148
181
    if ( stringp(vars["description"]) )
149
182
        obj->set_attribute(OBJ_DESC, vars["description"]);
180
213
    trashbin->sanction_object_meta(obj->this(), SANCTION_ALL);
181
214
    trashbin->sanction_object(_STEAMUSER, SANCTION_INSERT);
182
215
    trashbin->set_acquire(0); 
183
 
    
 
216
     
184
217
    obj->set_attribute(USER_TRASHBIN, trashbin);
185
218
 
186
219
    calendar = _Server->get_factory(CLASS_CALENDAR)->execute((["name":name+"'s calendar"]) );
187
220
    obj->set_attribute(USER_CALENDAR, calendar);
188
221
    obj->lock_attribute(USER_CALENDAR);
189
222
    calendar->set_creator(obj->this());
 
223
    calendar->sanction_object(obj->this(), SANCTION_ALL);
 
224
    calendar->sanction_object_meta(obj->this(), SANCTION_ALL);
190
225
    calendar->set_attribute(CALENDAR_OWNER, obj->this());
191
226
    calendar->lock_attribute(CALENDAR_OWNER);
192
227
 
223
258
    }
224
259
    iActivation = time() + random(100000);
225
260
    obj->set_activation(iActivation);
 
261
 
226
262
    return obj->this();
227
263
}
228
264