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