conference.c 33.2 KB
Newer Older
Linus Tolke's avatar
Linus Tolke committed
1
/*
2
 * $Id: conference.c,v 0.57 1999/07/05 07:02:36 ceder Exp $
3
 * Copyright (C) 1991-1999  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
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
36

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


Per Cederqvist's avatar
Per Cederqvist committed
37
static const char *
38
rcsid = "$Id: conference.c,v 0.57 1999/07/05 07:02:36 ceder Exp $";
39
40
#include "rcs.h"
USE(rcsid);
Per Cederqvist's avatar
Per Cederqvist committed
41

Per Cederqvist's avatar
Per Cederqvist committed
42
#include <ctype.h>
Per Cederqvist's avatar
Per Cederqvist committed
43
44
45
#include <stdio.h>
#include <time.h>
#include <setjmp.h>
46
#include <sys/types.h>
Per Cederqvist's avatar
Per Cederqvist committed
47

48
#include "s-string.h"
Per Cederqvist's avatar
Per Cederqvist committed
49
#include "kom-types.h"
Per Cederqvist's avatar
Per Cederqvist committed
50
#include "log.h"
Per Cederqvist's avatar
Per Cederqvist committed
51
52
53
54
55
#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
56
57
58
#include "com.h"
#include "async.h"
#include "connections.h"
Per Cederqvist's avatar
Per Cederqvist committed
59
60
#include "manipulate.h"
#include "server/smalloc.h"
David Byers's avatar
David Byers committed
61
#include "kom-config.h"
Per Cederqvist's avatar
Per Cederqvist committed
62
#include "parser.h"
Per Cederqvist's avatar
Per Cederqvist committed
63
#include "internal-connections.h"
Per Cederqvist's avatar
Per Cederqvist committed
64
65
66
67
#include "kom-errno.h"
#include "lyskomd.h"
#include "debug.h"
#include "send-async.h"
68
#include "param.h"
69
#include "aux-items.h"
70
#include "local-to-global.h"
71
#include "server-time.h"
72

David Byers's avatar
David Byers committed
73
74
BUGDECL;

Per Cederqvist's avatar
Per Cederqvist committed
75
76
/*
 * Defined in conference.c. This will go away when we use regexp-matching.
77
 * This is only temporary. FIXME+++***
Per Cederqvist's avatar
Per Cederqvist committed
78
 */
David Byers's avatar
Server:    
David Byers committed
79
extern Matching_info       *match_table;
Per Cederqvist's avatar
Per Cederqvist committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

/*
 * 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
97
	kom_log("ERROR: do_delete_conf() - couldn't unmark presentation.\n");
Per Cederqvist's avatar
Per Cederqvist committed
98
99
100
101
    }
    
    if ( do_set_etc_motd(conf_no, conf_c, 0) != OK )
    {
David Byers's avatar
David Byers committed
102
	kom_log("ERROR: do_delete_conf() - couldn't unmark motd.\n");
Per Cederqvist's avatar
Per Cederqvist committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
    }

    /* 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
Server:    
David Byers committed
117
118
    /* Delete the name.
       FIXME: This is done by cached_delete_conf */
Per Cederqvist's avatar
Per Cederqvist committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

    s_clear( &conf_c->name );
    cached_change_name( conf_no, EMPTY_STRING);
    
    /* texts */

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

    /* ??? Note that there will still be a recipient in the texts, but it
       will not exist in reality. This might cause problems. A do_sub_recpt()
       should maybe be used. */
    /* Yes, do!  Also, send out asynchronous message about deleted conf. */

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

/*
145
146
 * 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
147
148
149
150
151
 */

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

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

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

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

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

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

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

    if ( (conf_c = cached_get_conf_stat( conf_no ) ) == NULL)
    {
	restart_kom("create_conf() - can't get conf_stat");
    }

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

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

314
    prepare_aux_item_list(aux, creator);
315
316
317
    if (conf_stat_check_add_aux_item_list(conf_c,
                                          conf_no,
                                          aux,
318
319
                                          creator,
                                          TRUE) != OK)
