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