conference.c 36.8 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: conference.c,v 0.89 2003/08/20 08:26:02 ceder Exp $
3
 * Copyright (C) 1991-2002  Lysator Academic Computer Association.
Linus Tolke's avatar
Linus Tolke committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 *
 * This file is part of the LysKOM server.
 * 
 * LysKOM is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation; either version 1, or (at your option) 
 * any later version.
 * 
 * LysKOM is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with LysKOM; see the file COPYING.  If not, write to
 * Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
 * or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
 * MA 02139, USA.
 *
Per Cederqvist's avatar
Per Cederqvist committed
23
 * Please report bugs at http://bugzilla.lysator.liu.se/. 
Linus Tolke's avatar
Linus Tolke committed
24
 */
Per Cederqvist's avatar
Per Cederqvist committed
25
26
27
28
29
30
/*
 * conference.c
 *
 * All atomic calls that deals with conferences.
 */

David Byers's avatar
David Byers committed
31
32
33
34
35

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

Per Cederqvist's avatar
Per Cederqvist committed
36
#include <ctype.h>
Per Cederqvist's avatar
Per Cederqvist committed
37
#include <stdio.h>
38
#include "timewrap.h"
Per Cederqvist's avatar
Per Cederqvist committed
39
#include <setjmp.h>
40
#include <sys/types.h>
Per Cederqvist's avatar
Per Cederqvist committed
41

42
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
43
#include "kom-types.h"
Per Cederqvist's avatar
Per Cederqvist committed
44
#include "log.h"
Per Cederqvist's avatar
Per Cederqvist committed
45
46
47
48
49
#include "services.h"
#include "s-string.h"
#include "cache.h"
#include "misc-types.h"
#include "s-collat-tabs.h"
David Byers's avatar
Server    
David Byers committed
50
51
52
#include "com.h"
#include "async.h"
#include "connections.h"
53
#include "kom-errno.h"
Per Cederqvist's avatar
Per Cederqvist committed
54
55
#include "manipulate.h"
#include "server/smalloc.h"
David Byers's avatar
David Byers committed
56
#include "kom-config.h"
Per Cederqvist's avatar
Per Cederqvist committed
57
#include "parser.h"
Per Cederqvist's avatar
Per Cederqvist committed
58
#include "internal-connections.h"
Per Cederqvist's avatar
Per Cederqvist committed
59
60
61
#include "lyskomd.h"
#include "debug.h"
#include "send-async.h"
62
#include "param.h"
63
#include "aux-items.h"
64
#include "local-to-global.h"
65
#include "server-time.h"
66
#include "stats.h"
67

David Byers's avatar
David Byers committed
68
69
BUGDECL;

Per Cederqvist's avatar
Per Cederqvist committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Static functions
 */

/*
 * Delete a conference. Delete all references to this conf.
 */

static void
do_delete_conf (Conf_no      conf_no,
		Conference * conf_c) /* Not NULL */
{
    int i;
    
    if ( do_set_presentation(conf_no, conf_c, 0) != OK )
    {
David Byers's avatar
David Byers committed
86
	kom_log("ERROR: do_delete_conf() - couldn't unmark presentation.\n");
Per Cederqvist's avatar
Per Cederqvist committed
87
88
89
90
    }
    
    if ( do_set_etc_motd(conf_no, conf_c, 0) != OK )
    {
David Byers's avatar
David Byers committed
91
	kom_log("ERROR: do_delete_conf() - couldn't unmark motd.\n");
Per Cederqvist's avatar
Per Cederqvist committed
92
93
94
95
96
97
98
99
100
101
102
103
104
    }

    /* Delete all members */
    /* Note that because of the way do_sub_member is written it is important */
    /* that the loop is executed this way. */
    for ( i = conf_c->members.no_of_members - 1; i >= 0; i-- )
    {
	do_sub_member( conf_no, conf_c, conf_c->members.members + i,
		      conf_c->members.members[ i ].member, NULL, NULL);
    }

    sfree( conf_c->members.members );
    conf_c->members.members = NULL;
David Byers's avatar
David Byers committed
105

Per Cederqvist's avatar
Per Cederqvist committed
106
107
108
109
110
111
112
    /* texts */

    /*
     * The texts are not deleted at once, but since they now have no recipient
     * they will not live long.
     */

113
114
115
116
117
118
119
    /*
     * Note that there will still be a recipient in the texts, but it
     * will not exist in reality.  This is maybe unfortunate, but
     * there might be thousands of texts in the conference, and we
     * cannot modify all those text statuses in a single atomic call.
     */

120
    /* FIXME (bug 905): There should be an async message about the deletion. */
Per Cederqvist's avatar
Per Cederqvist committed
121
122

    cached_delete_conf( conf_no );
123
    update_stat(STAT_CONFS, -1);
Per Cederqvist's avatar
Per Cederqvist committed
124
125
126
127
128
129
130
131
    
    return;
}

