conference.c 33.1 KB
Newer Older
Linus Tolke Y's avatar
Linus Tolke Y committed
1
/*
2
 * $Id: conference.c,v 0.79 2003/07/12 22:26:32 ceder Exp $
3
 * Copyright (C) 1991-2002  Lysator Academic Computer Association.
Linus Tolke Y's avatar
Linus Tolke Y committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 *
 * 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.
 *
 * Please mail bug reports to bug-lyskom@lysator.liu.se. 
 */
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

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

Per Cederqvist's avatar
Per Cederqvist committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * 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
85
	kom_log("ERROR: do_delete_conf() - couldn't unmark presentation.\n");
Per Cederqvist's avatar
Per Cederqvist committed
86
87
88
89
    }
    
    if ( do_set_etc_motd(conf_no, conf_c, 0) != OK )
    {
David Byers's avatar
David Byers committed
90
	kom_log("ERROR: do_delete_conf() - couldn't unmark motd.\n");
Per Cederqvist's avatar
Per Cederqvist committed
91
92
93
94
95
96
97
98
99
100
101
102
103
    }

    /* 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
104

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

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

112
113
114
115
116
117
118
    /*
     * 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.
     */

119
    /* FIXME (bug 905): There should be an async message about the deletion. */
Per Cederqvist's avatar
Per Cederqvist committed
120
121
122
123
124
125
126
127
128
129

    cached_delete_conf( conf_no );
    
    return;
}

/*
 * Functions that are exported to the server.
 */

130
131
132
133
134
135
136
137
138
139
140
141
142
void
set_conf_errno(const Connection *viewer_conn,
	       Conf_no conf_no,
	       enum kom_err errcode)
{
    err_stat = conf_no;
    if (access_perm(conf_no, viewer_conn, read_protected) <= none)
	kom_errno = KOM_UNDEF_CONF;
    else
	kom_errno = errcode;
}


Per Cederqvist's avatar
Per Cederqvist committed
143
/*
144
145
 * 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
146
147
148
149
150
 */

