citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

serv_newuser.c
Go to the documentation of this file.
1/*
2 * Automatically copies the contents of a "New User Greetings" room to the
3 * inbox of any new user upon account creation.
4 *
5 * Copyright (c) 1987-2012 by the citadel.org team
6 *
7 * This program is open source software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 3.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16/*
17 * Name of the New User Greetings room.
18 */
19#define NEWUSERGREETINGS "New User Greetings"
20
21#include "sysdep.h"
22#include <stdlib.h>
23#include <unistd.h>
24#include <stdio.h>
25#include <fcntl.h>
26#include <signal.h>
27#include <pwd.h>
28#include <errno.h>
29#include <sys/types.h>
30#include <time.h>
31#include <sys/wait.h>
32#include <string.h>
33#include <limits.h>
34#include "ctdl_module.h"
35#include "citadel.h"
36#include "server.h"
37#include "citserver.h"
38#include "support.h"
39#include "config.h"
40#include "user_ops.h"
41#include "database.h"
42#include "msgbase.h"
43
44/*
45 * Copy the contents of the New User Greetings> room to the user's Mail> room.
46 */
48 struct cdbdata *cdbfr;
49 long *msglist = NULL;
50 int num_msgs = 0;
51 char mailboxname[ROOMNAMELEN];
52
53
54 /* Only do this for new users. */
55 if (CC->user.timescalled != 1) return;
56
57 /* This user's mailbox. */
58 CtdlMailboxName(mailboxname, sizeof mailboxname, &CC->user, MAILROOM);
59
60 /* Go to the source room ... bail out silently if it's not there,
61 * or if it's not private.
62 */
63 if (CtdlGetRoom(&CC->room, NEWUSERGREETINGS) != 0) return;
64 if ((CC->room.QRflags & QR_PRIVATE) == 0) return;
65
66 cdbfr = cdb_fetch(CDB_MSGLISTS, &CC->room.QRnumber, sizeof(long));
67
68 if (cdbfr != NULL) {
69 msglist = malloc(cdbfr->len);
70 memcpy(msglist, cdbfr->ptr, cdbfr->len);
71 num_msgs = cdbfr->len / sizeof(long);
72 cdb_free(cdbfr);
73 }
74
75 if (num_msgs > 0) {
76 CtdlSaveMsgPointersInRoom(mailboxname, msglist, num_msgs, 1, NULL, 0);
77 }
78
79 /* Now free the memory we used, and go away. */
80 if (msglist != NULL) free(msglist);
81}
82
83
85{
86 if (!threading)
87 {
89 }
90
91 /* return our module name for the log */
92 return "newuser";
93}
#define ROOMNAMELEN
Definition: citadel.h:56
#define CC
Definition: context.h:140
void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
Definition: user_ops.c:349
int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name)
Definition: room_ops.c:342
void CtdlRegisterSessionHook(void(*fcn_ptr)(void), int EventType, int Priority)
#define PRIO_LOGIN
Definition: ctdl_module.h:83
#define CTDL_MODULE_INIT(module_name)
Definition: ctdl_module.h:50
void cdb_free(struct cdbdata *cdb)
Definition: database.c:609
struct cdbdata * cdb_fetch(int cdb, const void *key, int keylen)
Definition: database.c:546
#define QR_PRIVATE
Definition: ipcdef.h:41
int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs, int do_repl_check, struct CtdlMessage *supplied_msg, int suppress_refcount_adj)
Definition: msgbase.c:2236
void * malloc(size_t)
void free(void *)
void CopyNewUserGreetings(void)
Definition: serv_newuser.c:47
#define NEWUSERGREETINGS
Definition: serv_newuser.c:19
#define EVT_LOGIN
Definition: server.h:214
@ CDB_MSGLISTS
Definition: server.h:189
size_t len
Definition: server.h:203
char * ptr
Definition: server.h:204
#define MAILROOM
Definition: sysconfig.h:61