/*
 * Functions that are exported to the server.
 */

132
133
134
135
136
137
void
set_conf_errno(const Connection *viewer_conn,
	       Conf_no conf_no,
	       enum kom_err errcode)
{
    err_stat = conf_no;
138
    if (!has_access(conf_no, viewer_conn, read_protected))
139
140
141
142
143
144
	kom_errno = KOM_UNDEF_CONF;
    else
	kom_errno = errcode;
}


Per Cederqvist's avatar
Per Cederqvist committed
145
/*
146
147
 * Return TRUE if NAME is not already used. Set kom_errno to
 * KOM_LONG_STR or KOM_BAD_NAME if it fails.
Per Cederqvist's avatar
Per Cederqvist committed
148
149
150
151
152
 */

Bool
legal_name( String name )
{
153
    if (name.len == 0 || name.len > param.conf_name_len )
Per Cederqvist's avatar
Per Cederqvist committed
154
    {
David Byers's avatar
David Byers committed
155
156
        err_stat = name.len?  param.conf_name_len : 0;
	kom_errno = name.len? KOM_LONG_STR        : KOM_BAD_NAME;
Per Cederqvist's avatar
Per Cederqvist committed
157
158
159
160
161
	return FALSE;
    }

    while( name.len-- )
    {
162
163
164
165
166
#ifdef HAVE_LOCALE_H
	if (param.force_iso_8859_1
	    ? (*name.string < ' ' ||
	       (*name.string > 126 && *name.string < ' ' + 128))
	    : !isprint(*name.string))
Per Cederqvist's avatar
Per Cederqvist committed
167
	{
168
            err_stat = 0;
169
	    kom_errno = KOM_BAD_NAME;
Per Cederqvist's avatar
Per Cederqvist committed
170
171
	    return FALSE;
	}
172
173
174
175
#else
	if (*name.string < ' ' ||
	    (*name.string > 126 && *name.string < ' ' + 128))
	{
176
            err_stat = 0;
177
178
179
180
	    kom_errno = KOM_BAD_NAME;
	    return FALSE;
	}
#endif
Per Cederqvist's avatar
Per Cederqvist committed
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
	name.string++;
    }

    return TRUE;
}

/*
 * Return TRUE if name is unique, or if the only match is conf_no. Use 0
 * as conf_no if it should not be allowed to be changed.
 */
Bool
unique_name( const String name, Conf_no conf_no )
{
    Parse_info   parse_info;
    Parse_token *name_token;
    Parse_token *existing_token;
    Bool	 exact_match_found;
    Bool	 diff_found;
    int i;
    int n;
        
    parse_info = parse(name, match_table, FALSE, TRUE,
203
204
		       s_fcrea_str(WHITESPACE),
		       DEFAULT_COLLAT_TAB);
Per Cederqvist's avatar
Per Cederqvist committed
205
206
207
208
209
210
211
212
213

    if ( parse_info.no_of_matches == 0 ) /* Doesn't match any name. */
    {
	sfree(parse_info.indexes);
	return TRUE;
    }

    if ( parse_info.no_of_matches == -1 ) /* Error. */
    {
David Byers's avatar
David Byers committed
214
	kom_log("unique_name(): parse returned error.\n");
Per Cederqvist's avatar
Per Cederqvist committed
215
216
217
218
219
220
221
222
223
224
225
226
227
	sfree(parse_info.indexes);
	return FALSE;
    }
    
    if ( parse_info.no_of_matches == 1 && parse_info.indexes[ 0 ] == -1 )
    {
	/* Empty name is not allowed. */
	sfree(parse_info.indexes);
	return FALSE;
    }
    
    /* The name matches some conference. Check if they are equal. */

228
    name_token = tokenize(name, s_fcrea_str(WHITESPACE));
Per Cederqvist's avatar
Per Cederqvist committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256

    exact_match_found = FALSE;
    
    for ( i = 0; !exact_match_found && i < parse_info.no_of_matches; i++ )
    {
	existing_token = match_table[ parse_info.indexes[ i ] ].tokens;
	diff_found = FALSE;
	
	for ( n = 0;
	     (!diff_found && !s_empty(existing_token[ n ].word)
	      && !s_empty(name_token[ n ].word));
	     ++n)
	{
	    if ( !s_usr_streq(existing_token[ n ].word,
			      name_token[ n ].word,
			      DEFAULT_COLLAT_TAB) )
	    {
		diff_found = TRUE;
	    }
	}

	if (! s_empty(existing_token[ n ].word)
	    || ! s_empty(name_token[ n ].word) )
	{
	    /* The length (number of words) differed. */
	    diff_found = TRUE;
	}

David Byers's avatar
Server:    
David Byers committed
257
	if ( !diff_found && match_table[ parse_info.indexes[ i ] ].conf_no != conf_no )
Per Cederqvist's avatar
Per Cederqvist committed
258
259
260
261
262
263
264
265
266
267
268
	    exact_match_found = TRUE;
    }
	    
    sfree(parse_info.indexes);
    free_tokens(name_token);
    return exact_match_found ? FALSE : TRUE;		
}

