Correct security_server_reset_pwd description in header.
[platform/core/security/security-server.git] / src / include / security-server.h
1 /*
2  *  security-server
3  *
4  *  Copyright (c) 2000 - 2011 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_H
23 #define SECURITY_SERVER_H
24
25 #include <sys/types.h>
26 #include <privilege-control.h>
27
28 /**
29  * @file    security-server.h
30  * @version 1.0
31  * @brief   This file contains APIs of the Security Server
32 */
33
34 /**
35  * @defgroup SecurityFW
36  * @{
37  *
38  * @defgroup SECURITY_SERVER Security Server
39  * @version  1.0
40  * @brief    Security Server client library functions
41  *
42 */
43
44 /**
45  * @addtogroup SECURITY_SERVER
46  * @{
47 */
48
49 /*
50  * ====================================================================================================
51  * <tt>
52  *
53  * Revision History:
54  *
55  *  -- Company Name -- | Modification Date | Description of Changes
56  *  -----------------------------------------------------------------------
57  *   --- Samsung ------ | --- 2010-07-25 -- | First created
58  *
59  *    </tt>
60  */
61
62 /**
63  * \name Return Codes
64  * exported by the foundation API.
65  * result codes begin with the start error code and extend into negative direction.
66  * @{
67 */
68 #define SECURITY_SERVER_API_SUCCESS 0
69 /*! \brief   indicating the result of the one specific API is successful */
70 #define SECURITY_SERVER_API_ERROR_SOCKET -1
71
72 /*! \brief   indicating the socket between client and Security Server has been failed  */
73 #define SECURITY_SERVER_API_ERROR_BAD_REQUEST -2
74
75 /*! \brief   indicating the response from Security Server is malformed */
76 #define SECURITY_SERVER_API_ERROR_BAD_RESPONSE -3
77
78 /*! \brief   indicating the transmitting request has been failed */
79 #define SECURITY_SERVER_API_ERROR_SEND_FAILED -4
80
81 /*! \brief   indicating the receiving response has been failed */
82 #define SECURITY_SERVER_API_ERROR_RECV_FAILED -5
83
84 /*! \brief   indicating requesting object is not exist */
85 #define SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT -6
86
87 /*! \brief   indicating the authentication between client and server has been failed */
88 #define SECURITY_SERVER_API_ERROR_AUTHENTICATION_FAILED -7
89
90 /*! \brief   indicating the API's input parameter is malformed */
91 #define SECURITY_SERVER_API_ERROR_INPUT_PARAM -8
92
93 /*! \brief   indicating the output buffer size which is passed as parameter is too small */
94 #define SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL -9
95
96 /*! \brief   indicating system  is running out of memory state */
97 #define SECURITY_SERVER_API_ERROR_OUT_OF_MEMORY -10
98
99 /*! \brief   indicating the access has been denied by Security Server */
100 #define SECURITY_SERVER_API_ERROR_ACCESS_DENIED -11
101
102 /*! \brief   indicating Security Server has been failed for some reason */
103 #define SECURITY_SERVER_API_ERROR_SERVER_ERROR -12
104
105 /*! \brief   indicating given cookie is not exist in the database  */
106 #define SECURITY_SERVER_API_ERROR_NO_SUCH_COOKIE -13
107
108 /*! \brief   indicating there is no phone password set  */
109 #define SECURITY_SERVER_API_ERROR_NO_PASSWORD -14
110
111 /*! \brief   indicating password exists in system  */
112 #define SECURITY_SERVER_API_ERROR_PASSWORD_EXIST -15
113
114 /*! \brief   indicating password mismatch  */
115 #define SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH -16
116
117 /*! \brief   indicating password retry timeout is not occurred yet  */
118 #define SECURITY_SERVER_API_ERROR_PASSWORD_RETRY_TIMER -17
119
120 /*! \brief   indicating password retry timeout is not occurred yet  */
121 #define SECURITY_SERVER_API_ERROR_PASSWORD_MAX_ATTEMPTS_EXCEEDED -18
122
123 /*! \brief   indicating password retry timeout is not occurred yet  */
124 #define SECURITY_SERVER_API_ERROR_PASSWORD_EXPIRED -19
125
126 /*! \brief   indicating password retry timeout is not occurred yet  */
127 #define SECURITY_SERVER_API_ERROR_PASSWORD_REUSED -20
128
129 /*! \brief   indicating getting smack label from socket failed  */
130 #define SECURITY_SERVER_API_ERROR_GETTING_SOCKET_LABEL_FAILED -21
131
132 /*! \brief   indicating getting smack label from file failed  */
133 #define SECURITY_SERVER_API_ERROR_GETTING_FILE_LABEL_FAILED -22
134
135 /*! \brief   indicating setting smack label for file failed  */
136 #define SECURITY_SERVER_API_ERROR_SETTING_FILE_LABEL_FAILED -23
137
138 /*! \brief   indicating file already exists  */
139 #define SECURITY_SERVER_API_ERROR_FILE_EXIST -24
140
141 /*! \brief   indicating file does not exist  */
142 #define SECURITY_SERVER_API_ERROR_FILE_NOT_EXIST -25
143
144 /*! \brief   indicating file open error  */
145 #define SECURITY_SERVER_API_ERROR_FILE_OPEN_FAILED -26
146
147 /*! \brief   indicating file creation error  */
148 #define SECURITY_SERVER_API_ERROR_FILE_CREATION_FAILED -27
149
150 /*! \brief   indicating file deletion error  */
151 #define SECURITY_SERVER_API_ERROR_FILE_DELETION_FAILED -28
152
153 /*! \brief   indicating the error with unknown reason */
154 #define SECURITY_SERVER_API_ERROR_UNKNOWN -255
155 /** @}*/
156
157
158 #ifdef __cplusplus
159 extern "C" {
160 #endif
161
162
163
164 /**
165  * \par Description:
166  * Retreives Linux group ID from object name which is passed by parameter
167  *
168  * \par Purpose:
169  * This API may be used before security_server_check_privilege() API by middleware daemon to get group ID of a specific object.
170  *
171  * \par Typical use case:
172  * In middleware daemon, before checking privilege of a service the daemon need to know the GID of the service. This API support the functionality.
173  *
174  * \par Method of function operation:
175  * Opens /etc/group file and searches the object name as group name. If there is matching result, returns GID as integer
176  *
177  * \par Sync (or) Async:
178  * This is a Synchronous API.
179  *
180  * \par Important notes:
181  * - This API is only allowed to be called by pre-defined middleware daemon
182  *
183  * \param[in] object Name of the object which is kwnown by the caller.
184  *
185  * \return matching gid (positive integer) on success, or negative error code on error.
186  *
187  * \par Prospective clients:
188  * Inhouse middleware
189  *
190  * \par Known issues/bugs:
191  * None
192  *
193  * \pre None
194  *
195  * \post None
196  *
197  * \see /etc/group,
198  * security_server_get_object_name(), security_server_check_privilege()
199  *
200  * \remarks None
201  *
202  * \par Sample code:
203  * \code
204  * #include <security-server.h>
205  * ...
206  * int retval;
207  *
208  * // You have to make sure that  the input param '*object' is defined in the platform
209  * retval = security_server_get_gid("telephony_makecall");
210  * if(retval < 0)
211  * {
212  *      printf("%s", "Error has occurred\n");
213  *      exit(0);
214  * }
215  * ...
216  * \endcode
217  *
218  * Access to this function requires SMACK rule: "<app_label> security-server::api-get-gid w"
219 */
220 int security_server_get_gid(const char *object);
221
222 /**
223  * \par Description:
224  * Request cookie to the Security Server. Cookie is a random bit stream which is used as ticket for user space object.
225  *
226  * \par Purpose:
227  * This API may be used by application and client middleware process to get access to middleware daemons.
228  *
229  * \par Typical use case:
230  * When an application process wants to get access to some middleware object, first call this API to get cookie value. Then it calls the service API to get service with the cookie value.
231  *
232  * \par Method of function operation:
233  * Caller process just send request message. Security Server checks proc file system to get list of gIDs the caller belongs, then create a random cookie and responds to caller.
234  *
235  * \par Sync (or) Async:
236  * This is a Synchronous API.
237  *
238  * \par Important notes:
239  * Cookie needs to be stored relatively secure.
240  *
241  * \param[out] cookie Place holder for cookie value.
242  * \param[in] max_cookie Allocated byte size of parameter "cookie".
243  *
244  * \return 0 on success, or negative error code on error.
245  *
246  * \par Prospective clients:
247  * Any process
248  *
249  * \par Known issues/bugs:
250  * None
251  *
252  * \pre output parameter cookie must be malloced before calling this API not to make memory curruption
253  * Size of the cookie can be retrieved by security_server_get_cookie_size() API.
254  *
255  * \post None
256  *
257  * \see security_server_check_privilege(), security_server_get_cookie_size()
258  *
259  * \remarks None
260  *
261  * \par Sample code:
262  * \code
263  * #include <security-server.h>
264  * ...
265  * int retval;
266  * size_t cookie_size;
267  * cookie_size = security_server_get_cookie_size();
268  * unsigned char cookie[cookie_size];
269  *
270  * // Call the API
271  * retval = security_server_request_cookie(cookie, cookie_size);
272  * if(retval < 0)
273  * {
274  *      printf("%s", "Error has occurred\n");
275  *      exit(0);
276  * }
277  * ...
278  * \endcode
279  *
280  * Access to this function not requires SMACK rule
281 */
282 int security_server_request_cookie(char *cookie, size_t bufferSize);
283
284
285
286 /**
287  * \par Description:
288  * This API gets the cookie's byte size which is issued by Security Server.
289  *
290  * \par Purpose:
291  * This API may be used by application and middleware process to get size of cookie before getting and storing cookie value.
292  *
293  * \par Typical use case:
294  * When an application process wants to get access to some middleware object, first call this API to get cookie value. Then it calls the service API to get service with the cookie value.
295  *
296  * \par Method of function operation:
297  * This API just returns pre-defined integer value as cookie size.
298  *
299  * \par Sync (or) Async:
300  * This is a Synchronous API.
301  *
302  * \par Important notes:
303  * None
304  *
305  * \return Always returns byte size of the cookie.
306  *
307  * \par Prospective clients:
308  * Any process
309  *
310  * \par Known issues/bugs:
311  * None
312  *
313  * \pre None
314  *
315  * \post None
316  *
317  * \see security_server_request_cookie()
318
319  * \remarks None
320  *
321  * \par Sample code:
322  * \code
323  * #include <security-server.h>
324  * ...
325  * int retval;
326  * size_t cookie_size;
327  *
328  * // API calling
329  * cookie_size = security_server_get_cookie_size();
330  * unsigned char cookie[cookie_size];
331  *
332  * char objectname[20];
333  * retval = security_server_request_cookie(cookie, cookie_size);
334  * if(retval < 0)
335  * {
336  *      printf("%s", "Error has occurred\n");
337  *      exit(0);
338  * }
339  * ...
340  * \endcode
341  *
342  * Access to this function not requires SMACK rule
343 */
344 int security_server_get_cookie_size(void);
345
346
347
348 /**
349  * \par Description:
350  * This API checks the cookie is allowed to access to given object.
351  *
352  * \par Purpose:
353  * This API may be used by middleware process to ask the client application has privilege for the given object.
354  *
355  * \par Typical use case:
356  * When middleware server receives request message from client application process with cookie value, it calls this API to ask to Security Server that the client application has privilege to access the service. If yes, then the middleware daemon can continue service, if not, it can return error to client application.
357  *
358  * \par Method of function operation:
359  * When Security Server receives this request, it searches cookie database and check the cookie is there, if there is matching cookie, then it checks the cookie has the privilege. It returns success if there is match, if not, it returns error.
360  *
361  * \par Sync (or) Async:
362  * This is a Synchronous API.
363  *
364  * \par Important notes:
365  * Cookie value needs to be stored relatively secure\n
366  * Privilege should be pre-defined by Platform design.
367  *
368  * \param[in] cookie Received cookie value from client application
369  * \param[in] privilege Object group ID which the client application wants to access
370  *
371  * \return 0 on success, or negative error code on error.
372  *
373  * \par Prospective clients:
374  * Only pre-defiend middleware daemons
375  *
376  * \par Known issues/bugs:
377  * None
378  * \pre None
379  *
380  * \post None
381  *
382  * \see security_server_request_cookie(), security_server_get_gid(), security_server_get_cookie_size()
383  *
384  * \remarks None
385  *
386  * \par Sample code:
387  * \code
388  * #include <security-server.h>
389  * ...
390  * int retval;
391  * size_t cookie_size;
392  * int call_gid;
393  * cookie_size = security_server_get_cookie_size();
394  * unsigned char recved_cookie[cookie_size];
395  *
396  * ... // Receiving request with cookie
397  *
398  * call_gid = security_server_get_gid("telephony_makecall");
399  * retval = security_server_check_privilege(recved_cookie, (gid_t)call_gid);
400  * if(retval < 0)
401  * {
402  *      if(retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED)
403  *      {
404  *              printf("%s", "access has been denied\n");
405  *              return;
406  *      }
407  *      printf("%s", "Error has occurred\n");
408  * }
409  * ...
410  *
411  * \endcode
412  *
413  * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
414 */
415 int security_server_check_privilege(const char *cookie, gid_t privilege);
416
417 int security_server_check_privilege_by_cookie(const char *cookie,
418                                               const char *object,
419                                               const char *access_rights);
420
421 /**
422  * \par Description:
423  * This API searchs a cookie value and returns PID of the given cookie.
424  *
425  * \par Purpose:
426  * This API may be used by middleware process to ask the client application has privilege for the given object.
427  *
428  * \par Typical use case:
429  * In some cases, a middleware server wants to know PID of the application process. But if the middleware server uses non-direct IPC such as dbus, it's nearly impossible to know and guarantee peer PID. By using this API, the middleware server can retrieve a PID of the requesting process.
430  *
431  * \par Method of function operation:
432  * When Security Server receives this request, it searches cookie database and check the cookie is there, if there is matching cookie, then it returns corresponding PID for the cookie.
433  *
434  * \par Sync (or) Async:
435  * This is a Synchronous API.
436  *
437  * \par Important notes:
438  * Cookie value needs to be stored relatively secure\n
439  * This API is abled to be called only by pre-defined middleware servers.
440  *
441  * \param[in] cookie Received cookie value from client application. Cookie is not a null terminated human readable string. Make sure you're code doesn't have any string related process on the cookie.
442  *
443  * \return positive integer on success meaning the PID, 0 means the cookie is for root process, negative integer error code on error.
444  *
445  * \par Prospective clients:
446  * Only pre-defined middleware daemons
447  *
448  * \par Known issues/bugs:
449  * None
450  *
451  * \pre None
452  *
453  * \post None
454  *
455  * \see security_server_request_cookie(), security_server_get_cookie_size()
456  *
457  * \remarks the cookie is not a null terminated string. Cookie is a BINARY byte stream of such length which can be retrieved by security_server_get_cookie_size() API.
458  * Therefore, please do not use strcpy() family to process cookie value. You MUST use memcpy() function to process cookie value.
459  * You also have to know that the cookie value doesn't carry any null terminator. So you don't need to allocate 1 more byte of the cookie size.
460  *
461  * \par Sample code:
462  * \code
463  * #include <security-server.h>
464  * ...
465  * int peerpid;
466  * size_t cookie_size;
467  * gid_t call_gid;
468  * cookie_size = security_server_get_cookie_size();
469  * unsigned char recved_cookie[cookie_size];
470  *
471  * ... // Receiving request with cookie
472  *
473  * peerpid = security_server_get_cookie_pid(recved_cookie);
474  * if(peerpid < 0)
475  * {
476  *      printf("%s", "Error has occurred\n");
477  * }
478  * ...
479  *
480  * \endcode
481  *
482  * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
483 */
484 int security_server_get_cookie_pid(const char *cookie);
485
486
487
488 /**
489  * \par Description:
490  * This API checks phone validity of password, to check existance, expiration, remaining attempts.
491  *
492  * \par Purpose:
493  * This API should be used by applications which needs phone password check. Caller application should behave properly after this API call.
494  *
495  * \par Typical use case:
496  * Lock screen can call this API before it shows unlock screen, if there is password, lock screen can show password input UI, if not, lock screen can show just unlock screen
497  *
498  * \par Method of function operation:
499  * Sends a validate request to security server and security server replies with password information.
500  *
501  * \par Sync (or) Async:
502  * This is a Synchronous API.
503  *
504  * \par Important notes:
505  * Password file should be stored safely. The password file will be stored by security server and only allowed itself to read/write, and data is will be securely hashed\n
506  *
507  * \param[out] current_attempts Number of password check missed attempts.
508  * \param[out] max_attempts Number of maximum attempts that the password locks. 0 means infinite
509  * \param[out] valid_secs Remaining time in second which represents this password will be expired. 0xFFFFFFFF means infinite
510  *
511  * \return 0 if there is no password set, other negative integer error code on error.
512  *
513  * \par Prospective clients:
514  * Applications which can unlock UI
515  *
516  * \par Known issues/bugs:
517  * None
518  *
519  * \pre None
520  *
521  * \post None
522  *
523  * \see security_server_set_pwd(), security_server_chk_pwd()
524  *
525  * \remarks If password file is corrupted or accidentally deleted, this API may not synchronized with security-server, but security-server will check file status on next request.
526  *
527  * \par Sample code:
528  * \code
529  * #include <security-server.h>
530  * ...
531  * int ret;
532  * unsigned int attempt, max_attempt, expire_sec;
533  *
534  * ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
535  * if(is_pwd_set == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
536  * {
537  *      printf("%s", "There is no password exists\n");
538  * }
539  * else if(is_pwd_set == SECURITY_SERVER_SUCCESS && expire_sec > 0 && attempt < max_attempts)
540  * {
541  *      printf("%s", "Password is valid by now\n");
542  * }
543  * else
544  * {
545  *      printf("%s", "Something wrong\n");
546  * }
547  * ...
548  *
549  * \endcode
550  *
551  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-check w"
552 */
553 int security_server_is_pwd_valid(unsigned int *current_attempts,
554                                  unsigned int *max_attempts,
555                                  unsigned int *valid_secs);
556
557
558
559 /**
560  * \par Description:
561  * This API sets phone password only if current password matches.
562  *
563  * \par Purpose:
564  * This API should be used by setting application when the user changes his/her phone password.
565  *
566  * \par Typical use case:
567  * Setting application calls this API to change phone password. Caller needs current password to grant the change.
568  *
569  * \par Method of function operation:
570  * Sends current password with new password to security-server, security-server checks current password and set new password to current only when current password is correct. Caller application can determine maximum number of attempts and expiration time in days
571  *
572  * \par Sync (or) Async:
573  * This is a Synchronous API.
574  *
575  * \par Important notes:
576  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
577  *
578  * \param[in] cur_pwd Null terminated current password string. It can be NULL pointer if there is no password set yet - by calling security_server_is_pwd_empty()
579  * \param[in] new_pwd Null terminated new password string. It must not a NULL pointer.
580  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
581  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
582  *
583  * \return 0 on success, negative integer error code on error.
584  *
585  * \par Prospective clients:
586  * Platform's THE ONLY setting application and some dedicated privileged processes
587  *
588  * \par Known issues/bugs:
589  * None
590  *
591  * \pre None
592  *
593  * \post None
594  *
595  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
596  *
597  * \remarks Only setting application can call this API. The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file corruption.
598  * \remarks If current password exists and it's expired, or max attempts reached, you cannot call this API. You have to call security_server_reset_pwd() API.
599  *
600  * \par Sample code:
601  * \code
602  * #include <security-server.h>
603  * ...
604  * int ret;
605  * unsigned int attempt, max_attempt, expire_sec;
606  *
607  * ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
608  * if(is_pwd_set == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
609  * {
610  *      printf("%s", "There is no password exists\n");
611  *      ret = security_server_set_pwd(NULL, "this_is_new_pwd", 20, 365);
612  *      if(ret != SECURITY_SERVER_API_SUCCESS)
613  *      {
614  *              printf("%s", "we have error\n");
615  *              ...
616  *      }
617  * }
618  * else if(is_pwd_set == SECURITY_SERVER_SUCCESS && expire_sec > 0 && attempt < max_attempts)
619  * {
620  *      printf("%s", "Password is valid by now\n");
621  *      ret = security_server_set_pwd("this_is_current_pwd", "this_is_new_pwd", 20, 365);
622  *      if(ret != SECURITY_SERVER_API_SUCCESS)
623  *      {
624  *              printf("%s", "we have error\n");
625  *              ...
626  *      }
627  * }
628  * else
629  * {
630  *      printf("%s", "Something wrong\n");
631  * }
632  * ...
633  *
634  * \endcode
635  *
636  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
637 */
638 int security_server_set_pwd(const char *cur_pwd,
639                             const char *new_pwd,
640                             const unsigned int max_challenge,
641                             const unsigned int valid_period_in_days);
642
643
644 /**
645  * \par Description:
646  * This API sets validity period for currently setup password.
647  *
648  * \par Purpose:
649  * This API should be used by Enterprise authorities to modify password policy. To be used only with valid password setup.
650  *
651  * \par Typical use case:
652  * Authorized application calls this API to change current passwords validity when password policy needs to be changed.
653  *
654  * \par Method of function operation:
655  * Function attempts to find currently set password and changes its current validity to passed number of days. Retry counter for the password is reset to zero.
656  * If there is no password set, function returns proper error code.
657  *
658  * \par Sync (or) Async:
659  * This is a Synchronous API.
660  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
661  *
662  * \return 0 on success, negative integer error code on error.
663  *
664  * \par Prospective clients:
665  * Platform's THE ONLY setting application and some dedicated privileged processes
666  *
667  * \par Known issues/bugs:
668  * Identifying calling peer is not ready yet, should be based on SMACK somehow.
669  *
670  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
671  *
672  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
673  */
674 int security_server_set_pwd_validity(const unsigned int valid_period_in_days);
675
676
677 /**
678  * \par Description:
679  * This API sets maximum number of attempts for currently setup password.
680  *
681  * \par Purpose:
682  * This API should be used by Enterprise authorities to modify password policy. To be used only with valid password setup.
683  *
684  * \par Typical use case:
685  * Authorized application calls this API to change current passwords max attempt number when password policy needs to be changed.
686  *
687  * \par Method of function operation:
688  * Function attempts to find currently set password and changes its max attempt number to passed one. Retry counter for the password is reset to zero.
689  * If there is no password set, function returns proper error code.
690  *
691  * \par Sync (or) Async:
692  * This is a Synchronous API.
693  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
694  *
695  * \return 0 on success, negative integer error code on error.
696  *
697  * \par Prospective clients:
698  * Platform's THE ONLY setting application and some dedicated privileged processes
699  *
700  * \par Known issues/bugs:
701  * Identifying calling peer is not ready yet, should be based on SMACK somehow.
702  *
703  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
704  *
705  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
706  */
707 int security_server_set_pwd_max_challenge(const unsigned int max_challenge);
708
709 /**
710  * \par Description:
711  * This API sets phone password without performing any checks connected with provided password. It
712  * should be used only if current password is invalid or user forgot the password.
713  *
714  * \par Purpose:
715  * This API should be used by setting application or dedicated processes when the user changes his/her phone password.
716  *
717  * \par Typical use case:
718  * User forgets the password. He calls emergency manager(auto or manual)  for reset password. Emergency manager calls this API and reset phone password.
719  *
720  * \par Method of function operation:
721  * Resetting phone password with input string without any matching current password. Function does
722  * no checks before password replacement (expiration time check, currently set password checks,
723  * history check and attempt count check are skipped).
724  *
725  * \par Sync (or) Async:
726  * This is a Synchronous API.
727  *
728  * \par Important notes:
729  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
730  *
731  * \param[in] new_pwd Null terminated new password string. It must not a NULL pointer.
732  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
733  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
734  *
735  * \return 0 on success, negative integer error code on error.
736  *
737  * \par Prospective clients:
738  * Platform's THE ONLY setting application and some dedicated privileged processes
739  *
740  * \par Known issues/bugs:
741  * None
742  *
743  * \pre None
744  *
745  * \post None
746  *
747  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_set_pwd()
748  *
749  * \remarks Only dedicated applications can call this API. The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file corruption.
750  *
751  * \par Sample code:
752  * \code
753  * #include <security-server.h>
754  * ...
755  * int ret;
756  *
757  *      ret = security_server_reset_pwd("this_is_new_pwd", 20, 365);
758  *      if(retval != SECURITY_SERVER_API_SUCCESS)
759  *      {
760  *              printf("%s", "we have error\n");
761  *              ...
762  *      }
763  * ...
764  *
765  * \endcode
766  *
767  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-reset w"
768 */
769 int security_server_reset_pwd(const char *new_pwd,
770                               const unsigned int max_challenge,
771                               const unsigned int valid_period_in_days);
772
773 /**
774  * \par Description:
775  * This API compares stored phone password with challenged input value.
776  *
777  * \par Purpose:
778  * This API should be used by applications which has phone UI lock capability.
779  *
780  * \par Typical use case:
781  * Lock screen calls this API after user typed phone password and pressed okay.
782  *
783  * \par Method of function operation:
784  * Sends challenged password to security-server, security-server compares hashed current password and hashed challenged password.
785  *
786  * \par Sync (or) Async:
787  * This is a Synchronous API.
788  *
789  * \par Important notes:
790  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
791  *
792  * \param[in] challenge Null terminated challenged password string. It must not a NULL pointer.
793  * \param[out] current_attempts Number of password check missed attempts.
794  * \param[out] max_attempts Number of maximum attempts that the password locks. 0 means infinite
795  * \param[out] valid_secs Remaining time in second which represents this password will be expired. 0xFFFFFFFF means infinite
796  *
797  * \return 0 on success, negative integer error code on error.
798  *
799  * \par Prospective clients:
800  * Applications which has phone UI lock feature.
801  *
802  * \par Known issues/bugs:
803  * None
804  *
805  * \pre None
806  *
807  * \post None
808  *
809  * \see security_server_is_pwd_valid(), security_server_set_pwd()
810  *
811  * \remarks The password file will be acces controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
812  *
813  * \par Sample code:
814  * \code
815  * #include <security-server.h>
816  * ...
817  * int retval;
818  * unsigned int attempt, max_attempt, expire_sec;
819  *
820  * retval = security_server_chk_pwd("is_this_password", &attmpt, &max_attempt, &expire_sec);
821  * if(retval == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH)
822  * {
823  *      printf("%s", "Oh you typed wrong password\n");
824  *      ...
825  * }
826  * else if(retval == SECURITY_SERVER_API_SUCCESS)
827  * {
828  *      printf("%s", "You remember your password.\n");
829  *      ...
830  * }
831  * ...
832  *
833  * \endcode
834  *
835  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-check w"
836 */
837 int security_server_chk_pwd(const char *challenge,
838                             unsigned int *current_attempt,
839                             unsigned int *max_attempt,
840                             unsigned int *valid_secs);
841
842
843 /**
844  * \par Description:
845  * This API set the number of password history which should be maintained. Once this number set, user cannot reuse recent number of passwords which is described in this history value
846  *
847  * \par Purpose:
848  * This API should be used only by dedicated process in the platform.
849  *
850  * \par Typical use case:
851  * Enterprise manager calls this API when the enterprise wants to enforce harder password policy.
852  *
853  * \par Method of function operation:
854  * When enterprise manager (MDM) is trying to change the security policy for phone password, it calls this API background to change the history policy.
855  *
856  * \par Sync (or) Async:
857  * This is a Synchronous API.
858  *
859  * \par Important notes:
860  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
861  *
862  * \param[in] history_size Number of history to be checked when user tries to change password. Maximum is currently 50
863  *
864  * \return 0 on success, negative integer error code on error.
865  *
866  * \par Prospective clients:
867  * MDM client, Enterprise manager.
868  *
869  * \par Known issues/bugs:
870  * None
871  *
872  * \pre None
873  *
874  * \post None
875  *
876  * \see security_server_set_pwd()
877  *
878  * \remarks The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
879  *
880  * \par Sample code:
881  * \code
882  * #include <security-server.h>
883  * ...
884  * int retval;
885  *
886  * ret = security_server_set_pwd_history(100);
887  *      if(ret != SECURITY_SERVER_API_SUCCESS)
888  *      {
889  *              printf("%s", "You have error\n");
890  *              ...
891  *      }
892  * ...
893  *
894  * \endcode
895  *
896  * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
897 */
898 int security_server_set_pwd_history(int history_size);
899
900 /*
901  * This function allows to get process SMACK label by passing cookie assigned
902  * to process. Function returns pointer to allocated buffer with label.
903  * User has to free the buffer after using.
904  *
905  * \param[in] Pointer to cookie
906  *
907  * \return Pointer to SMACK label or NULL
908  *
909  * \par For free label use free(), label allocated by calloc()
910  *      User responsibility is to free resource.
911  *
912  * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
913  */
914 char *security_server_get_smacklabel_cookie(const char *cookie);
915
916 /*
917  * This function allows to get process SMACK label by passing socket descriptor.
918  * Function returns pointer to allocated buffer with label.
919  * User has to free the buffer after using.
920  *
921  * \param[in] Socket descriptor
922  *
923  * \return Pointer to SMACK label or NULL
924  *
925  * \par For free label use free(), label allocated by calloc().
926  *      User responsibility is to free resource.
927  *
928  * Access to this function not requires SMACK rule
929  */
930 char *security_server_get_smacklabel_sockfd(int fd);
931
932 /*
933  * This function will give permissions "rwxat" from
934  * (subject) customer_label to caller process (object).
935  * Object label will be extracted from socket.
936  *
937  * Access to this function requires SMACK rule: "<app_label> security-server::api-data-share w"
938  * */
939 int security_server_app_give_access(const char *customer_label, int customer_pid);
940
941 /*
942  * This function allows middleware to check privileges of process with specified PID or socket
943  * file descriptor.
944  * Service is able to check process access to the specified object label with specified
945  * access rights.
946  *
947  * \param[in] PID id of process or SOCKFD socket file descriptor to be checked
948  * \param[in] SMACK object label
949  * \param[in] SMACK access rights to be checked
950  *
951  * \return Privilege confirm or error code
952  * SECURITY_SERVER_SUCCESS - on success
953  *
954  * Access to this function requires SMACK rule: "<app_label> security-server::api-privilege-by-pid w"
955  */
956 int security_server_check_privilege_by_pid(int pid, const char *object, const char *access_rights);
957
958 int security_server_check_privilege_by_sockfd(int sockfd,
959                                               const char *object,
960                                               const char *access_rights);
961 /*
962  * This function allows middleware to enable permissions for specified app_id.
963  *
964  * \param[in] Application ID
965  * \param[in] Application type defined in enum at the beginning of this file
966  * \param[in] Permissions list
967  * \param[in] Persistent
968  *
969  * \return SECURITY_SERVER_SUCCESS on success or error code on fail
970  *
971  * Access to this function requires SMACK rule: "<app_label> security-server::api-app-permissions w"
972  */
973 int security_server_app_enable_permissions(const char *app_id, app_type_t app_type, const char **perm_list, int persistent);
974
975 /*
976  * This function allows middleware to disable permissions for specified app_id.
977  *
978  * \param[in] Application ID
979  * \param[in] Application type defined in enum at the beginning of this file
980  * \param[in] Permissions list
981  *
982  * \return SECURITY_SERVER_SUCCESS on success or error code on fail
983  *
984  * Access to this function requires SMACK rule: "<app_label> security-server::api-app-permissions w"
985  */
986 int security_server_app_disable_permissions(const char *app_id, app_type_t app_type, const char **perm_list);
987
988 /*
989  * This function allows middleware to get UID assigned to cookie
990  *
991  * \param[in] Cookie
992  * \param[out] Handler to store UID
993  *
994  * \return SECURITY_SERVER_SUCCESS on success or error code on fail
995  *
996  * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
997  */
998 int security_server_get_uid_by_cookie(const char *cookie, uid_t *uid);
999
1000 /*
1001  * This function allows middleware to check if an app has the specified privilege
1002  * enabled.
1003  *
1004  * \param[in] Application ID
1005  * \param[in] Application type
1006  * \param[in] Privilege name
1007  * \param[out] Handler to store the result. It is set to 1 (true) if privilege is enabled, 0 (false) otherwise
1008  *
1009  * \return SECURITY_SERVER_SUCCESS on success or error code on fail
1010  *
1011  * Access to this function requires SMACK rule: "<app_label> security-server::api-app-privilege-by-name w"
1012  */
1013 int security_server_app_has_privilege(const char *app_id,
1014                                       app_type_t app_type,
1015                                       const char *privilege_name,
1016                                       int *result);
1017
1018 /*
1019  * This function allows middleware to check if caller app has the specified privilege
1020  * enabled. Security Server gets caller app smack label from the IPC socket.
1021  *
1022  * \param[in] Application type
1023  * \param[in] Privilege name
1024  * \param[out] Handler to store the result. It is set to 1 (true) if privilege is enabled, 0 (false) otherwise
1025  *
1026  * \return SECURITY_SERVER_SUCCESS on success or error code on fail
1027  *
1028  * Access to this function requires SMACK rule: "<app_label> security-server::api-app-privilege-by-name w"
1029  */
1030 int security_server_app_caller_has_privilege(app_type_t app_type,
1031                                              const char *privilege_name,
1032                                              int *result);
1033
1034 /*
1035  * This function allows middleware to get GID assigned to cookie
1036  *
1037  * \param[in] Cookie
1038  * \param[out] Handler to store GID
1039  *
1040  * \return SECURITY_SERVER_SUCCESS on success or error code on fail
1041  *
1042  * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
1043  */
1044 int security_server_get_gid_by_cookie(const char *cookie, gid_t *gid);
1045
1046 /*
1047  * This function allows to create, if doesn't exist, or open existing file by
1048  * Security Server on behalf of calling process in secured directory.
1049  *
1050  * \param[in] File name to create/open
1051  * \param[out] File descriptor
1052  *
1053  * \return SECURITY_SERVER_API_SUCCESS on success or error code on fail
1054  *
1055  * Access to this function requires SMACK rule: "<app_label> security-server::api-open-for w"
1056  */
1057 int security_server_open_for(const char *filename, int *fd) __attribute__((deprecated));
1058
1059 /*
1060  * This function allows to create, if doesn't exist, file by Security Server on
1061  * behalf of calling process in secured directory. File gets smack label of
1062  * designated client process, passed as 'client_label' argument, which is
1063  * allowed to read created file.
1064  *
1065  * \param[in] File name to create
1066  * \param[in] Label of designated client
1067  * \param[out] File descriptor
1068  *
1069  * \return SECURITY_SERVER_API_SUCCESS on success or one of error codes on fail
1070  * \return SECURITY_SERVER_API_ERROR_ACCESS_DENIED
1071  * \return SECURITY_SERVER_API_ERROR_SOCKET
1072  * \return SECURITY_SERVER_API_ERROR_INPUT_PARAM
1073  * \return SECURITY_SERVER_API_ERROR_GETTING_SOCKET_LABEL_FAILED
1074  * \return SECURITY_SERVER_API_ERROR_FILE_CREATION_FAILED
1075  * \return SECURITY_SERVER_API_ERROR_SETTING_FILE_LABEL_FAILED
1076  * \return SECURITY_SERVER_API_ERROR_FILE_EXIST
1077  *
1078  * Access to this function requires SMACK rule: "<app_label> security-server::api-open-for w"
1079  */
1080 int security_server_shared_file_open(const char *filename, const char *client_label, int *fd);
1081
1082 /*
1083  * This function allows to open existing file by Security Server on behalf of
1084  * calling process in secured directory. Security Server checks smack label
1085  * of calling process and if it's the same as file label access to file is
1086  * granted.
1087  *
1088  * \param[in] File name to open
1089  * \param[out] File descriptor
1090  *
1091  * \return SECURITY_SERVER_API_SUCCESS on success or one of error codes on fail
1092  * \return SECURITY_SERVER_API_ERROR_ACCESS_DENIED
1093  * \return SECURITY_SERVER_API_ERROR_SOCKET
1094  * \return SECURITY_SERVER_API_ERROR_INPUT_PARAM
1095  * \return SECURITY_SERVER_API_ERROR_GETTING_SOCKET_LABEL_FAILED
1096  * \return SECURITY_SERVER_API_ERROR_GETTING_FILE_LABEL_FAILED
1097  * \return SECURITY_SERVER_API_ERROR_AUTHENTICATION_FAILED
1098  * \return SECURITY_SERVER_API_ERROR_FILE_NOT_EXIST
1099  *
1100  * Access to this function requires SMACK rule: "<app_label> security-server::api-open-for w"
1101  */
1102 int security_server_shared_file_reopen(const char *filename, int *fd);
1103
1104 /*
1105  * This function allows to delete existing file by Security Server on behalf of
1106  * calling process in secured directory. Security Server checks smack label
1107  * of calling process and if it's the same as file label data file is deleted.
1108  *
1109  * \param[in] File name to delete
1110  *
1111  * \return SECURITY_SERVER_API_SUCCESS on success or one of error codes on fail
1112  * \return SECURITY_SERVER_API_ERROR_ACCESS_DENIED
1113  * \return SECURITY_SERVER_API_ERROR_SOCKET
1114  * \return SECURITY_SERVER_API_ERROR_INPUT_PARAM
1115  * \return SECURITY_SERVER_API_ERROR_GETTING_SOCKET_LABEL_FAILED
1116  * \return SECURITY_SERVER_API_ERROR_GETTING_FILE_LABEL_FAILED
1117  * \return SECURITY_SERVER_API_ERROR_AUTHENTICATION_FAILED
1118  * \return SECURITY_SERVER_API_ERROR_FILE_DELETION_FAILED
1119  * \return SECURITY_SERVER_API_ERROR_FILE_NOT_EXIST
1120  *
1121  * Access to this function requires SMACK rule: "<app_label> security-server::api-open-for w"
1122  */
1123 int security_server_shared_file_delete(const char *filename);
1124
1125 #ifdef __cplusplus
1126 }
1127 #endif
1128
1129 /**
1130  * @}
1131 */
1132
1133 /**
1134  * @}
1135 */
1136
1137 #endif