Bool
legal_name( String name )
{
151
    if (name.len == 0 || name.len > param.conf_name_len )
Per Cederqvist's avatar
Per Cederqvist committed
152
    {
David Byers's avatar
David Byers committed
153
154
        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
155
156
157
158
159
	return FALSE;
    }

    while( name.len-- )
    {
160
161
162
163
164
#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
165
	{
166
            err_stat = 0;
167
	    kom_errno = KOM_BAD_NAME;
Per Cederqvist's avatar
Per Cederqvist committed
168
169
	    return FALSE;
	}
170
171
172
173
#else
	if (*name.string < ' ' ||
	    (*name.string > 126 && *name.string < ' ' + 128))
	{
174
            err_stat = 0;
175
176
177
178
	    kom_errno = KOM_BAD_NAME;
	    return FALSE;
	}
#endif
Per Cederqvist's avatar
Per Cederqvist committed
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	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,
201
202
		       s_fcrea_str(WHITESPACE),
		       DEFAULT_COLLAT_TAB);
Per Cederqvist's avatar
Per Cederqvist committed
203
204
205
206
207
208
209
210
211

    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
212
	kom_log("unique_name(): parse returned error.\n");
Per Cederqvist's avatar
Per Cederqvist committed
213
214
215
216
217
218
219
220
221
222
223
224
225
	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. */

226
    name_token = tokenize(name, s_fcrea_str(WHITESPACE));
Per Cederqvist's avatar
Per Cederqvist committed
227
228
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

    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
255
	if ( !diff_found && match_table[ parse_info.indexes[ i ] ].conf_no != conf_no )
Per Cederqvist's avatar
Per Cederqvist committed
256
257
258
259
260
261
262
263
264
265
266
	    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
267
static Conf_no
Per Cederqvist's avatar
Per Cederqvist committed
268
269
270
271
do_create_conf(String	 name,
	       Pers_no	 creator,
	       Conf_no	 supervisor,
	       Conf_no	 super_conf,
272
273
	       Conf_type type,
               Aux_item_list *aux)
Per Cederqvist's avatar
Per Cederqvist committed
274
275
276
277
{
    Conf_no 	 conf_no;
    Conference * conf_c;
    
278
279
    /* Prepare, then check the aux items */

Per Cederqvist's avatar
Per Cederqvist committed
280
281
282
    /* Allocate memory for conf_c */

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

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

    conf_c->creator	= creator;
296
    conf_c->creation_time = current_time.tv_sec;
Per Cederqvist's avatar
Per Cederqvist committed
297
298
299
300
301
302
303
    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;
304
    conf_c->nice	= param.default_nice;
305
    conf_c->keep_commented = param.default_keep_commented;
306
    conf_c->highest_aux = 0;
307
    conf_c->expire      = 0;
308

309
310
311
312
    /* 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);

313
    prepare_aux_item_list(aux, creator);
314
315
316
    if (conf_stat_check_add_aux_item_list(conf_c,
                                          conf_no,
                                          aux,
317
318
                                          creator,
                                          TRUE) != OK)
319
    {
320
	/* FIXME (bug 146): Conf_no leak: We create a conference, check the
321
322
323
324
	   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.  */

325
326
327
328
329
        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
330

331
    mark_conference_as_changed (conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
332
333
334
335
336
337

    return conf_no;
}


/*
338
 * Return TRUE if viewer is a supervisor to CONF.
Per Cederqvist's avatar
Per Cederqvist committed
339
340
 */

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

349
    return is_strictly_supervisor(conf, viewer, viewer_p);
350
351
352
353
}


Bool
354
355
356
is_strictly_supervisor(Conf_no       conf,
                       Pers_no       viewer,
                       const Person *viewer_p) /* May be NULL */
357
{
358
359
    Conf_no supervisor;

360
361
    if (viewer == 0)		/* Not yet logged in. */
	return FALSE;
Per Cederqvist's avatar
Per Cederqvist committed
362

363
364
365
366
    if (!cached_conf_exists(conf))
	return FALSE;

    if ((supervisor = cached_get_conf_supervisor(conf)) == 0)
Per Cederqvist's avatar
Per Cederqvist committed
367
368
        return FALSE;
	
369
    if (viewer == supervisor)
Per Cederqvist's avatar
Per Cederqvist committed
370
371
        return TRUE;

372
    if (viewer_p == NULL)
373
374
	GET_P_STAT(viewer_p, viewer, FALSE);

375
    if (locate_membership(supervisor, viewer_p) != NULL)
Per Cederqvist's avatar
Per Cederqvist committed
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
	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
391
392
change_name (Conf_no	   conf_no,
	     const String  new_name)
Per Cederqvist's avatar
Per Cederqvist committed
393
394
{
    Conference * conf_c;
395
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
396

David Byers's avatar
Server  
David Byers committed
397
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
398
399
400
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

401
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
402
403
404

    if ( acc <= none )
    {
405
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
406
407
408
409
410
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    }

    if ( !ACT_P->privileges.change_name
David Byers's avatar
Server  
David Byers committed
411
	|| (acc != unlimited && !ENA(admin, 3))) /* OK -- In an RPC call */
Per Cederqvist's avatar
Per Cederqvist committed
412
    {
413
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
414
415
416
417
418
419
	kom_errno = KOM_PERM;
	return FAILURE;
    }

    if ( !legal_name( new_name ) )
    {
420
	/* kom_errno will be set by legal_name(). */
Per Cederqvist's avatar
Per Cederqvist committed
421
422
423
424
425
	return FAILURE;
    }

    if ( !unique_name( new_name, conf_no ) )
    {
426
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
	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...)
 */

455
456
457
458
static Conf_no
create_conf_generic(const String  name,
                    Conf_type	  type,
                    Aux_item_list *aux)
Per Cederqvist's avatar
Per Cederqvist committed
459
460
461
{
    Conf_no	 conf_no;
    
David Byers's avatar
Server  
David Byers committed
462
    CHK_CONNECTION(0);
Per Cederqvist's avatar
Per Cederqvist committed
463
464
    CHK_LOGIN(0);

465
    if (param.anyone_can_create_new_confs == FALSE
David Byers's avatar
Server  
David Byers committed
466
	&& !HAVE_PRIV(ACT_P, create_conf))
Per Cederqvist's avatar
Per Cederqvist committed
467
    {
468
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
469
470
471
472
473
474
	kom_errno = KOM_PERM;
	return 0;
    }

    if ( !legal_name( name ) )
    {
475
	/* kom_errno will be set by legal_name(). */
Per Cederqvist's avatar
Per Cederqvist committed
476
477
478
479
480
	return 0;
    }

    if ( !unique_name( name, 0 ) )
    {
481
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
482
483
484
485
486
487
488
489
490
491
492
493
	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 )
    {
494
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
495
496
497
498
	kom_errno = KOM_SECRET_PUBLIC;
	return 0;
    }
    
499
    conf_no = do_create_conf(name, ACTPERS, ACTPERS, ACTPERS, type, aux);
Per Cederqvist's avatar
Per Cederqvist committed
500
501
502
503
504
505
506
507
508
509

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

510
511
512
513
Conf_no
create_conf_old(const String name,
                Conf_type    type)
{
David Byers's avatar
Server  
David Byers committed
514
    /* CHK_CONNECTION in create_conf_generic */
515
516
517
518
519
520
521
522
523
524
    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
525
    /* CHK_CONNECTION in create_conf_generic */
526
527
528
529
530
531
532
533
534
535
536
    conf = create_conf_generic(name, type, aux);
    if (conf != 0)
    {
        /* Send message no. 2 */
    }

    return conf;
}



Per Cederqvist's avatar
Per Cederqvist committed
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
/*
 * 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;
567
    enum access	     acc;
Per Cederqvist's avatar
Per Cederqvist committed
568
    
David Byers's avatar
Server  
David Byers committed
569
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
570
571
572
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

573
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
574
575
576
    
    if ( acc != unlimited )
    {
577
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
578
579
580
581
582
583
	kom_errno = (acc <= none) ? KOM_UNDEF_CONF : KOM_PERM ;
	return FAILURE;
    }

    if ( conf_c->type.letter_box )
    {
584
585
586
	/* Make sure the person that is deleted is not logged in. */

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

588
	if ( do_delete_pers (conf_no) != OK )
Per Cederqvist's avatar
Per Cederqvist committed
589
	{
David Byers's avatar
David Byers committed
590
	    kom_log("ERROR: delete_conf(): can't delete person.\n");
Per Cederqvist's avatar
Per Cederqvist committed
591
592
593
	}
    }

594
    do_delete_conf (conf_no, conf_c);
Per Cederqvist's avatar
Per Cederqvist committed
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611

    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
612
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
613
614
615
616
617
618
619
620
    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-- )
    {
621
	if (access_perm(*no, active_connection, read_protected) <= none)
Per Cederqvist's avatar
Per Cederqvist committed
622
623
624
625
626
627
628
629
630
631
632
633
634
	    --result->no_of_conf_nos;
	else
	{
	    *no_copy++ = *no;
	    *type_copy++ = *type;
	}

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

635
636
637
638
639
640
641
642
643
644
645
646
647
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
648
    CHK_CONNECTION(FAILURE);
649
650
651
652
653
654
655
656
657
    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)
658
	    restart_kom("Internal error detected in lookup_z_name\n");
659
660

	if ((type->letter_box ? want_persons : want_confs) == 0
661
	    || access_perm(*no, active_connection, read_protected) <= none)
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
	{
	    *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) 
690
	restart_kom("Internal error in lookup_z_name\n");
691
692
693
694

    return OK;
}

695
static Success
David Byers's avatar
Server  
David Byers committed
696
697
do_lookup (Connection *conn,
           const String    name,
698
699
700
701
	   Conf_no_list * result,
	   Bool want_persons)
{
    Conf_list_old raw_match;
Per Cederqvist's avatar
Per Cederqvist committed
702
703
    unsigned long i;
    unsigned short retsize;
704
    unsigned int letterflag = want_persons;
705
706
707
708
709
710
711
712
713
714

    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. */
715
	if (raw_match.type_of_conf[i].letter_box == letterflag)
Per Cederqvist's avatar
Per Cederqvist committed
716
	{
717
	    retsize++;
Per Cederqvist's avatar
Per Cederqvist committed
718
719
720
721
722
723
	    /* 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
724
		kom_log("WNG: do_lookup: far too many matches\n");
Per Cederqvist's avatar
Per Cederqvist committed
725
726
727
		--retsize;
	    }
	}
728
729
730
731
732
733
734
    }

    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++)
    {
735
	if (raw_match.type_of_conf[i].letter_box == letterflag
736
	    && access_perm(raw_match.conf_nos[i], conn, read_protected) > none)
737
738
739
740
741
742
743
744
745
746
747
748
749
750
	{
	    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
751
752
    CHK_CONNECTION(FAILURE);
    return do_lookup(active_connection, pattern, result, TRUE);
753
754
755
756
757
758
}

extern  Success
lookup_conf (const String  pattern,
	     Conf_no_list  *result)
{
David Byers's avatar
Server  
David Byers committed
759
760
    CHK_CONNECTION(FAILURE);
    return do_lookup(active_connection, pattern, result, FALSE);
761
762
763
}


Per Cederqvist's avatar
Per Cederqvist committed
764
765
766
767

/*
 * Get status for a conference.
 */
768
769
770
771
772
773
774

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

David Byers's avatar
Server  
David Byers committed
775
    CHK_CONNECTION(FAILURE);
776
777
778
779
    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
780
                             active_connection);
781
782
783
784
785
786
787
        result->aux_item_list = filtered;
        return OK;
    }

    return FAILURE;
}

