admin.c 2.8 KB
Newer Older
Per Cederqvist's avatar
Per Cederqvist committed
1
2
3
4
5
/*
 * admin.c
 *
 * Administrative calls.
 */
Per Cederqvist's avatar
Per Cederqvist committed
6
7
8

static char *rcsid = "$Id: admin.c,v 0.4 1991/08/28 02:22:05 ceder Exp $";

Per Cederqvist's avatar
Per Cederqvist committed
9
10
11
12
13
#include <stdlib.h>
#include "lyskomd.h"
#include <kom-types.h>
#include <services.h>
#include "manipulate.h"
14
#include <server/smalloc.h>
Per Cederqvist's avatar
Per Cederqvist committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "cache.h"
#include "log.h"
#include "admin.h"
#include <kom-errno.h>
#include "com.h"
#include "connections.h"
#include "send-async.h"
#include "config.h"

Info kom_info = 
{
#include "version.incl"
    ,				/* version */
    1,				/* conf_pres_conf */
    2,				/* pers_pres_conf */
    3,				/* motd_conf */
    4,				/* kom_news_conf */
    0				/* motd_of_lyskom */
};

/*
 * Return info about this server. This can (and should) be done
 * before logging in. modt_of_lyskom should be displayed before
 * prompting for username if it isn't 0.
 */
extern Success
get_info( Info *result )
{
    *result = kom_info;
    return OK;
}

/* /// */
extern Success
set_motd_of_lyskom (Text_no motd)
{
    Text_stat *old_motd = NULL;
    Text_stat *new_motd = NULL;

    CHK_LOGIN(FAILURE);

    if ( !ENA(admin, 1) )
    {
	kom_errno = KOM_PERM;
	return FAILURE;
    }
    
    /* Check that the new motd exists before deleting the old*/

    if ( motd != 0 )
    {
	GET_T_STAT(new_motd, motd, FAILURE);
	if ( new_motd->no_of_marks >= MAX_MARKS_TEXT )
	{
69
70
71
	    log("LIMIT: set_motd_of_lyskom(%d): New motd has %d marks.\n",
		motd, new_motd->no_of_marks);
	    kom_errno = KOM_MARK_LIMIT;
Per Cederqvist's avatar
Per Cederqvist committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	    return FAILURE;
	}
    }
    
    /* Unmark the previous motd if it exists. */

    if ( kom_info.motd_of_lyskom != 0
	&& (old_motd = cached_get_text_stat(kom_info.motd_of_lyskom)) != NULL)
    {
	if ( old_motd->no_of_marks > 0 )
	{
	    --old_motd->no_of_marks;
	    mark_text_as_changed( kom_info.motd_of_lyskom );
	}
	else
	{
	    log("ERROR: do_set_motd(): Old motd not marked\n");
	}
    }

    /* Mark the new motd */

    if ( motd != 0 )
    {
	++new_motd->no_of_marks;
	mark_text_as_changed( motd );
    }
    
    kom_info.motd_of_lyskom = motd;

    return OK;
}




/*
 * Force all clients to read a message.
 * Sends an asynchronous message. This is obsoleted by send_message.
 */
extern Success
broadcast (String message)
{
    CHK_LOGIN(FAILURE);

    async_broadcast(ACTPERS, message);
    return OK;
}

/*
 * Send a message
 */
extern Success
send_message (Pers_no recipient,
	      const String message)
{
    CHK_LOGIN(FAILURE);

    return async_send_message(recipient, ACTPERS, message);
}



/*
 * Make LysKOM sync its files.
 */
extern Success
sync (void) 
{
    cache_sync_all();
    dump_statistics();
    return OK;
}

/*
 * Close LysKOM. exit_val is (currently) not used. The database is synced.
 */
extern Success
shutdown (int exit_val) 
{
    CHK_LOGIN(FAILURE);
    if ( !ENA(admin, 1) )
    {
	kom_errno = KOM_PERM;
	return FAILURE;
    }

    go_and_die = TRUE;
    return OK;
}