Fixed: Security Issue by Command Injection in DLT System.
[profile/ivi/dlt-daemon.git] / src / system / dlt-system.h
1 /**
2  * @licence app begin@
3  * Copyright (C) 2012  BMW AG
4  *
5  * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
6  *
7  * Contributions are licensed to the GENIVI Alliance under one or more
8  * Contribution License Agreements.
9  *
10  * \copyright
11  * This Source Code Form is subject to the terms of the
12  * Mozilla Public License, v. 2.0. If a  copy of the MPL was not distributed with
13  * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
14  *
15  *
16  * \author Lassi Marttala <lassi.lm.marttala@partner.bmw.de> BMW 2012
17  *
18  * \file dlt-system.c
19  * For further information see http://www.genivi.org/.
20  * @licence end@
21  */
22
23 /*******************************************************************************
24 **                                                                            **
25 **  SRC-MODULE: dlt-system.h                                                  **
26 **                                                                            **
27 **  TARGET    : linux                                                         **
28 **                                                                            **
29 **  PROJECT   : DLT                                                           **
30 **                                                                            **
31 **  AUTHOR    : Lassi Marttala <lassi.lm.marttala@partner.bmw.de>             **
32 **                                                                            **
33 **  PURPOSE   :                                                               **
34 **                                                                            **
35 **  REMARKS   :                                                               **
36 **                                                                            **
37 **  PLATFORM DEPENDANT [yes/no]: yes                                          **
38 **                                                                            **
39 **  TO BE CHANGED BY USER [yes/no]: no                                        **
40 **                                                                            **
41 *******************************************************************************/
42
43 /*******************************************************************************
44 **                      Author Identity                                       **
45 ********************************************************************************
46 **                                                                            **
47 ** Initials     Name                       Company                            **
48 ** --------     -------------------------  ---------------------------------- **
49 **  lm          Lassi Marttala             BMW                                **
50 *******************************************************************************/
51
52 #ifndef DLT_SYSTEM_H_
53 #define DLT_SYSTEM_H_
54
55 // DLT related includes.
56 #include "dlt.h"
57 #include "dlt_common.h"
58
59 // Constants
60 #define DEFAULT_CONF_FILE "/etc/dlt-system.conf"
61 #define DLT_SYSTEM_LOG_FILE_MAX 32
62 #define DLT_SYSTEM_LOG_DIRS_MAX 32
63 #define DLT_SYSTEM_LOG_PROCESSES_MAX 32
64
65 #define DLT_SYSTEM_MODE_OFF 0
66 #define DLT_SYSTEM_MODE_STARTUP 1
67 #define DLT_SYSTEM_MODE_REGULAR 2
68
69 #define MAX_LINE 1024
70
71 #define MAX_THREADS 8
72
73 // Macros
74 #define MALLOC_ASSERT(x) if(x == NULL) {\
75         fprintf(stderr, "Out of memory\n");\
76         abort();}
77
78 /**
79  * Configuration structures.
80  * Please see dlt-system.conf for explanation of all the options.
81  */
82
83 // Command line options
84 typedef struct {
85         char    *ConfigurationFileName;
86         int     Daemonize;
87 } DltSystemCliOptions;
88
89 // Configuration shell options
90 typedef struct {
91         int     Enable;
92 } ShellOptions;
93
94 // Configuration syslog options
95 typedef struct {
96         int     Enable;
97         char    *ContextId;
98         int     Port;
99 } SyslogOptions;
100
101 // Configuration journal options
102 typedef struct {
103         int     Enable;
104         char    *ContextId;
105         int     CurrentBoot;
106         int             Follow;
107         int             MapLogLevels;
108 } JournalOptions;
109
110 typedef struct {
111         int  Enable;
112         char *ContextId;
113         int  TimeStartup;
114         int  TimeDelay;
115         int  TimeoutBetweenLogs;
116         char *TempDir;
117
118         // Variable number of file transfer dirs
119         int  Count;
120         int  Compression[DLT_SYSTEM_LOG_DIRS_MAX];
121         int  CompressionLevel[DLT_SYSTEM_LOG_DIRS_MAX];
122         char *Directory[DLT_SYSTEM_LOG_DIRS_MAX];
123 } FiletransferOptions;
124
125 typedef struct {
126         int  Enable;
127
128         // Variable number of files to transfer
129         int  Count;
130         char *ContextId[DLT_SYSTEM_LOG_FILE_MAX];
131         char *Filename[DLT_SYSTEM_LOG_FILE_MAX];
132         int  Mode[DLT_SYSTEM_LOG_FILE_MAX];
133         int  TimeDelay[DLT_SYSTEM_LOG_FILE_MAX];
134 } LogFileOptions;
135
136 typedef struct {
137         int  Enable;
138         char *ContextId;
139
140         // Variable number of processes
141         int  Count;
142         char *Name[DLT_SYSTEM_LOG_PROCESSES_MAX];
143         char *Filename[DLT_SYSTEM_LOG_PROCESSES_MAX];
144         int  Mode[DLT_SYSTEM_LOG_PROCESSES_MAX];
145         int  TimeDelay[DLT_SYSTEM_LOG_PROCESSES_MAX];
146 } LogProcessOptions;
147
148 typedef struct {
149         char *ApplicationId;
150         ShellOptions                    Shell;
151         SyslogOptions                   Syslog;
152         JournalOptions                  Journal;
153         FiletransferOptions     Filetransfer;
154         LogFileOptions                  LogFile;
155         LogProcessOptions               LogProcesses;
156 } DltSystemConfiguration;
157
158 typedef struct {
159         pthread_t threads[MAX_THREADS];
160         int count;
161         int shutdown;
162 } DltSystemThreads;
163
164 /**
165  * Forward declarations for the whole application
166  */
167
168 // In dlt-system-options.c
169 int read_command_line(DltSystemCliOptions *options, int argc, char *argv[]);
170 int read_configuration_file(DltSystemConfiguration *config, char *file_name);
171
172 // In dlt-process-handling.c
173 int daemonize();
174 void start_threads(DltSystemConfiguration *config);
175 void join_threads();
176 void dlt_system_signal_handler(int sig);
177 void register_with_dlt(DltSystemConfiguration *config);
178
179 // Thread initiators:
180 void init_shell();
181 void start_syslog();
182 void start_filetransfer(DltSystemConfiguration *conf);
183 void start_logfile(DltSystemConfiguration *conf);
184 void start_logprocess(DltSystemConfiguration *conf);
185
186 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE)
187 void start_systemd_watchdog(DltSystemConfiguration *conf);
188 #endif
189
190 #if defined(DLT_SYSTEMD_JOURNAL_ENABLE)
191 void start_systemd_journal(DltSystemConfiguration *conf);
192 #endif
193
194 #endif /* DLT_SYSTEM_H_ */