File: system.h

package info (click to toggle)
cyphesis-cpp 0.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,752 kB
  • sloc: cpp: 94,194; xml: 40,196; python: 8,717; sh: 4,164; makefile: 1,968; ansic: 753
file content (83 lines) | stat: -rw-r--r-- 2,508 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2000-2003 Alistair Riddoch
//
// This program 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 2 of the License, or
// (at your option) any later version.
// 
// This program 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 this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA


#ifndef COMMON_SYSTEM_H
#define COMMON_SYSTEM_H

#include <skstream/skstreamconfig.h>

#include <cstdlib>

// These two will not be transmitted to our parent, so we don't need to
// convery any data
#define EXIT_CONFIG_ERROR     (EXIT_FAILURE)
#define EXIT_FORK_ERROR       (EXIT_FAILURE)
#define EXIT_SECURITY_ERROR   (EXIT_FAILURE)

// These exit status values might be passed back to our waiting parent, so we
// can embed information about the nature of the error.
#define EXIT_DATABASE_ERROR   (EXIT_FAILURE | 1 << 1)
#define EXIT_SOCKET_ERROR     (EXIT_FAILURE | 1 << 2)
#define EXIT_PORT_ERROR       (EXIT_FAILURE | 1 << 3)

// Magic number returned by the security check if everything is okay.
#define SECURITY_OKAY         (0xff7a64e1)

#include <string>

const std::string get_hostname();
int socket_linger(SOCKET_TYPE, int);
int socket_client_send_credentials(int fd);

unsigned int security_init();
unsigned int security_check();
unsigned int security_setup();
void reduce_priority(int);
void interactive_signals();
void daemon_signals();
int daemonise();
void running();

std::string create_session_username();

void hash_password(const std::string & pwd, const std::string & salt,
                   std::string & hash);

void encrypt_password(const std::string & pwd, std::string & hash);
int check_password(const std::string & pwd, const std::string & hash);

int getfiletime(const std::string & filename, time_t & t);

void getinstallprefix();

#ifdef _WIN32

// int gettimeofday(struct timeval * tv, struct timezone * tz);

#else // _WIN32

#include <unistd.h>

static inline int closesocket(int sock)
{   
    return ::close(sock);
}

#endif // _WIN32

#endif // COMMON_SYSTEM_H