/*
 * Create a conference.
 */
Per Cederqvist's avatar
Per Cederqvist committed
269
static Conf_no
Per Cederqvist's avatar
Per Cederqvist committed
270
271
272
273
do_create_conf(String	 name,
	       Pers_no	 creator,
	       Conf_no	 supervisor,
	       Conf_no	 super_conf,
274
	       Conf_type type,
275
	       Connection *creating_connection,
276
               Aux_item_list *aux)
Per Cederqvist's avatar
Per Cederqvist committed
277
278
279
280
{
    Conf_no 	 conf_no;
    Conference * conf_c;
    
281
282
    /* Prepare, then check the aux items */

Per Cederqvist's avatar
Per Cederqvist committed
283
284
285
    /* Allocate memory for conf_c */

    conf_no = cached_create_conf( name );
David Byers's avatar
David Byers committed
286
287
288
    if (conf_no == 0)
    {
        /* kom_errno and err_stat set in cached_create_conf */
289
        kom_log("ERROR: Couldn't create conference. Too many conferences.\n");
David Byers's avatar
David Byers committed
290
291
        return 0;
    }
Per Cederqvist's avatar
Per Cederqvist committed
292
293
294

    if ( (conf_c = cached_get_conf_stat( conf_no ) ) == NULL)
    {
295
	restart_kom("create_conf() - can't get conf_stat\n");
Per Cederqvist's avatar
Per Cederqvist committed
296
297
298
    }

    conf_c->creator	= creator;
299
    conf_c->creation_time = current_time.tv_sec;
Per Cederqvist's avatar
Per Cederqvist committed
300
301
302
303
304
305
306
    conf_c->presentation= 0;		/* No presentation yet */
    conf_c->supervisor	= supervisor;
    conf_c->permitted_submitters = 0;
    conf_c->super_conf	= super_conf;
    conf_c->type	= type;
    conf_c->last_written= conf_c->creation_time;
    conf_c->msg_of_day	= 0;
307
    conf_c->nice	= param.default_nice;
308
    conf_c->keep_commented = param.default_keep_commented;
309
    conf_c->highest_aux = 0;
310
    conf_c->expire      = 0;
311

312
313
314
315
    /* Update small_conf_arr before conf_stat_check_add_aux_item_list
       uses it to check that the user is allowed to add the aux-items. */
    mark_conference_as_changed (conf_no);

316
    prepare_aux_item_list(aux, creator);
317
318
319
    if (conf_stat_check_add_aux_item_list(conf_c,
                                          conf_no,
                                          aux,
320
                                          creating_connection,
321
                                          TRUE) != OK)
322
    {
323
	/* FIXME (bug 146): Conf_no leak: We create a conference, check the
324
325
326
327
	   aux-items, determine that the aux-items are bogus, and
	   immediately delete the conference.  This leaks a conference
	   number.  We can live with that, but it isn't pretty.  */

328
329
330
331
332
        cached_delete_conf(conf_no);
        return 0;
    }

    conf_stat_add_aux_item_list(conf_c, conf_no, aux, creator);
Per Cederqvist's avatar
Per Cederqvist committed
333

334
    mark_conference_as_changed (conf_no);
335
    update_stat(STAT_CONFS, 1);
Per Cederqvist's avatar
Per Cederqvist committed
336
337
338
339
340
341

    return conf_no;
}