320
321
322
323
324
325
    {
        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
326

327
    mark_conference_as_changed (conf_no);
Per Cederqvist's avatar
Per Cederqvist committed
328
329
330
331
332
333

    return conf_no;
}


/*
334
 * Return TRUE if viewer is a supervisor to CONF.
Per Cederqvist's avatar
Per Cederqvist committed
335
336
 */

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

345
    return is_strictly_supervisor(conf, viewer, viewer_p);
346
347
348
349
350
351
352
353
}


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

356
357
    if (viewer == 0)		/* Not yet logged in. */
	return FALSE;
Per Cederqvist's avatar
Per Cederqvist committed
358

359
360
361
362
    if (!cached_conf_exists(conf))
	return FALSE;

    if ((supervisor = cached_get_conf_supervisor(conf)) == 0)
Per Cederqvist's avatar
Per Cederqvist committed
363
364
        return FALSE;
	
365
    if (viewer == supervisor)
Per Cederqvist's avatar
Per Cederqvist committed
366
367
        return TRUE;

368
    if (viewer_p == NULL)
369
370
	GET_P_STAT(viewer_p, viewer, FALSE);

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

David Byers's avatar
Server    
David Byers committed
393
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
394
395
396
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

397
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
398
399
400

    if ( acc <= none )
    {
401
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
402
403
404
405
406
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    }

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

    if ( !legal_name( new_name ) )
    {
416
	/* kom_errno will be set by legal_name(). */
Per Cederqvist's avatar
Per Cederqvist committed
417
418
419
420
421
	return FAILURE;
    }

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

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

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

    if ( !legal_name( name ) )
    {
471
	/* kom_errno will be set by legal_name(). */
Per Cederqvist's avatar
Per Cederqvist committed
472
473
474
475
476
	return 0;
    }

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

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

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

    return conf;
}



Per Cederqvist's avatar
Per Cederqvist committed
533
534
535
536
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
/*
 * 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;
    Access	     acc;
    
David Byers's avatar
Server    
David Byers committed
565
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
566
567
568
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

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

    if ( conf_c->type.letter_box )
    {
580
581
582
	/* Make sure the person that is deleted is not logged in. */

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

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

590
    do_delete_conf (conf_no, conf_c);
Per Cederqvist's avatar
Per Cederqvist committed
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

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

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

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

	if ((type->letter_box ? want_persons : want_confs) == 0
657
	    || access_perm(*no, active_connection, read_protected) <= none)
658
659
660
661
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
690
	{
	    *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) 
	restart_kom("Internal error in lookup_z_name");

    return OK;
}

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

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

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

extern  Success
lookup_conf (const String  pattern,
	     Conf_no_list  *result)
{
David Byers's avatar
Server    
David Byers committed
754
755
    CHK_CONNECTION(FAILURE);
    return do_lookup(active_connection, pattern, result, FALSE);
756
757
758
}


Per Cederqvist's avatar
Per Cederqvist committed
759
760
761
762

/*
 * Get status for a conference.
 */
763
764
765
766
767
768
769

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

David Byers's avatar
Server    
David Byers committed
770
    CHK_CONNECTION(FAILURE);
771
772
773
774
    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
775
                             active_connection);
776
777
778
779
780
781
782
        result->aux_item_list = filtered;
        return OK;
    }

    return FAILURE;
}

Per Cederqvist's avatar
Per Cederqvist committed
783
extern  Success
784
785
get_conf_stat_old (Conf_no		  conf_no,
                   Conference           * result )
Per Cederqvist's avatar
Per Cederqvist committed
786
787
788
789
{
    Conference * conf_c;
    Access	 acc;
        
David Byers's avatar
Server    
David Byers committed
790
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
791
792
    GET_C_STAT(conf_c, conf_no, FAILURE);

793
    acc = access_perm(conf_no, active_connection, read_protected);
Per Cederqvist's avatar
Per Cederqvist committed
794
795
796
797

    if ( acc == error )
	return FAILURE;

David Byers's avatar
David Byers committed
798
    if ( acc <= none )
Per Cederqvist's avatar
Per Cederqvist committed
799
    {
800
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
801
802
803
804
805
806
807
808
809
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    }

    *result = *conf_c;

    return OK;
}

