4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Bumjin Im <bj.im@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 #ifndef SECURITY_SERVER_H
23 #define SECURITY_SERVER_H
25 #include <sys/types.h>
26 #include <privilege-control.h>
29 * @file security-server.h
31 * @brief This file contains APIs of the Security Server
35 * @defgroup SecurityFW
38 * @defgroup SECURITY_SERVER Security Server
40 * @brief Security Server client library functions
45 * @addtogroup SECURITY_SERVER
50 * ====================================================================================================
55 * -- Company Name -- | Modification Date | Description of Changes
56 * -----------------------------------------------------------------------
57 * --- Samsung ------ | --- 2010-07-25 -- | First created
64 * exported by the foundation API.
65 * result codes begin with the start error code and extend into negative direction.
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
72 /*! \brief indicating the socket between client and Security Server has been failed */
73 #define SECURITY_SERVER_API_ERROR_BAD_REQUEST -2
75 /*! \brief indicating the response from Security Server is malformed */
76 #define SECURITY_SERVER_API_ERROR_BAD_RESPONSE -3
78 /*! \brief indicating the requested service does not exist */
79 #define SECURITY_SERVER_API_ERROR_NO_SUCH_SERVICE -4
81 /*! \brief indicating requesting object is not exist */
82 #define SECURITY_SERVER_API_ERROR_NO_SUCH_OBJECT -6
84 /*! \brief indicating the authentication between client and server has been failed */
85 #define SECURITY_SERVER_API_ERROR_AUTHENTICATION_FAILED -7
87 /*! \brief indicating the API's input parameter is malformed */
88 #define SECURITY_SERVER_API_ERROR_INPUT_PARAM -8
90 /*! \brief indicating the output buffer size which is passed as parameter is too small */
91 #define SECURITY_SERVER_API_ERROR_BUFFER_TOO_SMALL -9
93 /*! \brief indicating system is running out of memory state */
94 #define SECURITY_SERVER_API_ERROR_OUT_OF_MEMORY -10
96 /*! \brief indicating the access has been denied by Security Server */
97 #define SECURITY_SERVER_API_ERROR_ACCESS_DENIED -11
99 /*! \brief indicating Security Server has been failed for some reason */
100 #define SECURITY_SERVER_API_ERROR_SERVER_ERROR -12
102 /*! \brief indicating given cookie is not exist in the database */
103 #define SECURITY_SERVER_API_ERROR_NO_SUCH_COOKIE -13
105 /*! \brief indicating there is no phone password set */
106 #define SECURITY_SERVER_API_ERROR_NO_PASSWORD -14
108 /*! \brief indicating password exists in system */
109 #define SECURITY_SERVER_API_ERROR_PASSWORD_EXIST -15
111 /*! \brief indicating password mismatch */
112 #define SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH -16
114 /*! \brief indicating password retry timeout is not occurred yet */
115 #define SECURITY_SERVER_API_ERROR_PASSWORD_RETRY_TIMER -17
117 /*! \brief indicating password retry timeout is not occurred yet */
118 #define SECURITY_SERVER_API_ERROR_PASSWORD_MAX_ATTEMPTS_EXCEEDED -18
120 /*! \brief indicating password retry timeout is not occurred yet */
121 #define SECURITY_SERVER_API_ERROR_PASSWORD_EXPIRED -19
123 /*! \brief indicating password retry timeout is not occurred yet */
124 #define SECURITY_SERVER_API_ERROR_PASSWORD_REUSED -20
126 /*! \brief indicating getting smack label from socket failed */
127 #define SECURITY_SERVER_API_ERROR_GETTING_SOCKET_LABEL_FAILED -21
129 /*! \brief indicating getting smack label from file failed */
130 #define SECURITY_SERVER_API_ERROR_GETTING_FILE_LABEL_FAILED -22
132 /*! \brief indicating setting smack label for file failed */
133 #define SECURITY_SERVER_API_ERROR_SETTING_FILE_LABEL_FAILED -23
135 /*! \brief indicating file already exists */
136 #define SECURITY_SERVER_API_ERROR_FILE_EXIST -24
138 /*! \brief indicating file does not exist */
139 #define SECURITY_SERVER_API_ERROR_FILE_NOT_EXIST -25
141 /*! \brief indicating file open error */
142 #define SECURITY_SERVER_API_ERROR_FILE_OPEN_FAILED -26
144 /*! \brief indicating file creation error */
145 #define SECURITY_SERVER_API_ERROR_FILE_CREATION_FAILED -27
147 /*! \brief indicating file deletion error */
148 #define SECURITY_SERVER_API_ERROR_FILE_DELETION_FAILED -28
150 /*! \brief indicating the error with unknown reason */
151 #define SECURITY_SERVER_API_ERROR_UNKNOWN -255
163 * Retreives Linux group ID from object name which is passed by parameter
166 * This API may be used before security_server_check_privilege() API by middleware daemon to get group ID of a specific object.
168 * \par Typical use case:
169 * In middleware daemon, before checking privilege of a service the daemon need to know the GID of the service. This API support the functionality.
171 * \par Method of function operation:
172 * Opens /etc/group file and searches the object name as group name. If there is matching result, returns GID as integer
174 * \par Sync (or) Async:
175 * This is a Synchronous API.
177 * \par Important notes:
178 * - This API is only allowed to be called by pre-defined middleware daemon
180 * \param[in] object Name of the object which is kwnown by the caller.
182 * \return matching gid (positive integer) on success, or negative error code on error.
184 * \par Prospective clients:
187 * \par Known issues/bugs:
195 * security_server_get_object_name(), security_server_check_privilege()
201 * #include <security-server.h>
205 * // You have to make sure that the input param '*object' is defined in the platform
206 * retval = security_server_get_gid("telephony_makecall");
209 * printf("%s", "Error has occurred\n");
215 * Access to this function requires SMACK rule: "<app_label> security-server::api-get-gid w"
217 int security_server_get_gid(const char *object);
221 * Request cookie to the Security Server. Cookie is a random bit stream which is used as ticket for user space object.
224 * This API may be used by application and client middleware process to get access to middleware daemons.
226 * \par Typical use case:
227 * 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.
229 * \par Method of function operation:
230 * 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.
232 * \par Sync (or) Async:
233 * This is a Synchronous API.
235 * \par Important notes:
236 * Cookie needs to be stored relatively secure.
238 * \param[out] cookie Place holder for cookie value.
239 * \param[in] max_cookie Allocated byte size of parameter "cookie".
241 * \return 0 on success, or negative error code on error.
243 * \par Prospective clients:
246 * \par Known issues/bugs:
249 * \pre output parameter cookie must be malloced before calling this API not to make memory curruption
250 * Size of the cookie can be retrieved by security_server_get_cookie_size() API.
254 * \see security_server_check_privilege(), security_server_get_cookie_size()
260 * #include <security-server.h>
263 * size_t cookie_size;
264 * cookie_size = security_server_get_cookie_size();
265 * unsigned char cookie[cookie_size];
268 * retval = security_server_request_cookie(cookie, cookie_size);
271 * printf("%s", "Error has occurred\n");
277 * Access to this function not requires SMACK rule
279 int security_server_request_cookie(char *cookie, size_t bufferSize);
285 * This API gets the cookie's byte size which is issued by Security Server.
288 * This API may be used by application and middleware process to get size of cookie before getting and storing cookie value.
290 * \par Typical use case:
291 * 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.
293 * \par Method of function operation:
294 * This API just returns pre-defined integer value as cookie size.
296 * \par Sync (or) Async:
297 * This is a Synchronous API.
299 * \par Important notes:
302 * \return Always returns byte size of the cookie.
304 * \par Prospective clients:
307 * \par Known issues/bugs:
314 * \see security_server_request_cookie()
320 * #include <security-server.h>
323 * size_t cookie_size;
326 * cookie_size = security_server_get_cookie_size();
327 * unsigned char cookie[cookie_size];
329 * char objectname[20];
330 * retval = security_server_request_cookie(cookie, cookie_size);
333 * printf("%s", "Error has occurred\n");
339 * Access to this function not requires SMACK rule
341 int security_server_get_cookie_size(void);
347 * This API checks the cookie is allowed to access to given object.
350 * This API may be used by middleware process to ask the client application has privilege for the given object.
352 * \par Typical use case:
353 * 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.
355 * \par Method of function operation:
356 * 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.
358 * \par Sync (or) Async:
359 * This is a Synchronous API.
361 * \par Important notes:
362 * Cookie value needs to be stored relatively secure\n
363 * Privilege should be pre-defined by Platform design.
365 * \param[in] cookie Received cookie value from client application
366 * \param[in] privilege Object group ID which the client application wants to access
368 * \return 0 on success, or negative error code on error.
370 * \par Prospective clients:
371 * Only pre-defiend middleware daemons
373 * \par Known issues/bugs:
379 * \see security_server_request_cookie(), security_server_get_gid(), security_server_get_cookie_size()
385 * #include <security-server.h>
388 * size_t cookie_size;
390 * cookie_size = security_server_get_cookie_size();
391 * unsigned char recved_cookie[cookie_size];
393 * ... // Receiving request with cookie
395 * call_gid = security_server_get_gid("telephony_makecall");
396 * retval = security_server_check_privilege(recved_cookie, (gid_t)call_gid);
399 * if(retval == SECURITY_SERVER_API_ERROR_ACCESS_DENIED)
401 * printf("%s", "access has been denied\n");
404 * printf("%s", "Error has occurred\n");
410 * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
412 int security_server_check_privilege(const char *cookie, gid_t privilege);
414 int security_server_check_privilege_by_cookie(const char *cookie,
416 const char *access_rights);
420 * This API searchs a cookie value and returns PID of the given cookie.
423 * This API may be used by middleware process to ask the client application has privilege for the given object.
425 * \par Typical use case:
426 * 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.
428 * \par Method of function operation:
429 * 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.
431 * \par Sync (or) Async:
432 * This is a Synchronous API.
434 * \par Important notes:
435 * Cookie value needs to be stored relatively secure\n
436 * This API is abled to be called only by pre-defined middleware servers.
438 * \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.
440 * \return positive integer on success meaning the PID, 0 means the cookie is for root process, negative integer error code on error.
442 * \par Prospective clients:
443 * Only pre-defined middleware daemons
445 * \par Known issues/bugs:
452 * \see security_server_request_cookie(), security_server_get_cookie_size()
454 * \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.
455 * Therefore, please do not use strcpy() family to process cookie value. You MUST use memcpy() function to process cookie value.
456 * 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.
460 * #include <security-server.h>
463 * size_t cookie_size;
465 * cookie_size = security_server_get_cookie_size();
466 * unsigned char recved_cookie[cookie_size];
468 * ... // Receiving request with cookie
470 * peerpid = security_server_get_cookie_pid(recved_cookie);
473 * printf("%s", "Error has occurred\n");
479 * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
481 int security_server_get_cookie_pid(const char *cookie);
487 * This API checks phone validity of password, to check existance, expiration, remaining attempts.
490 * This API should be used by applications which needs phone password check. Caller application should behave properly after this API call.
492 * \par Typical use case:
493 * 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
495 * \par Method of function operation:
496 * Sends a validate request to security server and security server replies with password information.
498 * \par Sync (or) Async:
499 * This is a Synchronous API.
501 * \par Important notes:
502 * 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
504 * \param[out] current_attempts Number of password check missed attempts.
505 * \param[out] max_attempts Number of maximum attempts that the password locks. 0 means infinite
506 * \param[out] valid_secs Remaining time in second which represents this password will be expired. 0xFFFFFFFF means infinite
508 * \return 0 if there is no password set, other negative integer error code on error.
510 * \par Prospective clients:
511 * Applications which can unlock UI
513 * \par Known issues/bugs:
520 * \see security_server_set_pwd(), security_server_chk_pwd()
522 * \remarks If password file is corrupted or accidentally deleted, this API may not synchronized with security-server, but security-server will check file status on next request.
526 * #include <security-server.h>
529 * unsigned int attempt, max_attempt, expire_sec;
531 * ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
532 * if(is_pwd_set == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
534 * printf("%s", "There is no password exists\n");
536 * else if(is_pwd_set == SECURITY_SERVER_API_SUCCESS && expire_sec > 0 && attempt < max_attempts)
538 * printf("%s", "Password is valid by now\n");
542 * printf("%s", "Something wrong\n");
548 * Access to this function requires SMACK rule: "<app_label> security-server::api-password-check w"
550 int security_server_is_pwd_valid(unsigned int *current_attempts,
551 unsigned int *max_attempts,
552 unsigned int *valid_secs);
558 * This API sets phone password only if current password matches.
561 * This API should be used by setting application when the user changes his/her phone password.
563 * \par Typical use case:
564 * Setting application calls this API to change phone password. Caller needs current password to grant the change.
566 * \par Method of function operation:
567 * 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
569 * \par Sync (or) Async:
570 * This is a Synchronous API.
572 * \par Important notes:
573 * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
575 * \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()
576 * \param[in] new_pwd Null terminated new password string. It must not a NULL pointer.
577 * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
578 * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
580 * \return 0 on success, negative integer error code on error.
582 * \par Prospective clients:
583 * Platform's THE ONLY setting application and some dedicated privileged processes
585 * \par Known issues/bugs:
592 * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
594 * \remarks Only setting application can call this API. The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file corruption.
595 * \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.
599 * #include <security-server.h>
602 * unsigned int attempt, max_attempt, expire_sec;
604 * ret = security_server_is_pwd_valid(&attempt, &max_attempt, &expire_sec);
605 * if(is_pwd_set == SECURITY_SERVER_API_ERROR_NO_PASSWORD)
607 * printf("%s", "There is no password exists\n");
608 * ret = security_server_set_pwd(NULL, "this_is_new_pwd", 20, 365);
609 * if(ret != SECURITY_SERVER_API_SUCCESS)
611 * printf("%s", "we have error\n");
615 * else if(is_pwd_set == SECURITY_SERVER_API_SUCCESS && expire_sec > 0 && attempt < max_attempts)
617 * printf("%s", "Password is valid by now\n");
618 * ret = security_server_set_pwd("this_is_current_pwd", "this_is_new_pwd", 20, 365);
619 * if(ret != SECURITY_SERVER_API_SUCCESS)
621 * printf("%s", "we have error\n");
627 * printf("%s", "Something wrong\n");
633 * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
635 int security_server_set_pwd(const char *cur_pwd,
637 const unsigned int max_challenge,
638 const unsigned int valid_period_in_days);
643 * This API sets validity period for currently setup password.
646 * This API should be used by Enterprise authorities to modify password policy. To be used only with valid password setup.
648 * \par Typical use case:
649 * Authorized application calls this API to change current passwords validity when password policy needs to be changed.
651 * \par Method of function operation:
652 * 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.
653 * If there is no password set, function returns proper error code.
655 * \par Sync (or) Async:
656 * This is a Synchronous API.
657 * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
659 * \return 0 on success, negative integer error code on error.
661 * \par Prospective clients:
662 * Platform's THE ONLY setting application and some dedicated privileged processes
664 * \par Known issues/bugs:
665 * Identifying calling peer is not ready yet, should be based on SMACK somehow.
667 * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
669 * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
671 int security_server_set_pwd_validity(const unsigned int valid_period_in_days);
676 * This API sets maximum number of attempts for currently setup password.
679 * This API should be used by Enterprise authorities to modify password policy. To be used only with valid password setup.
681 * \par Typical use case:
682 * Authorized application calls this API to change current passwords max attempt number when password policy needs to be changed.
684 * \par Method of function operation:
685 * 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.
686 * If there is no password set, function returns proper error code.
688 * \par Sync (or) Async:
689 * This is a Synchronous API.
690 * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
692 * \return 0 on success, negative integer error code on error.
694 * \par Prospective clients:
695 * Platform's THE ONLY setting application and some dedicated privileged processes
697 * \par Known issues/bugs:
698 * Identifying calling peer is not ready yet, should be based on SMACK somehow.
700 * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_reset_pwd()
702 * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
704 int security_server_set_pwd_max_challenge(const unsigned int max_challenge);
708 * This API sets phone password without performing any checks connected with provided password. It
709 * should be used only if current password is invalid or user forgot the password.
712 * This API should be used by setting application or dedicated processes when the user changes his/her phone password.
714 * \par Typical use case:
715 * User forgets the password. He calls emergency manager(auto or manual) for reset password. Emergency manager calls this API and reset phone password.
717 * \par Method of function operation:
718 * Resetting phone password with input string without any matching current password. Function does
719 * no checks before password replacement (expiration time check, currently set password checks,
720 * history check and attempt count check are skipped).
722 * \par Sync (or) Async:
723 * This is a Synchronous API.
725 * \par Important notes:
726 * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
728 * \param[in] new_pwd Null terminated new password string. It must not a NULL pointer.
729 * \param[in] max_challenge Maximum number of attempts that user can try to check the password without success in serial. 0 means infinity.
730 * \param[in] valid_period_in_days. Number of days that this password is valid. 0 means infinity
732 * \return 0 on success, negative integer error code on error.
734 * \par Prospective clients:
735 * Platform's THE ONLY setting application and some dedicated privileged processes
737 * \par Known issues/bugs:
744 * \see security_server_is_pwd_valid(), security_server_chk_pwd(), security_server_set_pwd()
746 * \remarks Only dedicated applications can call this API. The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file corruption.
750 * #include <security-server.h>
754 * ret = security_server_reset_pwd("this_is_new_pwd", 20, 365);
755 * if(retval != SECURITY_SERVER_API_SUCCESS)
757 * printf("%s", "we have error\n");
764 * Access to this function requires SMACK rule: "<app_label> security-server::api-password-reset w"
766 int security_server_reset_pwd(const char *new_pwd,
767 const unsigned int max_challenge,
768 const unsigned int valid_period_in_days);
772 * This API compares stored phone password with challenged input value.
775 * This API should be used by applications which has phone UI lock capability.
777 * \par Typical use case:
778 * Lock screen calls this API after user typed phone password and pressed okay.
780 * \par Method of function operation:
781 * Sends challenged password to security-server, security-server compares hashed current password and hashed challenged password.
783 * \par Sync (or) Async:
784 * This is a Synchronous API.
786 * \par Important notes:
787 * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
789 * \param[in] challenge Null terminated challenged password string. It must not a NULL pointer.
790 * \param[out] current_attempts Number of password check missed attempts.
791 * \param[out] max_attempts Number of maximum attempts that the password locks. 0 means infinite
792 * \param[out] valid_secs Remaining time in second which represents this password will be expired. 0xFFFFFFFF means infinite
794 * \return 0 on success, negative integer error code on error.
796 * \par Prospective clients:
797 * Applications which has phone UI lock feature.
799 * \par Known issues/bugs:
806 * \see security_server_is_pwd_valid(), security_server_set_pwd()
808 * \remarks The password file will be acces controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
812 * #include <security-server.h>
815 * unsigned int attempt, max_attempt, expire_sec;
817 * retval = security_server_chk_pwd("is_this_password", &attmpt, &max_attempt, &expire_sec);
818 * if(retval == SECURITY_SERVER_API_ERROR_PASSWORD_MISMATCH)
820 * printf("%s", "Oh you typed wrong password\n");
823 * else if(retval == SECURITY_SERVER_API_SUCCESS)
825 * printf("%s", "You remember your password.\n");
832 * Access to this function requires SMACK rule: "<app_label> security-server::api-password-check w"
834 int security_server_chk_pwd(const char *challenge,
835 unsigned int *current_attempt,
836 unsigned int *max_attempt,
837 unsigned int *valid_secs);
842 * 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
845 * This API should be used only by dedicated process in the platform.
847 * \par Typical use case:
848 * Enterprise manager calls this API when the enterprise wants to enforce harder password policy.
850 * \par Method of function operation:
851 * When enterprise manager (MDM) is trying to change the security policy for phone password, it calls this API background to change the history policy.
853 * \par Sync (or) Async:
854 * This is a Synchronous API.
856 * \par Important notes:
857 * There is retry timer on this API to limit replay attack. You will get error if you called this API too often.\n
859 * \param[in] history_size Number of history to be checked when user tries to change password. Maximum is currently 50
861 * \return 0 on success, negative integer error code on error.
863 * \par Prospective clients:
864 * MDM client, Enterprise manager.
866 * \par Known issues/bugs:
873 * \see security_server_set_pwd()
875 * \remarks The password file will be access controlled and securely hashed. Security-server will remain previous password file to recover unexpected password file curruption.
879 * #include <security-server.h>
883 * ret = security_server_set_pwd_history(100);
884 * if(ret != SECURITY_SERVER_API_SUCCESS)
886 * printf("%s", "You have error\n");
893 * Access to this function requires SMACK rule: "<app_label> security-server::api-password-set w"
895 int security_server_set_pwd_history(int history_size);
898 * This function allows to get process SMACK label by passing cookie assigned
899 * to process. Function returns pointer to allocated buffer with label.
900 * User has to free the buffer after using.
902 * \param[in] Pointer to cookie
904 * \return Pointer to SMACK label or NULL
906 * \par For free label use free(), label allocated by calloc()
907 * User responsibility is to free resource.
909 * Access to this function requires SMACK rule: "<app_label> security-server::api-cookie-check w"
911 char *security_server_get_smacklabel_cookie(const char *cookie);
914 * This function allows to get process SMACK label by passing socket descriptor.
915 * Function returns pointer to allocated buffer with label.
916 * User has to free the buffer after using.
918 * \param[in] Socket descriptor
920 * \return Pointer to SMACK label or NULL
922 * \par For free label use free(), label allocated by calloc().
923 * User responsibility is to free resource.
925 * Access to this function not requires SMACK rule
927 char *security_server_get_smacklabel_sockfd(int fd);
930 * This function will give permissions "rwxat" from
931 * (subject) customer_label to caller process (object).
932 * Object label will be extracted from socket.
934 * \param[in] CUSTOMER_LABEL execute label of the process that should have access to caller.
935 * \param[in] CUSTOMER_PID all rules applied by this function should be removed from system
936 * when process with CUSTOMER_PID dies.
938 * \return SECURITY_SERVER_API_SUCCESS on success
939 * \return SECURITY_SERVER_API_ERROR_GETTING_SOCKET_LABEL_FAILED
940 * \return SECURITY_SERVER_API_ERROR_ACCESS_DENIED
941 * \return SECURITY_SERVER_API_ERROR_BAD_REQUEST input params were rejected by security-server
942 * \return SECURITY_SERVER_API_ERROR_INPUT_PARAM input params were rejected by client library
943 * \return SECURITY_SERVER_API_ERROR_SOCKET connection to security server failed.
945 * Important: In current implementation CUSTOMER_PID is ignored! This mean that rules applied
946 * by this function won't be revoke until device reset!
948 * Access to this function requires SMACK rule: "<app_label> security-server::api-data-share w"
950 int security_server_app_give_access(const char *customer_label, int customer_pid);
953 * This function allows middleware to check privileges of process with specified PID or socket
955 * Service is able to check process access to the specified object label with specified
958 * \param[in] PID id of process or SOCKFD socket file descriptor to be checked
959 * \param[in] SMACK object label
960 * \param[in] SMACK access rights to be checked
962 * \return Privilege confirm or error code
963 * \return SECURITY_SERVER_API_SUCCESS - on succes
965 * Access to this function requires SMACK rule: "<app_label> security-server::api-privilege-by-pid w"
967 int security_server_check_privilege_by_pid(int pid, const char *object, const char *access_rights);
969 int security_server_check_privilege_by_sockfd(int sockfd,
971 const char *access_rights);
974 * This function allows middleware to check if an app has the specified privilege
977 * \param[in] Application ID
978 * \param[in] Application type
979 * \param[in] Privilege name
980 * \param[out] Handler to store the result. It is set to 1 (true) if privilege is enabled, 0 (false) otherwise
982 * \return SECURITY_SERVER_API_SUCCESS on success or error code on fail
984 * Access to this function requires SMACK rule: "<app_label> security-server::api-app-privilege-by-name w"
986 int security_server_app_has_privilege(const char *app_id,
988 const char *privilege_name,