/*
342
 * Return TRUE if viewer is a supervisor to CONF.
Per Cederqvist's avatar
Per Cederqvist committed
343
344
 */

345
Bool
346
347
348
is_supervisor_2(Conf_no conf,
		Pers_no viewer,
		const Person *viewer_p)
Per Cederqvist's avatar
Per Cederqvist committed
349
{
350
    if (viewer == conf)	/* A person is ALWAYS supervisor to	*/
351
        return TRUE;		/* his/her own mailbox!		*/
Per Cederqvist's avatar
Per Cederqvist committed
352

353
    return is_strictly_supervisor(conf, viewer, viewer_p);
354
355
}

356
357
358
359
360
361
362
363
364
365
366
367
368
369
Bool
is_supervisor(Conf_no conf,
	      const Connection *viewer)
{
    if (viewer->pers_no == 0)
	return FALSE;

    /* A person is ALWAYS supervisor to his/her own mailbox!  */
    if (viewer->pers_no == conf)
        return TRUE;

    return is_strictly_supervisor(conf, viewer->pers_no, viewer->person);
}

370
371

Bool
372
373
374
is_strictly_supervisor(Conf_no       conf,
                       Pers_no       viewer,
                       const Person *viewer_p) /* May be NULL */
375
{
376
377
    Conf_no supervisor;

378
379
    if (viewer == 0)		/* Not yet logged in. */
	return FALSE;
Per Cederqvist's avatar
Per Cederqvist committed
380

381
382
383
384
    if (!cached_conf_exists(conf))
	return FALSE;

    if ((supervisor = cached_get_conf_supervisor(conf)) == 0)
Per Cederqvist's avatar
Per Cederqvist committed
385
386
        return FALSE;
	
387
    if (viewer == supervisor)
Per Cederqvist's avatar
Per Cederqvist committed
388
389
        return TRUE;

390
    if (viewer_p == NULL)
391
392
	GET_P_STAT(viewer_p, viewer, FALSE);

393
    if (locate_membership(supervisor, viewer_p) != NULL)
Per Cederqvist's avatar
Per Cederqvist committed
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
	return TRUE;
    
    return FALSE;
}


/*
 * Atomic functions
 */

/*
 * Change name of a person or conference. You must be supervisor
 * of the conference to use this call.
 */
extern Success
409
410
change_name (Conf_no	   conf_no,
	     const String  new_name)
Per Cederqvist's avatar
Per Cederqvist committed
411
412
{
    Conference * conf_c;
413
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
414

David Byers's avatar
Server    
David Byers committed
415
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
416
417
418
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

419
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
420
421
422

    if ( acc <= none )
    {
423
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
424
425
426
427
428
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    }

    if ( !ACT_P->privileges.change_name
David Byers's avatar
Server    
David Byers committed
429
	|| (acc != unlimited && !ENA(admin, 3))) /* OK -- In an RPC call */
Per Cederqvist's avatar
Per Cederqvist committed
430
    {
431
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
432
433
434
435
436
437
	kom_errno = KOM_PERM;
	return FAILURE;
    }

    if ( !legal_name( new_name ) )
    {
438
	/* kom_errno will be set by legal_name(). */
Per Cederqvist's avatar
Per Cederqvist committed
439
440
441
442
443
	return FAILURE;
    }

    if ( !unique_name( new_name, conf_no ) )
    {
444
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
	kom_errno = KOM_CONF_EXISTS;
	return FAILURE;
    }

    async_new_name(conf_no, conf_c->name, new_name);

    s_strcpy(&conf_c->name, new_name);
    mark_conference_as_changed(conf_no);

    cached_change_name(conf_no, new_name);

    return OK;
}

/*
 * Create a conference: Default modes:
 *	ACTPERS becomes supervisor and super_conf.
 *	Anyone can submitt texts.
 *	Noone (not even the creator) is a member in the conf.
 *
 * If ANYONE_CAN_CREATE_NEW_CONFS (#defined in config.h) is not true
 * you must have the 'create_conf' capability.
 *
 * It is currently not allowed to have a conference that is secret
 * and not rd_prot. This restriction might be lifted in the future
 * (but I don't understand the use of such a conference...)
 */

