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