Per Cederqvist's avatar
Per Cederqvist committed
788
extern  Success
789
790
get_conf_stat_old (Conf_no		  conf_no,
                   Conference           * result )
Per Cederqvist's avatar
Per Cederqvist committed
791
792
{
    Conference * conf_c;
793
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
794
        
David Byers's avatar
Server  
David Byers committed
795
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
796
797
    GET_C_STAT(conf_c, conf_no, FAILURE);

798
    acc = access_perm(conf_no, active_connection, read_protected);
Per Cederqvist's avatar
Per Cederqvist committed
799
800
801
802

    if ( acc == error )
	return FAILURE;

David Byers's avatar
David Byers committed
803
    if ( acc <= none )
Per Cederqvist's avatar
Per Cederqvist committed
804
    {
805
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
806
807
808
809
810
811
812
813
814
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    }

    *result = *conf_c;

    return OK;
}

815
816
817
818
819
820
821
822
/*
 * Get small status for a conference
 */

extern Success
get_uconf_stat (Conf_no		conf_no,
	       Small_conf     * result)
{
823
    enum access		acc;
824
825
    Small_conf	      * conf_c;

David Byers's avatar
Server  
David Byers committed
826
    CHK_CONNECTION(FAILURE);
827
828
    conf_c = cached_get_small_conf_stat(conf_no);
    if (conf_c != NULL)
829
	acc = access_perm(conf_no, active_connection, read_protected);
830
831
832
833
834
835
836
837
    else
	acc = error;

    switch (acc)
    {
    case error:
	return FAILURE;
    case none:
838
        err_stat = conf_no;
839
840
841
842
843
844
845
846
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    default:
	*result = *conf_c;
	return OK;
    }
}