473
474
475
476
static Conf_no
create_conf_generic(const String  name,
                    Conf_type	  type,
                    Aux_item_list *aux)
Per Cederqvist's avatar
Per Cederqvist committed
477
478
479
{
    Conf_no	 conf_no;
    
David Byers's avatar
Server    
David Byers committed
480
    CHK_CONNECTION(0);
Per Cederqvist's avatar
Per Cederqvist committed
481
482
    CHK_LOGIN(0);

483
    if (param.anyone_can_create_new_confs == FALSE
David Byers's avatar
Server    
David Byers committed
484
	&& !HAVE_PRIV(ACT_P, create_conf))
Per Cederqvist's avatar
Per Cederqvist committed
485
    {
486
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
487
488
489
490
491
492
	kom_errno = KOM_PERM;
	return 0;
    }

    if ( !legal_name( name ) )
    {
493
	/* kom_errno will be set by legal_name(). */
Per Cederqvist's avatar
Per Cederqvist committed
494
495
496
497
498
	return 0;
    }

    if ( !unique_name( name, 0 ) )
    {
499
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
500
501
502
503
504
505
506
507
508
509
510
511
	kom_errno = KOM_CONF_EXISTS;
	return 0;
    }

    if ( type.letter_box )	/* A letter_box can only be created via */
    {				/* create_person.			*/
	kom_errno = KOM_PERM;
	return 0;
    }

    if ( type.secret && !type.rd_prot )
    {
512
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
513
514
515
516
	kom_errno = KOM_SECRET_PUBLIC;
	return 0;
    }
    
517
518
    conf_no = do_create_conf(name, ACTPERS, ACTPERS, ACTPERS, type,
			     active_connection, aux);
Per Cederqvist's avatar
Per Cederqvist committed
519
520
521
522
523
524
525
526
527
528

    if ( conf_no != 0)
    {
	ACT_P->created_confs++;
	mark_person_as_changed( ACTPERS );
    }
    
    return conf_no;
}

529
530
531
532
Conf_no
create_conf_old(const String name,
                Conf_type    type)
{
David Byers's avatar
Server    
David Byers committed
533
    /* CHK_CONNECTION in create_conf_generic */
534
535
536
537
538
539
540
541
542
543
    return create_conf_generic(name, type, NULL);
}

Conf_no
create_conf(const String name,
            Conf_type    type,
            Aux_item_list *aux)
{
    Conf_no     conf;

David Byers's avatar
Server    
David Byers committed
544
    /* CHK_CONNECTION in create_conf_generic */
545
546
547
548
549
550
551
552
553
554
555
    conf = create_conf_generic(name, type, aux);
    if (conf != 0)
    {
        /* Send message no. 2 */
    }

    return conf;
}



Per Cederqvist's avatar
Per Cederqvist committed
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
/*
 * Log out a person from any connection he might be logged on to.
 */
static void
logout_person(Pers_no pers_no)
{
    Session_no i = 0;
    Connection *real_active_connection;

    real_active_connection = active_connection;

    while ( (i = traverse_connections(i)) != 0)
    {
	active_connection = get_conn_by_number(i);

	if ( active_connection->pers_no == pers_no )
	    logout();
    }

    active_connection = real_active_connection;
}

/*
 * Delete a conference or person. You must be supervisor of the
 * conference to be allowed to delete it.
 */
