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