Per Cederqvist's avatar
Per Cederqvist committed
847
extern  Success
848
get_conf_stat_older (Conf_no	  conf_no,
849
                     int	  mask,
850
                     Conference	* result )
Per Cederqvist's avatar
Per Cederqvist committed
851
852
{
    Conference * conf_c;
853
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
854
        
David Byers's avatar
Server  
David Byers committed
855
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
856
857
    GET_C_STAT(conf_c, conf_no, FAILURE);

858
    acc = access_perm(conf_no, active_connection, read_protected);
Per Cederqvist's avatar
Per Cederqvist committed
859
860
861
862

    if ( acc == error )
	return FAILURE;

David Byers's avatar
David Byers committed
863
    if ( acc <= none )
Per Cederqvist's avatar
Per Cederqvist committed
864
    {
865
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
	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;
893
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
894
    
David Byers's avatar
Server  
David Byers committed
895
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
896
897
898
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

899
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
900
901
902
    
    if ( acc < unlimited )
    {
903
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
904
905
906
907
908
909
910
911
912
913
914
915
916
917
	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.
 *
918
 * FIXME (bug 906): There is no asynchronous message that reports new motds.
Per Cederqvist's avatar
Per Cederqvist committed
919
920
921
922
923
924
 */
extern Success
set_etc_motd(	Conf_no		conf_no,
		Text_no		text_no )
{
    Conference * conf_c;
925
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
926
    
David Byers's avatar
Server  
David Byers committed
927
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
928
929
930
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

931
    if ((acc = access_perm(conf_no, active_connection, unlimited)) < unlimited)
Per Cederqvist's avatar
Per Cederqvist committed
932
    {
933
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
	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
959
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
960
961
962
963
964
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);
    if (new_super != 0)
	CHK_EXIST(new_super, FAILURE);

965
    if ( !is_strictly_supervisor(conf_no, ACTPERS, ACT_P) &&
David Byers's avatar
Server  
David Byers committed
966
967
         !ENA(wheel, 8) &&      /* OK -- in an RPC call */
         !ENA(admin, 6) )       /* OK -- in an RPC call */
Per Cederqvist's avatar
Per Cederqvist committed
968
    {
969
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
	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.
 *
 * If NEW_PERM_SUB == 0 anyone may submit texts.
 * If it is a person only that person can submit texts to CONF_NO.
 * If it is a conference only the members in that conference can
 * submit texts.
 *
 * If anyone tries to submit a text to a conference he is not allowed
 * to submit texts to the text will silently be redirected to the
 * superconf. If he is not allowed to submit to that conference either
 * it will be redirected again and so forth, but there is a limit
 * (MAX_SUPER_CONF_LOOP) on how many redirections will be done.
 *
 * It is possible to have a secret conference as super_conf. Users
 * will then be able to send texts to it, but they will not see
 * where the text went...
 */
extern Success
set_permitted_submitters (Conf_no  conf_no,
			  Conf_no  new_perm_sub ) 
{
    Conference * conf_c;
    
David Byers's avatar
Server  
David Byers committed
1004
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
1005
1006
1007
1008
1009
    CHK_LOGIN(FAILURE);
    if (new_perm_sub != 0)
	CHK_EXIST(new_perm_sub, FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

1010
    if ( !is_supervisor(conf_no, ACTPERS, ACT_P) &&
David Byers's avatar
Server  
David Byers committed
1011
1012
         !ENA(wheel, 8) &&      /* OK -- In an RPC call */
         !ENA(admin, 6) )       /* OK -- In an RPC call */
Per Cederqvist's avatar
Per Cederqvist committed
1013
    {
1014
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
	kom_errno = conf_c->type.secret ? KOM_UNDEF_CONF : KOM_PERM;
	return FAILURE;
    }
	
    conf_c->permitted_submitters = new_perm_sub;
    mark_conference_as_changed( conf_no );
	
    return OK;
}

/*
 * Set the super_conf of CONF_NO. This call may only be used of a
 * supervisor of CONF_NO.
 *
 * See documentation for set_permitted_submitters().
 */
extern Success
set_super_conf (Conf_no  conf_no,
		Conf_no  new_super_conf )
{
    Conference * conf_c;
    
David Byers's avatar
Server  
David Byers committed
1037
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
1038
1039
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);
1040
1041
    if (new_super_conf != 0)
	CHK_EXIST(new_super_conf, FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
1042

1043
    if ( !is_supervisor(conf_no, ACTPERS, ACT_P) &&
David Byers's avatar
Server  
David Byers committed
1044
1045
         !ENA(wheel, 8) &&      /* OK -- In an RPC call */
         !ENA(admin, 5) )       /* OK -- In an RPC call */
Per Cederqvist's avatar
Per Cederqvist committed
1046
    {
1047
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
	kom_errno = conf_c->type.secret ? KOM_UNDEF_CONF : KOM_PERM;
	return FAILURE;
    }

    conf_c->super_conf = new_super_conf;
    mark_conference_as_changed( conf_no );
	
    return OK;
}

/*
 * Set the type of a conference. Only the supervisor of a conference can
 * set the conf_type. The letter_box flag can not be changed.
 *
1062
 * FIXME (bug 70): It is allowed to set the type to 'secret' for
1063
 * persons. I don't think we want it to be that way. /ceder
Per Cederqvist's avatar
Per Cederqvist committed
1064
1065
1066
1067
1068
 */
extern Success
set_conf_type (Conf_no    conf_no,
	       Conf_type  type )
{
1069
1070
    Conference      *conf_c;
    Member          *memb;
1071
    enum access      acc;
1072
    unsigned long    i;
Per Cederqvist's avatar
Per Cederqvist committed
1073
        
David Byers's avatar
Server  
David Byers committed
1074
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
1075
1076
1077
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

1078
1079
1080
1081
    /*
     * Can't be secret and public at the same time?
     */

Per Cederqvist's avatar
Per Cederqvist committed
1082
1083
    if ( type.secret && !type.rd_prot )
    {
1084
        err_stat = 0;
Per Cederqvist's avatar
Per Cederqvist committed
1085
	kom_errno = KOM_SECRET_PUBLIC;
1086
	return FAILURE;
Per Cederqvist's avatar
Per Cederqvist committed
1087
1088
    }

1089
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
1090
    
1091
1092
1093
1094
    /*
     * Can't change type without privs
     */

Per Cederqvist's avatar
Per Cederqvist committed
1095
1096
    if ( acc < unlimited )
    {
1097
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
1098
1099
1100
1101
	kom_errno = ( acc <= none ) ? KOM_UNDEF_CONF : KOM_PERM ;
	return FAILURE;
    }
    
1102
1103
1104
1105
    /*
     * Can't change the letterbox flag.
     */

Per Cederqvist's avatar
Per Cederqvist committed
1106
1107
    if ( type.letter_box != conf_c->type.letter_box )
    {
1108
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
1109
1110
1111
1112
	kom_errno = KOM_LETTER_BOX;
	return FAILURE;
    }

1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
    /*
     * Can't change to secret if there are secret memberships
     * Only check this if we are changing the forbid_secret
     * flag to on from off
     */

    if (type.forbid_secret && !conf_c->type.forbid_secret)
    {
        for (i = 0; i < conf_c->members.no_of_members; i++)
        {
            memb = &conf_c->members.members[i];
            if (memb->type.secret)
            {
                err_stat = memb->member;
                kom_errno = KOM_INVALID_MEMBERSHIP_TYPE;
                return FAILURE;
            }
        }
    }

Per Cederqvist's avatar
Per Cederqvist committed
1133
    conf_c->type = type;
1134
    mark_conference_as_changed (conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150

    return OK;
}


/*
 * Set garb_nice for a conference. This controls how long messages
 * to a conference will live. The argument is probably the number of
 * days a message will live. Only the supervisor of the conference
 * may change the garb_nice.
 */
extern Success
set_garb_nice(	Conf_no		conf_no,
		Garb_nice	nice	)	/* number of days */
{
    Conference * conf_c;
1151
    enum access	 acc;
Per Cederqvist's avatar
Per Cederqvist committed
1152
        
David Byers's avatar
Server  
David Byers committed
1153
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
1154
1155
1156
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

1157
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
1158
1159
1160
    
    if ( acc < unlimited )
    {
1161
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
	kom_errno = (acc <= none) ? KOM_UNDEF_CONF : KOM_PERM;
	return FAILURE;
    }

    conf_c->nice = nice;
    mark_conference_as_changed( conf_no );

    return OK;
}

1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
/*
 * Set expire for a conference. This controls nothing at the moment, but
 * will probably control when a conference is killed automatically by
 * the server in cases of extreme inactivity.
 */
extern Success
set_expire(	Conf_no		conf_no,
		Garb_nice	expire	)	/* number of days */
{
    Conference * conf_c;
1182
    enum access	 acc;
1183
        
David Byers's avatar
Server  
David Byers committed
1184
    CHK_CONNECTION(FAILURE);
1185
1186
1187
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

1188
    acc = access_perm(conf_no, active_connection, unlimited);
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
    
    if ( acc < unlimited )
    {
        err_stat = conf_no;
	kom_errno = (acc <= none) ? KOM_UNDEF_CONF : KOM_PERM;
	return FAILURE;
    }

    conf_c->expire = expire;
    mark_conference_as_changed( conf_no );

    return OK;
}

1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
/*
 * Set expire for a conference. This controls nothing at the moment, but
 * will probably control when a conference is killed automatically by
 * the server in cases of extreme inactivity.
 */
extern Success
set_keep_commented(Conf_no	conf_no,
                   Garb_nice	keep_commented)	/* number of days */
{
    Conference * conf_c;
1213
    enum access	 acc;
1214
        
David Byers's avatar
Server  
David Byers committed
1215
    CHK_CONNECTION(FAILURE);
1216
1217
1218
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

1219
    acc = access_perm(conf_no, active_connection, unlimited);
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
    
    if ( acc < unlimited )
    {
        err_stat = conf_no;
	kom_errno = (acc <= none) ? KOM_UNDEF_CONF : KOM_PERM;
	return FAILURE;
    }

    conf_c->keep_commented = keep_commented;
    mark_conference_as_changed( conf_no );

    return OK;
}

Per Cederqvist's avatar
Per Cederqvist committed
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
/*
 * Change presentation of a conference. If text_no is 0, there will be
 * no presentation.
 */

Success
do_set_presentation(Conf_no 	 conf_no,
		    Conference * conf_c,
		    Text_no	 text_no)
{
    Text_stat * old_pres;
    Text_stat * new_pres = NULL; /* Initialized to stop gcc complaining
				  * about this being used uninitialized.
				  * This initialization is in fact not needed
				  * since it would not be used uninitialized.*/

    /* Check that the new presentation exists before deleting the old*/

    if ( text_no != 0 )
    {
	GET_T_STAT(new_pres, text_no, FAILURE);
1255
	if ( new_pres->no_of_marks >= param.max_marks_text )
Per Cederqvist's avatar
Per Cederqvist committed
1256
	{
David Byers's avatar
David Byers committed
1257
	    kom_log("%s(%d, ptr, %lu): New presentation has %d marks.\n", 
Per Cederqvist's avatar
Per Cederqvist committed
1258
		"LIMIT: do_set_presentation",
1259
		conf_no, (unsigned long)text_no, new_pres->no_of_marks);
1260
            err_stat = text_no;
1261
	    kom_errno = KOM_MARK_LIMIT;
Per Cederqvist's avatar
Per Cederqvist committed
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
	    return FAILURE;
	}
    }
    
    /* Unmark the previous presentation if it exists. */

    if ( conf_c->presentation != 0
	&& (old_pres = cached_get_text_stat(conf_c->presentation)) != NULL)
    {
	if ( old_pres->no_of_marks > 0 )
	{
	    --old_pres->no_of_marks;
	    mark_text_as_changed( conf_c->presentation );
	}
	else
	{
1278
1279
1280
	    kom_log("ERROR: do_set_presentation(%d, ptr, %lu): "
		    "Old presentation not marked.\n",
		    conf_no, (unsigned long)text_no);
Per Cederqvist's avatar
Per Cederqvist committed
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
	}
    }

    /* Mark the new presentation */

    if ( text_no != 0 )
    {
	++new_pres->no_of_marks;
	mark_text_as_changed( text_no );
    }
    
    conf_c->presentation = text_no;
    mark_conference_as_changed( conf_no );

    return OK;
}

/*
 * Change motd of a conference. If text_no is 0, there will be
 * no motd.
 */

Success
do_set_etc_motd(Conf_no      conf_no,
		Conference * conf_c,
		Text_no      text_no)
{
    Text_stat * old_motd;
    Text_stat * new_motd = NULL; /* To stop gcc complaining. */

    /* Check that the new motd exists before deleting the old*/

    if ( text_no != 0 )
    {
	GET_T_STAT(new_motd, text_no, FAILURE);
1316
	if ( new_motd->no_of_marks >= param.max_marks_text )
Per Cederqvist's avatar
Per Cederqvist committed
1317
	{
1318
1319
1320
	    kom_log("LIMIT: do_set_etc_motd(%d, ptr, %lu): "
		    "New motd has %d marks.\n",
		    conf_no, (unsigned long)text_no, new_motd->no_of_marks);
1321
            err_stat = text_no;
1322
	    kom_errno = KOM_MARK_LIMIT;
Per Cederqvist's avatar
Per Cederqvist committed
1323
1324
1325
1326
1327
1328
1329
1330