extern Success
delete_conf (Conf_no	conf_no )
{
    Conference	   * conf_c;
586
    enum access	     acc;
Per Cederqvist's avatar
Per Cederqvist committed
587
    
David Byers's avatar
Server    
David Byers committed
588
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
589
590
591
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

592
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
593
594
595
    
    if ( acc != unlimited )
    {
596
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
597
598
599
600
601
602
	kom_errno = (acc <= none) ? KOM_UNDEF_CONF : KOM_PERM ;
	return FAILURE;
    }

    if ( conf_c->type.letter_box )
    {
603
604
605
	/* Make sure the person that is deleted is not logged in. */

	logout_person (conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
606

607
	if ( do_delete_pers (conf_no) != OK )
Per Cederqvist's avatar
Per Cederqvist committed
608
	{
David Byers's avatar
David Byers committed
609
	    kom_log("ERROR: delete_conf(): can't delete person.\n");
Per Cederqvist's avatar
Per Cederqvist committed
610
611
612
	}
    }

613
    do_delete_conf (conf_no, conf_c);
Per Cederqvist's avatar
Per Cederqvist committed
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630

    return OK;
}

/*
 * Map conference name to number. Can be done without logging in.
 * Secret conferences will not be returned unless ACTPERS is supervisor
 * of, or member in, that conference.
 */
extern Success
lookup_name (const String    name,
	     Conf_list_old * result)
{
    Conf_no	* no, * no_copy;
    Conf_type   * type, *type_copy;
    int		i;
    
David Byers's avatar
Server    
David Byers committed
631
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
632
633
634
635
636
637
638
639
    if ( cached_lookup_name( name, result ) != OK )
	return FAILURE;

    no = no_copy = result->conf_nos;
    type = type_copy = result->type_of_conf;

    for ( i = result->no_of_conf_nos; i > 0; i-- )
    {
640
	if (!has_access(*no, active_connection, read_protected))
Per Cederqvist's avatar
Per Cederqvist committed
641
642
643
644
645
646
647
648
649
650
651
652
653
	    --result->no_of_conf_nos;
	else
	{
	    *no_copy++ = *no;
	    *type_copy++ = *type;
	}

	++no;
	++type;
    }
    return OK;
}

654
655
656
657
658
659
660
661
662
663
664
665
666
extern Success
lookup_z_name (const String       name,
	       int                want_persons,
	       int                want_confs,
	       Conf_z_info_list * result)
{
    Conf_no	 *no;
    Conf_type    *type;
    Conf_z_info  *res;
    int		  i;
    int           n_filtered;
    Conf_list_old raw_matches;
    
David Byers's avatar
Server    
David Byers committed
667
    CHK_CONNECTION(FAILURE);
668
669
670
671
672
673
674
675
676
    if (cached_lookup_name(name, &raw_matches) != OK)
	return FAILURE;

    no = raw_matches.conf_nos;
    type = raw_matches.type_of_conf;
    n_filtered = raw_matches.no_of_conf_nos;
    for (i = raw_matches.no_of_conf_nos; i > 0; i--)
    {
	if (*no == 0)
677
	    restart_kom("Internal error detected in lookup_z_name\n");
678
679

	if ((type->letter_box ? want_persons : want_confs) == 0
680
	    || !has_access(*no, active_connection, read_protected))
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
	{
	    *no = 0;
	    n_filtered--;
	}

	no++;
	type++;
    }

    result->no_of_confs = n_filtered;
    result->confs = tmp_alloc(n_filtered * sizeof(Conf_z_info));
    no = raw_matches.conf_nos;
    type = raw_matches.type_of_conf;
    res = result->confs;
    for (i = raw_matches.no_of_conf_nos; i > 0; i--)
    {
	if (*no != 0)
	{
	    res->conf_no = *no;
	    res->type = *type;
	    res->name = cached_get_name(*no);
	    res++;
	}
	no++;
	type++;
    }

    if (res != result->confs + n_filtered) 
709
	restart_kom("Internal error in lookup_z_name\n");
710
711
712
713

    return OK;
}

714
static Success
David Byers's avatar
Server    
David Byers committed
715
716
do_lookup (Connection *conn,
           const String    name,
717
718
719
720
	   Conf_no_list * result,
	   Bool want_persons)
{
    Conf_list_old raw_match;
Per Cederqvist's avatar
Per Cederqvist committed
721
722
    unsigned long i;
    unsigned short retsize;
723
    unsigned int letterflag = want_persons;
724
725
726
727
728
729
730
731
732
733

    if ( cached_lookup_name( name, &raw_match ) != OK )
	return FAILURE;

    /* Find out how much space we need to allocate */
    retsize = 0;
    for (i = 0; i < raw_match.no_of_conf_nos; i++)
    {
	/* Don't call check access permissions here. It doesn't matter
	   that much if we allocate slightly too much memory. */
734
	if (raw_match.type_of_conf[i].letter_box == letterflag)
Per Cederqvist's avatar
Per Cederqvist committed
735
	{
736
	    retsize++;
Per Cederqvist's avatar
Per Cederqvist committed
737
738
739
740
741
742
	    /* i is "unsigned long", and retsize is "unsigned short".
	       They should probably both be "Conf_no" or
	       "Conf_no_iterator".  This should never be a problem in
	       practice as long as Conf_no is a short. */
	    if (retsize == 0)
	    {
David Byers's avatar
David Byers committed
743
		kom_log("WNG: do_lookup: far too many matches\n");
Per Cederqvist's avatar
Per Cederqvist committed
744
745
746
		--retsize;
	    }
	}
747
748
749
750
751
752
753
    }

    result->conf_nos = tmp_alloc(sizeof(Conf_no) * retsize);
    result->no_of_confs = 0;

    for (i = 0; i < raw_match.no_of_conf_nos; i++)
    {
754
	if (raw_match.type_of_conf[i].letter_box == letterflag
755
	    && has_access(raw_match.conf_nos[i], conn, read_protected))
756
757
758
759
760
761
762
763
764
765
766
767
768
769
	{
	    result->conf_nos[result->no_of_confs++] = raw_match.conf_nos[i];
	    if (result->no_of_confs > retsize)
		restart_kom("ERROR: conference.c: do_lookup: error.\n");
	}
    }

    return OK;
}

extern  Success
lookup_person (const String  pattern,
	       Conf_no_list  *result)
{
David Byers's avatar
Server    
David Byers committed
770
771
    CHK_CONNECTION(FAILURE);
    return do_lookup(active_connection, pattern, result, TRUE);
772
773
774
775
776
777
}

extern  Success
lookup_conf (const String  pattern,
	     Conf_no_list  *result)
{
David Byers's avatar
Server    
David Byers committed
778
779
    CHK_CONNECTION(FAILURE);
    return do_lookup(active_connection, pattern, result, FALSE);
780
781
782
}


Per Cederqvist's avatar
Per Cederqvist committed
783
784
785
786

/*
 * Get status for a conference.
 */
787
788
789
790
791
792
793

extern Success
get_conf_stat(Conf_no         conf_no,
              Conference    * result)
{
    Aux_item_list    filtered;

David Byers's avatar
Server    
David Byers committed
794
    CHK_CONNECTION(FAILURE);
795
796
797
798
    if (get_conf_stat_old(conf_no, result) == OK)
    {
        filter_aux_item_list(&result->aux_item_list,
                             &filtered,
David Byers's avatar
Server    
David Byers committed
799
                             active_connection);
800
801
802
803
804
805
806
        result->aux_item_list = filtered;
        return OK;
    }

    return FAILURE;
}

Per Cederqvist's avatar
Per Cederqvist committed
807
extern  Success
808
809
get_conf_stat_old (Conf_no		  conf_no,
                   Conference           * result )
Per Cederqvist's avatar
Per Cederqvist committed
810
811
{
    Conference * conf_c;
812
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
813
        
David Byers's avatar
Server    
David Byers committed
814
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
815
816
    GET_C_STAT(conf_c, conf_no, FAILURE);

817
    acc = access_perm(conf_no, active_connection, read_protected);
Per Cederqvist's avatar
Per Cederqvist committed
818
819
820
821

    if ( acc == error )
	return FAILURE;

David Byers's avatar
David Byers committed
822
    if ( acc <= none )
Per Cederqvist's avatar
Per Cederqvist committed
823
    {
824
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
825
826
827
828
829
830
831
832
833
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    }

    *result = *conf_c;

    return OK;
}

834
835
836
837
838
839
840
841
/*
 * Get small status for a conference
 */

extern Success
get_uconf_stat (Conf_no		conf_no,
	       Small_conf     * result)
{
842
    enum access		acc;
843
844
    Small_conf	      * conf_c;

David Byers's avatar
Server    
David Byers committed
845
    CHK_CONNECTION(FAILURE);
846
847
    conf_c = cached_get_small_conf_stat(conf_no);
    if (conf_c != NULL)
848
	acc = access_perm(conf_no, active_connection, read_protected);
849
850
851
852
853
854
855
856
    else
	acc = error;

    switch (acc)
    {
    case error:
	return FAILURE;
    case none:
857
        err_stat = conf_no;
858
859
860
861
862
863
864
865
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    default:
	*result = *conf_c;
	return OK;
    }
}

Per Cederqvist's avatar
Per Cederqvist committed
866
extern  Success
867
get_conf_stat_older (Conf_no	  conf_no,
868
                     int	  mask,
869
                     Conference	* result )
Per Cederqvist's avatar
Per Cederqvist committed
870
871
{
    Conference * conf_c;
872
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
873
        
David Byers's avatar
Server    
David Byers committed
874
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
875
876
    GET_C_STAT(conf_c, conf_no, FAILURE);

877
    acc = access_perm(conf_no, active_connection, read_protected);
Per Cederqvist's avatar
Per Cederqvist committed
878
879
880
881

    if ( acc == error )
	return FAILURE;

David Byers's avatar
David Byers committed
882
    if ( acc <= none )
Per Cederqvist's avatar
Per Cederqvist committed
883
    {
884
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    }

    *result = *conf_c;

    if ( !(mask & 1) )
	result->name = EMPTY_STRING;	

    return OK;
}


		
/*
 * Set or delete the presentation of a conference. If text_no == 0 there
 * will be no presentation.
 *
 * The text's mark-count will be increased so that it will not be deleted
 * when it gets old.
 */

extern Success
set_presentation (Conf_no	conf_no,
		  Text_no	text_no )
{
    Conference * conf_c;
912
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
913
    
David Byers's avatar
Server    
David Byers committed
914
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
915
916
917
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

918
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
919
920
921
    
    if ( acc < unlimited )
    {
922
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
923
924
925
926
927
928
929
930
931
932
933
934
935
936
	kom_errno = (acc <= none) ? KOM_UNDEF_CONF : KOM_PERM;
	return FAILURE;
    }

    return do_set_presentation(conf_no, conf_c, text_no);
}

/*
 * Set a message-of-the-day for a conference. There should normally
 * be no motd unless something extraordinary happens. If there is
 * a motd the client should show it as soon as possible.
 *
 * Only the supervisor can change the motd.
 *
937
 * FIXME (bug 906): There is no asynchronous message that reports new motds.
Per Cederqvist's avatar
Per Cederqvist committed
938
939
940
941
942
943
 */
extern Success
set_etc_motd(	Conf_no		conf_no,
		Text_no		text_no )
{
    Conference * conf_c;
944
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
945
    
David Byers's avatar
Server    
David Byers committed
946
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
947
948
949
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

950
    if ((acc = access_perm(conf_no, active_connection, unlimited)) < unlimited)
Per Cederqvist's avatar
Per Cederqvist committed
951
    {
952
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
	kom_errno = (acc <= none ) ? KOM_UNDEF_CONF : KOM_PERM;
	BUG(("set_etc_motd failed. Conf %ld Text %ld Acc %ld < %ld (%d).\n",
	     (u_long)conf_no, (u_long)text_no, (u_long)acc,
	     (u_long)unlimited, acc < unlimited));
	return FAILURE;
    }

    return do_set_etc_motd(conf_no, conf_c, text_no);
}

/*
 * Set a new supervisor for a conference. May only be used by
 * the old supervisor.
 *
 * NEW_SUPER is either a person or a conference number. If it is a
 * conference number it means that all the members in NEW_SUPER become
 * supervisors to CONF_NO. (NEW_SUPER should normally be rd_prot to
 * prevent anyone from makeing themselves supervisors).
 */
extern Success
set_supervisor(	Conf_no	 conf_no,
		Conf_no	 new_super )
{
    Conference * conf_c;
    
David Byers's avatar
Server    
David Byers committed
978
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
979
980
981
982
983
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);
    if (new_super != 0)
	CHK_EXIST(new_super, FAILURE);

984
    if ( !is_strictly_supervisor(conf_no, ACTPERS, ACT_P) &&
David Byers's avatar
Server    
David Byers committed
985
986
         !ENA(wheel, 8) &&      /* OK -- in an RPC call */
         !ENA(admin, 6) )       /* OK -- in an RPC call */
Per Cederqvist's avatar
Per Cederqvist committed
987
    {
988
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
989
990
991
992
993
994
995
996
997
998
999
1000
	kom_errno = conf_c->type.secret ? KOM_UNDEF_CONF : KOM_PERM;
	return FAILURE;
    }
    
    conf_c->supervisor = new_super;
    mark_conference_as_changed( conf_no );
	
    return OK;
}

/*
 * Allow certain users to submit texts to CONF_NO.
For faster browsing, not all history is shown. View entire blame