810
811
812
813
814
815
816
817
818
819
820
/*
 * Get small status for a conference
 */

extern Success
get_uconf_stat (Conf_no		conf_no,
	       Small_conf     * result)
{
    Access		acc;
    Small_conf	      * conf_c;

David Byers's avatar
Server    
David Byers committed
821
    CHK_CONNECTION(FAILURE);
822
823
    conf_c = cached_get_small_conf_stat(conf_no);
    if (conf_c != NULL)
824
	acc = access_perm(conf_no, active_connection, read_protected);
825
826
827
828
829
830
831
832
    else
	acc = error;

    switch (acc)
    {
    case error:
	return FAILURE;
    case none:
833
        err_stat = conf_no;
834
835
836
837
838
839
840
841
	kom_errno = KOM_UNDEF_CONF;
	return FAILURE;
    default:
	*result = *conf_c;
	return OK;
    }
}

Per Cederqvist's avatar
Per Cederqvist committed
842
extern  Success
843
get_conf_stat_older (Conf_no	  conf_no,
844
                     int	  mask,
845
                     Conference	* result )
Per Cederqvist's avatar
Per Cederqvist committed
846
847
848
849
{
    Conference * conf_c;
    Access	 acc;
        
David Byers's avatar
Server    
David Byers committed
850
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
851
852
    GET_C_STAT(conf_c, conf_no, FAILURE);

853
    acc = access_perm(conf_no, active_connection, read_protected);
Per Cederqvist's avatar
Per Cederqvist committed
854
855
856
857

    if ( acc == error )
	return FAILURE;

David Byers's avatar
David Byers committed
858
    if ( acc <= none )
Per Cederqvist's avatar
Per Cederqvist committed
859
    {
860
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
861
862
863
864
865
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
893
894
895
896
897
898
899
900
901
	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.
 *
 * BUGS: This should probably be a Info_type 'presentation to conf no #'
 *	 for at least two reasons:
 *		1) Given the text, there is no way to know that it
 *		   is a presentation unless what the user writes
 *		   tells you so.
 *		2) Presentations should always be readable by everyone.
 *		   But to be readable an open conference needs to be
 *		   recipient of the text. Since all presentations should
 *		   go to the presentation-confs (that is the clients
 *		   responsibility!) this is no big problem, but it depends
 *		   somewhat on how the text-garber is implemented.
 */

extern Success
set_presentation (Conf_no	conf_no,
		  Text_no	text_no )
{
    Conference * conf_c;
    Access	 acc;
    
David Byers's avatar
Server    
David Byers committed
902
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
903
904
905
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

906
    acc = access_perm(conf_no, active_connection, unlimited);
Per Cederqvist's avatar
Per Cederqvist committed
907
908
909
    
    if ( acc < unlimited )
    {
910
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
911
912
913
914
915
916
917
918
919
920
921
922
923
924
	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.
 *
Per Cederqvist's avatar
Per Cederqvist committed
925
 * BUG: +++ There is no asynchronous message that reports new motds.
Per Cederqvist's avatar
Per Cederqvist committed
926
927
928
929
930
931
932
933
 */
extern Success
set_etc_motd(	Conf_no		conf_no,
		Text_no		text_no )
{
    Conference * conf_c;
    Access	 acc;
    
David Byers's avatar
Server    
David Byers committed
934
    CHK_CONNECTION(FAILURE);
Per Cederqvist's avatar
Per Cederqvist committed
935
936
937
    CHK_LOGIN(FAILURE);
    GET_C_STAT(conf_c, conf_no, FAILURE);

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

972
    if ( !is_strictly_supervisor(conf_no, ACTPERS, ACT_P) &&
David Byers's avatar
Server    
David Byers committed
973
974
         !ENA(wheel, 8) &&      /* OK -- in an RPC call */
         !ENA(admin, 6) )       /* OK -- in an RPC call */
Per Cederqvist's avatar
Per Cederqvist committed
975
    {
976
        err_stat = conf_no;
Per Cederqvist's avatar
Per Cederqvist committed
977
978
979
980
981
982
983
984
985
986
987
988
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.
 *
 * 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.
 *
For faster browsing, not all history is shown. View entire blame