4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Bumjin Im <bj.im@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 #ifndef SECURITY_SERVER_COMM_H
23 #define SECURITY_SERVER_COMM_H
28 unsigned char version;
30 unsigned short msg_len;
35 basic_header basic_hdr;
36 unsigned char return_code;
39 #define SECURITY_SERVER_MIDDLEWARE_USER "app"
42 #define SECURITY_SERVER_MSG_TYPE_COOKIE_REQUEST 0x01
43 #define SECURITY_SERVER_MSG_TYPE_COOKIE_RESPONSE 0x02
44 #define SECURITY_SERVER_MSG_TYPE_CHECK_PRIVILEGE_REQUEST 0x03
45 #define SECURITY_SERVER_MSG_TYPE_CHECK_PRIVILEGE_RESPONSE 0x04
46 #define SECURITY_SERVER_MSG_TYPE_OBJECT_NAME_REQUEST 0x05
47 #define SECURITY_SERVER_MSG_TYPE_OBJECT_NAME_RESPONSE 0x06
48 #define SECURITY_SERVER_MSG_TYPE_GID_REQUEST 0x07
49 #define SECURITY_SERVER_MSG_TYPE_GID_RESPONSE 0x08
50 #define SECURITY_SERVER_MSG_TYPE_PID_REQUEST 0x09
51 #define SECURITY_SERVER_MSG_TYPE_PID_RESPONSE 0x0a
52 #define SECURITY_SERVER_MSG_TYPE_TOOL_REQUEST 0x0b
53 #define SECURITY_SERVER_MSG_TYPE_TOOL_RESPONSE 0x0c
54 #define SECURITY_SERVER_MSG_TYPE_VALID_PWD_REQUEST 0x0d
55 #define SECURITY_SERVER_MSG_TYPE_VALID_PWD_RESPONSE 0x0e
56 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_REQUEST 0x0f
57 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_RESPONSE 0x10
58 #define SECURITY_SERVER_MSG_TYPE_RESET_PWD_REQUEST 0x11
59 #define SECURITY_SERVER_MSG_TYPE_RESET_PWD_RESPONSE 0x12
60 #define SECURITY_SERVER_MSG_TYPE_CHK_PWD_REQUEST 0x13
61 #define SECURITY_SERVER_MSG_TYPE_CHK_PWD_RESPONSE 0x14
62 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_HISTORY_REQUEST 0x15
63 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_HISTORY_RESPONSE 0x16
64 #define SECURITY_SERVER_MSG_TYPE_CHECK_PRIVILEGE_NEW_REQUEST 0x17
65 #define SECURITY_SERVER_MSG_TYPE_CHECK_PRIVILEGE_NEW_RESPONSE 0x18
66 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_MAX_CHALLENGE_REQUEST 0x19
67 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_MAX_CHALLENGE_RESPONSE 0x1a
68 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_VALIDITY_REQUEST 0x1b
69 #define SECURITY_SERVER_MSG_TYPE_SET_PWD_VALIDITY_RESPONSE 0x1c
70 #define SECURITY_SERVER_MSG_TYPE_SMACK_REQUEST 0x1d
71 #define SECURITY_SERVER_MSG_TYPE_SMACK_RESPONSE 0x1e
72 #define SECURITY_SERVER_MSG_TYPE_APP_GIVE_ACCESS_REQUEST 0x1f
73 #define SECURITY_SERVER_MSG_TYPE_APP_GIVE_ACCESS_RESPONSE 0x20
74 #define SECURITY_SERVER_MSG_TYPE_CHECK_PID_PRIVILEGE_REQUEST 0x21
75 #define SECURITY_SERVER_MSG_TYPE_CHECK_PID_PRIVILEGE_RESPONSE 0x22
76 #define SECURITY_SERVER_MSG_TYPE_GENERIC_RESPONSE 0xff
79 #define SECURITY_SERVER_RETURN_CODE_SUCCESS 0x00
80 #define SECURITY_SERVER_RETURN_CODE_BAD_REQUEST 0x01
81 #define SECURITY_SERVER_RETURN_CODE_AUTHENTICATION_FAILED 0x02
82 #define SECURITY_SERVER_RETURN_CODE_ACCESS_GRANTED 0x03
83 #define SECURITY_SERVER_RETURN_CODE_ACCESS_DENIED 0x04
84 #define SECURITY_SERVER_RETURN_CODE_NO_SUCH_OBJECT 0x05
85 #define SECURITY_SERVER_RETURN_CODE_NO_SUCH_COOKIE 0x06
86 #define SECURITY_SERVER_RETURN_CODE_NO_PASSWORD 0x07
87 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_EXIST 0x08
88 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_MISMATCH 0x09
89 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_MAX_ATTEMPTS_EXCEEDED 0x0a
90 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_EXPIRED 0x0b
91 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_REUSED 0x0c
92 #define SECURITY_SERVER_RETURN_CODE_PASSWORD_RETRY_TIMER 0x0d
93 #define SECURITY_SERVER_RETURN_CODE_SERVER_ERROR 0x0e
95 int return_code_to_error_code(int ret_code);
96 int create_new_socket(int *sockfd);
97 int safe_server_sock_close(int client_sockfd);
98 int connect_to_server(int *fd);
99 int accept_client(int server_sockfd);
100 int authenticate_client_application(int sockfd, int *pid, int *uid);
101 int authenticate_client_middleware(int sockfd, int *pid);
102 int get_client_gid_list(int sockfd, int ** privileges);
103 int authenticate_developer_shell(int sockfd);
104 char *read_exe_path_from_proc(pid_t pid);
105 int send_generic_response (int sockfd, unsigned char msgid, unsigned char return_code);
106 int send_cookie(int sockfd, unsigned char *cookie);
107 int send_object_name(int sockfd, char *obj);
108 int send_gid(int sockfd, int gid);
109 int send_cookie_request(int sock_fd);
110 int send_gid_request(int sock_fd, const char* object);
111 int send_object_name_request(int sock_fd, int gid);
112 int send_privilege_check_request(int sock_fd, const char*cookie, int gid);
113 int send_privilege_check_new_request(int sock_fd,
116 const char *access_rights);
117 int recv_get_gid_response(int sockfd, response_header *hdr, int *gid);
118 int recv_get_object_name(int sockfd, response_header *hdr, char *object, int max_object_size);
119 int recv_cookie(int sockfd, response_header *hdr, char *cookie);
120 int recv_privilege_check_response(int sockfd, response_header *hdr);
121 int recv_privilege_check_new_response(int sockfd, response_header *hdr);
122 int recv_hdr(int client_sockfd, basic_header *basic_hdr);
123 int recv_check_privilege_request(int sockfd, unsigned char *requested_cookie, int *requested_privilege);
124 int recv_check_privilege_new_request(int sockfd,
125 unsigned char *requested_cookie,
127 char *access_rights);
128 int send_pid_request(int sock_fd, const char*cookie);
129 int recv_pid_request(int sockfd, unsigned char *requested_cookie);
130 int send_pid(int sockfd, int pid);
131 int recv_pid_response(int sockfd, response_header *hdr, int *pid);
133 int send_smack_request(int sockfd, const char * cookie);
134 int recv_smack_request(int sockfd, unsigned char *requested_cookie);
135 int send_smack(int sockfd, char * label);
136 int recv_smack_response(int sockfd, response_header *hdr, char * label);
138 int send_pid_privilege_request(int sockfd, int pid, const char *object, const char *access_rights);
139 int recv_pid_privilege_request(int sockfd, int datasize, int * pid, char ** object, char ** access_rights);
140 int recv_pid_privilege_response(int sockfdi, response_header *hdr);
142 int send_launch_tool_request(int sock_fd, int argc, const char **argv);
143 int recv_generic_response(int sockfd, response_header *hdr);
144 int recv_launch_tool_request(int sockfd, int argc, char *argv[]);
145 int recv_pwd_response(int sockfd, response_header *hdr, unsigned int *current_attempts,
146 unsigned int *max_attempts, unsigned int *valid_days);
147 int send_set_pwd_request(int sock_fd, const char*cur_pwd, const char*new_pwd,
148 const unsigned int max_challenge, const unsigned int valid_period_in_days);
149 int send_set_pwd_validity_request(int sock_fd, const unsigned int valid_period_in_days);
150 int send_set_pwd_max_challenge_request(int sock_fd, const unsigned int max_challenge);
151 int send_chk_pwd_request(int sock_fd, const char*challenge);
152 int check_socket_poll(int sockfd, int event, int timeout);
153 int free_argv(char **argv, int argc);
154 int send_valid_pwd_request(int sock_fd);
155 int send_reset_pwd_request(int sock_fd,
157 const unsigned int max_challenge,
158 const unsigned int valid_period_in_days);
159 int send_set_pwd_history_request(int sock_fd, int num);
160 int send_app_give_access(int sock_df, const char *customer_label, int customer_pid);