3a3de6f970961aecbd7e589003ab74b71ef0b31c
[framework/security/security-server.git] / src / security-srv / include / security-server-comm.h
1 /*
2  *  security-server
3  *
4  *  Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
5  *
6  *  Contact: Bumjin Im <bj.im@samsung.com>
7  *
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License
19  *
20  */
21
22 #ifndef SECURITY_SERVER_COMM_H
23 #define SECURITY_SERVER_COMM_H
24
25 /* Message */
26 typedef struct
27 {
28         unsigned char version;
29         unsigned char msg_id;
30         unsigned short msg_len;
31 } basic_header;
32
33 typedef struct
34 {
35         basic_header basic_hdr;
36         unsigned char return_code;
37 } response_header;
38
39 /* Message Types */
40 #define SECURITY_SERVER_MSG_TYPE_COOKIE_REQUEST         0x01
41 #define SECURITY_SERVER_MSG_TYPE_COOKIE_RESPONSE        0x02
42 #define SECURITY_SERVER_MSG_TYPE_CHECK_PRIVILEGE_REQUEST        0x03
43 #define SECURITY_SERVER_MSG_TYPE_CHECK_PRIVILEGE_RESPONSE       0x04
44 #define SECURITY_SERVER_MSG_TYPE_OBJECT_NAME_REQUEST    0x05
45 #define SECURITY_SERVER_MSG_TYPE_OBJECT_NAME_RESPONSE   0x06
46 #define SECURITY_SERVER_MSG_TYPE_GID_REQUEST            0x07
47 #define SECURITY_SERVER_MSG_TYPE_GID_RESPONSE           0x08
48 #define SECURITY_SERVER_MSG_TYPE_PID_REQUEST            0x09
49 #define SECURITY_SERVER_MSG_TYPE_PID_RESPONSE           0x0a
50 #define SECURITY_SERVER_MSG_TYPE_TOOL_REQUEST           0x0b
51 #define SECURITY_SERVER_MSG_TYPE_TOOL_RESPONSE          0x0c
52 #define SECURITY_SERVER_MSG_TYPE_VALID_PWD_REQUEST      0x0d
53 #define SECURITY_SERVER_MSG_TYPE_VALID_PWD_RESPONSE     0x0e
54 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_REQUEST        0x0f
55 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_RESPONSE       0x10
56 #define SECURITY_SERVER_MSG_TYPE_RESET_PWD_REQUEST      0x11
57 #define SECURITY_SERVER_MSG_TYPE_RESET_PWD_RESPONSE     0x12
58 #define SECURITY_SERVER_MSG_TYPE_CHK_PWD_REQUEST        0x13
59 #define SECURITY_SERVER_MSG_TYPE_CHK_PWD_RESPONSE       0x14
60 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_HISTORY_REQUEST        0x15
61 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_HISTORY_RESPONSE       0x16
62 #define SECURITY_SERVER_MSG_TYPE_CHECK_PRIVILEGE_NEW_REQUEST    0x17
63 #define SECURITY_SERVER_MSG_TYPE_CHECK_PRIVILEGE_NEW_RESPONSE   0x18
64 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_MAX_CHALLENGE_REQUEST   0x19
65 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_MAX_CHALLENGE_RESPONSE  0x1a
66 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_VALIDITY_REQUEST    0x1b
67 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_VALIDITY_RESPONSE   0x1c
68 #define SECURITY_SERVER_MSG_TYPE_GENERIC_RESPONSE       0xff
69
70 /* Return code */
71 #define SECURITY_SERVER_RETURN_CODE_SUCCESS             0x00
72 #define SECURITY_SERVER_RETURN_CODE_BAD_REQUEST         0x01
73 #define SECURITY_SERVER_RETURN_CODE_AUTHENTICATION_FAILED       0x02
74 #define SECURITY_SERVER_RETURN_CODE_ACCESS_GRANTED      0x03
75 #define SECURITY_SERVER_RETURN_CODE_ACCESS_DENIED       0x04
76 #define SECURITY_SERVER_RETURN_CODE_NO_SUCH_OBJECT      0x05
77 #define SECURITY_SERVER_RETURN_CODE_NO_SUCH_COOKIE      0x06
78 #define SECURITY_SERVER_RETURN_CODE_NO_PASSWORD         0x07
79 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_EXIST              0x08
80 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_MISMATCH   0x09
81 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_MAX_ATTEMPTS_EXCEEDED      0x0a
82 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_EXPIRED    0x0b
83 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_REUSED     0x0c
84 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_RETRY_TIMER        0x0d
85 #define SECURITY_SERVER_RETURN_CODE_SERVER_ERROR        0x0e
86
87 int return_code_to_error_code(int ret_code);
88 int create_new_socket(int *sockfd);
89 int safe_server_sock_close(int client_sockfd);
90 int connect_to_server(int *fd);
91 int accept_client(int server_sockfd);
92 int authenticate_client_application(int sockfd, int *pid, int *uid);
93 int authenticate_client_middleware(int sockfd, int *pid);
94 int authenticate_developer_shell(int sockfd);
95 char *read_cmdline_from_proc(pid_t pid);
96 int send_generic_response (int sockfd, unsigned char msgid, unsigned char return_code);
97 int send_cookie(int sockfd, unsigned char *cookie);
98 int send_object_name(int sockfd, char *obj);
99 int send_gid(int sockfd, int gid);
100 int send_cookie_request(int sock_fd);
101 int send_gid_request(int sock_fd, const char* object);
102 int send_object_name_request(int sock_fd, int gid);
103 int send_privilege_check_request(int sock_fd, const char*cookie, int gid);
104 int send_privilege_check_new_request(int sock_fd,
105                                      const char *cookie,
106                                      const char *object,
107                                      const char *access_rights);
108 int recv_get_gid_response(int sockfd, response_header *hdr, int *gid);
109 int recv_get_object_name(int sockfd, response_header *hdr, char *object, int max_object_size);
110 int recv_cookie(int sockfd, response_header *hdr, char *cookie);
111 int recv_privilege_check_response(int sockfd, response_header *hdr);
112 int recv_privilege_check_new_response(int sockfd, response_header *hdr);
113 int recv_hdr(int client_sockfd, basic_header *basic_hdr);
114 int recv_check_privilege_request(int sockfd, unsigned char *requested_cookie, int *requested_privilege);
115 int recv_check_privilege_new_request(int sockfd,
116                                      unsigned char *requested_cookie,
117                                      char *object_label,
118                                      char *access_rights);
119 int send_pid_request(int sock_fd, const char*cookie);
120 int recv_pid_response(int sockfd, response_header *hdr, int *pid);
121 int recv_pid_request(int sockfd, unsigned char *requested_cookie);
122 int send_pid(int sockfd, int pid);
123 int send_launch_tool_request(int sock_fd, int argc, const char **argv);
124 int recv_generic_response(int sockfd, response_header *hdr);
125 int recv_launch_tool_request(int sockfd, int argc, char *argv[]);
126 int recv_pwd_response(int sockfd, response_header *hdr, unsigned int *current_attempts,
127         unsigned int *max_attempts, unsigned int *valid_days);
128 int send_set_pwd_request(int sock_fd, const char*cur_pwd, const char*new_pwd,
129         const unsigned int max_challenge, const unsigned int valid_period_in_days);
130 int send_set_pwd_validity_request(int sock_fd, const unsigned int valid_period_in_days);
131 int send_set_pwd_max_challenge_request(int sock_fd, const unsigned int max_challenge);
132 int send_chk_pwd_request(int sock_fd, const char*challenge);
133 int check_socket_poll(int sockfd, int event, int timeout);
134 int free_argv(char **argv, int argc);
135
136 #endif