Added API for APP enable and disable permissions
[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 password is empty  */
130 #define SECURITY_SERVER_API_ERROR_PASSWORD_EMPTY -21
131
132 /*! \brief   indicating the error with unknown reason */
133 #define SECURITY_SERVER_API_ERROR_UNKNOWN -255
134 /** @}*/
135
136
137 #ifdef __cplusplus
138 extern "C" {
139 #endif
140
141
142
143 /**
144  * \par Description:
145  * Retreives Linux group ID from object name which is passed by parameter
146  *
147  * \par Purpose:
148  * This API may be used before security_server_check_privilege() API by middleware daemon to get group ID of a specific object.
149  *
150  * \par Typical use case:
151  * In middleware daemon, before checking privilege of a service the daemon need to know the GID of the service. This API support the functionality.
152  *
153  * \par Method of function operation:
154  * Opens /etc/group file and searches the object name as group name. If there is matching result, returns GID as integer
155  *
156  * \par Sync (or) Async:
157  * This is a Synchronous API.
158  *
159  * \par Important notes:
160  * - This API is only allowed to be called by pre-defined middleware daemon
161  *
162  * \param[in] object Name of the object which is kwnown by the caller.
163  *
164  * \return matching gid (positive integer) on success, or negative error code on error.
165  *
166  * \par Prospective clients:
167  * Inhouse middleware
168  *
169  * \par Known issues/bugs:
170  * None
171  *
172  * \pre None
173  *
174  * \post None
175  *
176  * \see /etc/group,
177  * security_server_get_object_name(), security_server_check_privilege()
178  *
179  * \remarks None
180  *
181  * \par Sample code:
182  * \code
183  * #include <security-server.h>
184  * ...
185  * int retval;
186  *
187  * // You have to make sure that  the input param '*object' is defined in the platform
188  * retval = security_server_get_gid("telephony_makecall");
189  * if(retval < 0)
190  * {
191  *      printf("%s", "Error has occurred\n");
192  *      exit(0);
193  * }
194  * ...
195  * \endcode
196 */
197 int security_server_get_gid(const char *object);
198
199
200
201 /**
202  * \par Description:
203  * Retreives object name as mull terminated string from Linux group ID which is passed by parameter
204  *
205  * \par Purpose:
206  * This API may be used to get object name if the caller process only knows GID of the object.
207  *
208  * \par Typical use case:
209  * In middleware daemon, by some reason, need to know object name from the Linux group ID, then call this API to retrieve object name as string
210  *
211  * \par Method of function operation:
212  * Opens /etc/group file and searches matching gid. If there is matching result, returns name of the group as null terminated string
213  *
214  * \par Sync (or) Async:
215  * This is a Synchronous API.
216  *
217  * \par Important notes:
218  * - This API is only allowed to be called by pre-defined middleware daemon
219  *
220  * \param[in] gid Linux group ID which needed to be retrieved as object name.
221  * \param[out] object Place holder for matching object name for gid.
222  * \param[in] max_object_size Allocated byte size of parameter "object".
223  *
224  * \return 0 on success, or negative error code on error.
225  *
226  * \par Prospective clients:
227  * Inhouse middleware.
228  *
229  * \par Known issues/bugs:
230  * None
231  *
232  * \pre output parameter object must be malloced before calling this API not to make memory curruption
233  *
234  * \post None
235  *
236  * \see /etc/group,
237  * security_server_get_gid()
238  *
239  * \remarks None
240  *
241  * \par Sample code:
242  * \code
243  * #include <security-server.h>
244  * ...
245  * int retval;
246  * char objectname[20];
247  *
248  * // Call the API
249  * retval = security_server_get_object_name(6005, objectname, sizeof(objectname));
250  * if(retval < 0)
251  * {
252  *      printf("%s", "Error has occurred\n");
253  *      exit(0);
254  * }
255  * ...
256  * \endcode
257 */
258 int security_server_get_object_name(gid_t gid, char *object, size_t max_object_size);
259
260
261
262 /**
263  * \par Description:
264  * Request cookie to the Security Server. Cookie is a random bit stream which is used as ticket for user space object.
265  *
266  * \par Purpose:
267  * This API may be used by application and client middleware process to get access to middleware daemons.
268  *
269  * \par Typical use case:
270  * 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.
271  *
272  * \par Method of function operation:
273  * 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.
274  *
275  * \par Sync (or) Async:
276  * This is a Synchronous API.
277  *
278  * \par Important notes:
279  * Cookie needs to be stored relatively secure.
280  *
281  * \param[out] cookie Place holder for cookie value.
282  * \param[in] max_cookie Allocated byte size of parameter "cookie".
283  *
284  * \return 0 on success, or negative error code on error.
285  *
286  * \par Prospective clients:
287  * Any process
288  *
289  * \par Known issues/bugs:
290  * None
291  *
292  * \pre output parameter cookie must be malloced before calling this API not to make memory curruption
293  * Size of the cookie can be retrieved by security_server_get_cookie_size() API.
294  *
295  * \post None
296  *
297  * \see security_server_check_privilege(), security_server_get_cookie_size()
298  *
299  * \remarks None
300  *
301  * \par Sample code:
302  * \code
303  * #include <security-server.h>
304  * ...
305  * int retval;
306  * size_t cookie_size;
307  * cookie_size = security_server_get_cookie_size();
308  * unsigned char cookie[cookie_size];
309  *
310  * // Call the API
311  * retval = security_server_request_cookie(cookie, cookie_size);
312  * if(retval < 0)
313  * {
314  *      printf("%s", "Error has occurred\n");
315  *      exit(0);
316  * }
317  * ...
318  * \endcode
319 */
320 int security_server_request_cookie(char *cookie, size_t max_cookie);
321
322
323
324 /**
325  * \par Description:
326  * This API gets the cookie's byte size which is issued by Security Server.
327  *
328  * \par Purpose:
329  * This API may be used by application and middleware process to get size of cookie before getting and storing cookie value.
330  *
331  * \par Typical use case:
332  * 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.
333  *
334  * \par Method of function operation:
335  * This API just returns pre-defined integer value as cookie size.
336  *
337  * \par Sync (or) Async:
338  * This is a Synchronous API.
339  *
340  * \par Important notes:
341  * None
342  *
343  * \return Always returns byte size of the cookie.
344  *
345  * \par Prospective clients:
346  * Any process
347  *
348  * \par Known issues/bugs:
349  * None
350  *
351  * \pre None
352  *
353  * \post None
354  *
355  * \see security_server_request_cookie()
356
357  * \remarks None
358  *
359  * \par Sample code:
360  * \code
361  * #include <security-server.h>
362  * ...
363  * int retval;
364  * size_t cookie_size;
365  *
366  * // API calling
367  * cookie_size = security_server_get_cookie_size();
368  * unsigned char cookie[cookie_size];
369  *
370  * char objectname[20];
371  * retval = security_server_request_cookie(cookie, cookie_size);
372  * if(retval < 0)
373  * {
374  *      printf("%s", "Error has occurred\n");
375  *      exit(0);
376  * }
377  * ...
378  * \endcode
379 */
380 int security_server_get_cookie_size(void);
381
382
383
384 /**
385  * \par Description:
386  * This API checks the cookie is allowed to access to given object.
387  *
388  * \par Purpose:
389  * This API may be used by middleware process to ask the client application has privilege for the given object.
390  *
391  * \par Typical use case:
392  * 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.
393  *
394  * \par Method of function operation:
395  * 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.
396  *
397  * \par Sync (or) Async:
398  * This is a Synchronous API.
399  *
400  * \par Important notes:
401  * Cookie value needs to be stored relatively secure\n
402  * Privilege should be pre-defined by Platform design.
403  *
404  * \param[in] cookie Received cookie value from client application
405  * \param[in] privilege Object group ID which the client application wants to access
406  *
407  * \return 0 on success, or negative error code on error.
408  *
409  * \par Prospective clients:
410  * Only pre-defiend middleware daemons
411  *
412  * \par Known issues/bugs:
413  * None
414  * \pre None
415  *
416  * \post None
417  *
418  * \see security_server_request_cookie(), security_server_get_gid(), security_server_get_cookie_size()
419  *
420  * \remarks None
421  *
422  * \par Sample code:
423  * \code
424  * #include <security-server.h>
425  * ...
426  * int retval;
427  * size_t cookie_size;
428  * int call_gid;
429  * cookie_size = security_server_get_cookie_size();
430  * unsigned char recved_cookie[cookie_size];
431  *
432  * ... // Receiving request with cookie
433  *
434  * call_gid = security_server_get_gid("telephony_makecall");
435  * retval = security_server_check_privilege(recved_cookie, (gid_t)call_gid);
436  * if(retval < 0)
437  * {
438  *      if(retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED)
439  *      {
440  *              printf("%s", "access has been denied\n");
441  *              return;
442  *      }
443  *      printf("%s", "Error has occurred\n");
444  * }
445  * ...
446  *
447  * \endcode
448 */
449 int security_server_check_privilege(const char *cookie, gid_t privilege);
450
451 int security_server_check_privilege_by_cookie(const char *cookie,
452                                               const char *object,
453                                               const char *access_rights);
454
455 int security_server_check_privilege_by_sockfd(int sockfd,
456                                               const char *object,
457                                               const char *access_rights);
458
459 /**
460  * \par Description:
461  * This API searchs a cookie value and returns PID of the given cookie.
462  *
463  * \par Purpose:
464  * This API may be used by middleware process to ask the client application has privilege for the given object.
465  *
466  * \par Typical use case:
467  * 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.
468  *
469  * \par Method of function operation:
470  * 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.
471  *
472  * \par Sync (or) Async:
473  * This is a Synchronous API.
474  *
475  * \par Important notes:
476  * Cookie value needs to be stored relatively secure\n
477  * This API is abled to be called only by pre-defined middleware servers.
478  *
479  * \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.
480  *
481  * \return positive integer on success meaning the PID, 0 means the cookie is for root process, negative integer error code on error.
482  *
483  * \par Prospective clients:
484  * Only pre-defiend middleware daemons
485  *
486  * \par Known issues/bugs:
487  * None
488  *
489  * \pre None
490  *
491  * \post None
492  *
493  * \see security_server_request_cookie(), security_server_get_cookie_size()
494  *
495  * \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.
496  * Therefore, please do not use strcpy() family to process cookie value. You MUST use memcpy() function to process cookie value.
497  * 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.
498  *
499  * \par Sample code:
500  * \code
501  * #include <security-server.h>
502  * ...
503  * int peerpid;
504  * size_t cookie_size;
505  * gid_t call_gid;
506  * cookie_size = security_server_get_cookie_size();
507  * unsigned char recved_cookie[cookie_size];
508  *
509  * ... // Receiving request with cookie
510  *
511  * peerpid = security_server_get_cookie_pid(recved_cookie);
512  * if(peerpid < 0)
513  * {
514  *      printf("%s", "Error has occurred\n");
515  * }
516  * ...
517  *
518  * \endcode
519 */
520 int security_server_get_cookie_pid(const char *cookie);
521
522
523
524 /**
525  * \par Description:
526  * This API checks phone validity of password, to check existance, expiration, remaining attempts.
527  *
528  * \par Purpose:
529  * This API should be used by applications which needs phone password check. Caller application should behave properly after this API call.
530  *
531  * \par Typical use case:
532  * 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
533  *
534  * \par Method of function operation:
535  * Sends a validate request to security server and security server replies with password information.
536  *
537  * \par Sync (or) Async:
538  * This is a Synchronous API.
539  *
540  * \par Important notes:
541  * 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
542  *
543  * \param[out] current_attempts Number of password check missed attempts.
544  * \param[out] max_attempts Number of maximum attempts that the password locks. 0 means infinite
545  * \param[out] valid_secs Remaining time in second which represents this password will be expired. 0xFFFFFFFF means infinite
546  *
547  * \return 0 if there is no password set, other negative integer error code on error.
548  *
549  * \par Prospective clients:
550  * Applications which can unlock UI
551  *
552  * \par Known issues/bugs:
553  * None
554  *
555  * \pre None
556  *
557  * \post None
558  *
559  * \see security_server_set_pwd(), security_server_chk_pwd()
560  *
561  * \remarks If password file is currupted or accitentally deleted, this API may not synchronized with security-server, but security-server will check file status on next request.
562  *
563  * \par Sample code:
564  * \code
565  * #include <security-server.h>
566  * ...
567  * int ret;
568  * unsigned int attempt, max_attempt, expire_sec;
569  *
570  * ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
571  * if(is_pwd_set == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
572  * {
573  *      printf("%s", "There is no password exists\n");
574  * }
575  * else if(is_pwd_set == SECURITY_SERVER_SUCCESS && expire_sec > 0 && attempt < max_attempts)
576  * {
577  *      printf("%s", "Password is valid by now\n");
578  * }
579  * else
580  * {
581  *      printf("%s", "Something wrong\n");
582  * }
583  * ...
584  *
585  * \endcode
586 */
587 int security_server_is_pwd_valid(unsigned int *current_attempts,
588                                  unsigned int *max_attempts,
589                                  unsigned int *valid_secs);
590
591
592
593 /**
594  * \par Description:
595  * This API sets phone password only if current password matches.
596  *
597  * \par Purpose:
598  * This API should be used by setting application when the user changes his/her phone password.
599  *
600  * \par Typical use case:
601  * Setting application calls this API to change phone password. Caller needs current password to grant the change.
602  *
603  * \par Method of function operation:
604  * 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
605  *
606  * \par Sync (or) Async:
607  * This is a Synchronous API.
608  *
609  * \par Important notes:
610  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
611  *
612  * \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()
613  * \param[in] new_pwd Null terminated new password string. It must not a NULL pointer.
614  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
615  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
616  *
617  * \return 0 on seccuess, negative integer error code on error.
618  *
619  * \par Prospective clients:
620  * Platform's THE ONLY setting application and some dedicated privileged processes
621  *
622  * \par Known issues/bugs:
623  * None
624  *
625  * \pre None
626  *
627  * \post None
628  *
629  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
630  *
631  * \remarks Only setting application can call this API. The password file will be acces controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
632  * \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.
633  *
634  * \par Sample code:
635  * \code
636  * #include <security-server.h>
637  * ...
638  * int ret;
639  * unsigned int attempt, max_attempt, expire_sec;
640  *
641  * ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
642  * if(is_pwd_set == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
643  * {
644  *      printf("%s", "There is no password exists\n");
645  *      ret = security_server_set_pwd(NULL, "this_is_new_pwd", 20, 365);
646  *      if(ret != SECURITY_SERVER_API_SUCCESS)
647  *      {
648  *              printf("%s", "we have error\n");
649  *              ...
650  *      }
651  * }
652  * else if(is_pwd_set == SECURITY_SERVER_SUCCESS && expire_sec > 0 && attempt < max_attempts)
653  * {
654  *      printf("%s", "Password is valid by now\n");
655  *      ret = security_server_set_pwd("this_is_current_pwd", "this_is_new_pwd", 20, 365);
656  *      if(ret != SECURITY_SERVER_API_SUCCESS)
657  *      {
658  *              printf("%s", "we have error\n");
659  *              ...
660  *      }
661  * }
662  * else
663  * {
664  *      printf("%s", "Something wrong\n");
665  * }
666  * ...
667  *
668  * \endcode
669 */
670 int security_server_set_pwd(const char *cur_pwd,
671                             const char *new_pwd,
672                             const unsigned int max_challenge,
673                             const unsigned int valid_period_in_days);
674
675
676 /**
677  * \par Description:
678  * This API sets validity period for currently setup password.
679  *
680  * \par Purpose:
681  * This API should be used by Enterprise authorities to modify password policy. To be used only with valid password setup.
682  *
683  * \par Typical use case:
684  * Authorized application calls this API to change current passwords validity when password policy needs to be changed.
685  *
686  * \par Method of function operation:
687  * 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.
688  * If there is no password set, function returns proper error code.
689  *
690  * \par Sync (or) Async:
691  * This is a Synchronous API.
692  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
693  *
694  * \return 0 on success, negative integer error code on error.
695  *
696  * \par Prospective clients:
697  * Platform's THE ONLY setting application and some dedicated privileged processes
698  *
699  * \par Known issues/bugs:
700  * Identifying calling peer is not ready yet, should be based on SMACK somehow.
701  *
702  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
703  */
704 int security_server_set_pwd_validity(const unsigned int valid_period_in_days);
705
706
707 /**
708  * \par Description:
709  * This API sets maximum number of attempts for currently setup password.
710  *
711  * \par Purpose:
712  * This API should be used by Enterprise authorities to modify password policy. To be used only with valid password setup.
713  *
714  * \par Typical use case:
715  * Authorized application calls this API to change current passwords max attempt number when password policy needs to be changed.
716  *
717  * \par Method of function operation:
718  * 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.
719  * If there is no password set, function returns proper error code.
720  *
721  * \par Sync (or) Async:
722  * This is a Synchronous API.
723  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
724  *
725  * \return 0 on success, negative integer error code on error.
726  *
727  * \par Prospective clients:
728  * Platform's THE ONLY setting application and some dedicated privileged processes
729  *
730  * \par Known issues/bugs:
731  * Identifying calling peer is not ready yet, should be based on SMACK somehow.
732  *
733  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
734  */
735 int security_server_set_pwd_max_challenge(const unsigned int max_challenge);
736
737 /**
738  * \par Description:
739  * This API sets phone password only if current password is invalid or user forgot the password.
740  *
741  * \par Purpose:
742  * This API should be used by setting application or dedicated processes when the user changes his/her phone password.
743  *
744  * \par Typical use case:
745  * User forgots the password. He calls emergency manager(auto or manual)  for reset password. Emergency manager calls this API and reset phone password.
746  *
747  * \par Method of function operation:
748  * Resetting phone password with input string without any matching current password.
749  *
750  * \par Sync (or) Async:
751  * This is a Synchronous API.
752  *
753  * \par Important notes:
754  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
755  *
756  * \param[in] new_pwd Null terminated new password string. It must not a NULL pointer.
757  * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
758  * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
759  *
760  * \return 0 on seccuess, negative integer error code on error.
761  *
762  * \par Prospective clients:
763  * Platform's THE ONLY setting application and some dedicated privileged processes
764  *
765  * \par Known issues/bugs:
766  * None
767  *
768  * \pre None
769  *
770  * \post None
771  *
772  * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_set_pwd()
773  *
774  * \remarks Only dedicated applications can call this API. The password file will be acces controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
775  *
776  * \par Sample code:
777  * \code
778  * #include <security-server.h>
779  * ...
780  * int ret;
781  * unsigned int attempt, max_attempt, expire_sec;
782  *
783  *      ret = security_server_set_pwd("this_is_new_pwd", 20, 365);
784  *      if(retval != SECURITY_SERVER_API_SUCCESS)
785  *      {
786  *              printf("%s", "we have error\n");
787  *              ...
788  *      }
789  * ...
790  *
791  * \endcode
792 */
793 int security_server_reset_pwd(const char *new_pwd,
794                               const unsigned int max_challenge,
795                               const unsigned int valid_period_in_days);
796
797 /**
798  * \par Description:
799  * This API compares stored phone password with challenged input value.
800  *
801  * \par Purpose:
802  * This API should be used by applications which has phone UI lock capability.
803  *
804  * \par Typical use case:
805  * Lock screen calls this API after user typed phone password and pressed okay.
806  *
807  * \par Method of function operation:
808  * Sends challenged password to security-server, security-server compares hashed current password and hashed challenged password.
809  *
810  * \par Sync (or) Async:
811  * This is a Synchronous API.
812  *
813  * \par Important notes:
814  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
815  *
816  * \param[in] challenge Null terminated challenged password string. It must not a NULL pointer.
817  * \param[out] current_attempts Number of password check missed attempts.
818  * \param[out] max_attempts Number of maximum attempts that the password locks. 0 means infinite
819  * \param[out] valid_secs Remaining time in second which represents this password will be expired. 0xFFFFFFFF means infinite
820  *
821  * \return 0 on seccuess, negative integer error code on error.
822  *
823  * \par Prospective clients:
824  * Applications which has phone UI lock feature.
825  *
826  * \par Known issues/bugs:
827  * None
828  *
829  * \pre None
830  *
831  * \post None
832  *
833  * \see security_server_is_pwd_valid(), security_server_set_pwd()
834  *
835  * \remarks The password file will be acces controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
836  *
837  * \par Sample code:
838  * \code
839  * #include <security-server.h>
840  * ...
841  * int retval;
842  * unsigned int attempt, max_attempt, expire_sec;
843  *
844  * retval = security_server_chk_pwd("is_this_password", &attmpt, &max_attempt, &expire_sec);
845  * if(retval == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH)
846  * {
847  *      printf("%s", "Oh you typed wrong password\n");
848  *      ...
849  * }
850  * else if(retval == SECURITY_SERVER_API_SUCCESS)
851  * {
852  *      printf("%s", "You remember your password.\n");
853  *      ...
854  * }
855  * ...
856  *
857  * \endcode
858 */
859 int security_server_chk_pwd(const char *challenge,
860                             unsigned int *current_attempt,
861                             unsigned int *max_attempt,
862                             unsigned int *valid_secs);
863
864
865 /**
866  * \par Description:
867  * 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
868  *
869  * \par Purpose:
870  * This API should be used only by dedicated process in the platform.
871  *
872  * \par Typical use case:
873  * Enterprise manager calls this API when the enterprise wants to enforce harder password policy.
874  *
875  * \par Method of function operation:
876  * When enterprise manager (MDM) is trying to change the security policy for phone password, it calls this API background to change the history policy.
877  *
878  * \par Sync (or) Async:
879  * This is a Synchronous API.
880  *
881  * \par Important notes:
882  * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
883  *
884  * \param[in] number_of_history Number of history to be checked when user tries to change password. Maximum is currently 50
885  *
886  * \return 0 on seccuess, negative integer error code on error.
887  *
888  * \par Prospective clients:
889  * MDM client, Enterprise manager.
890  *
891  * \par Known issues/bugs:
892  * None
893  *
894  * \pre None
895  *
896  * \post None
897  *
898  * \see security_server_set_pwd()
899  *
900  * \remarks The password file will be acces controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
901  *
902  * \par Sample code:
903  * \code
904  * #include <security-server.h>
905  * ...
906  * int retval;
907  *
908  * ret = security_server_set_pwd_history(100);
909  *      if(ret != SECURITY_SERVER_API_SUCCESS)
910  *      {
911  *              printf("%s", "You have error\n");
912  *              ...
913  *      }
914  * ...
915  *
916  * \endcode
917 */
918 int security_server_set_pwd_history(int number_of_history);
919
920 /*
921  * This function allows to get process SMACK label by passing cookie assigned
922  * to process. Function returns pointer to allocated buffer with label.
923  * User has to free the buffer after using.
924  *
925  * \param[in] Pointer to cookie
926  *
927  * \return Pointer to SMACK label or NULL
928  *
929  * \par For free label use free(), label allocated by calloc()
930  *      User responsibility is to free resource.
931  */
932 char *security_server_get_smacklabel_cookie(const char *cookie);
933
934 /*
935  * This function allows to get process SMACK label by passing socket descriptor.
936  * Function returns pointer to allocated buffer with label.
937  * User has to free the buffer after using.
938  *
939  * \param[in] Socket descriptor
940  *
941  * \return Pointer to SMACK label or NULL
942  *
943  * \par For free label use free(), label allocated by calloc().
944  *      User responsibility is to free resource.
945  */
946 char *security_server_get_smacklabel_sockfd(int fd);
947
948 /*
949  * This function will give permissions "rwxat" from
950  * (subject) customer_label to caller process (object).
951  * Object label will be extracted from socket.
952  * */
953 int security_server_app_give_access(const char *customer_label, int customer_pid);
954
955 /*
956  * This function allows middleware to check priviliges of process with specified PID.
957  * Service is able to check proces acces to the specified object label with specified
958  * access rights.
959  *
960  * \param[in] PID number of process to be checked
961  * \param[in] SMACK object label
962  * \param[in] SMACK access rights to be checked
963  *
964  * \return Privilege confirm or error code
965  * SECURITY_SERVER_SUCCESS - on succes
966  */
967 int security_server_check_privilege_by_pid(int pid, const char *object, const char *access_rights);
968
969 /*
970  * This function allows middleware to enable permissions for specified app_id.
971  *
972  * \param[in] Application ID
973  * \param[in] Application type definet in enum at the beginning of this file
974  * \param[in] Permissions list
975  * \param[in] Persistent
976  *
977  * \return SECURITY_SERVER_SUCCESS on success or error code on fail
978  */
979 int security_server_app_enable_permissions(const char *app_id, app_type_t app_type, const char **perm_list, int persistent);
980
981 /*
982  * This function allows middleware to disable permissions for specified app_id.
983  *
984  * \param[in] Application ID
985  * \param[in] Application type definet in enum at the beginning of this file
986  * \param[in] Permissions list
987  *
988  * \return SECURITY_SERVER_SUCCESS on success or error code on fail
989  */
990 int security_server_app_disable_permissions(const char *app_id, app_type_t app_type, const char **perm_list);
991
992
993 #ifdef __cplusplus
994 }
995 #endif
996
997 /**
998  * @}
999 */
1000
1001 /**
1002  * @}
1003 */
1004
1005 #endif