2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 * @brief Login Tool to change login user
20 #include <ico_syc_common.h>
21 #include <ico_syc_error.h>
22 #include <ico_syc_userctl.h>
25 /*============================================================================*/
26 /* Function prototype for static(internal) functions */
27 /*============================================================================*/
28 static void _sysctl_callback(const ico_syc_ev_e event, const void *detail,
31 /*============================================================================*/
32 /* Tables and Variables */
33 /*============================================================================*/
34 /* original stdout file discriptor */
35 static FILE *org_stdout;
37 static char newuser[128];
39 static char progname[128];
41 /*============================================================================*/
43 /*============================================================================*/
45 * @brief _sysctl_callback
48 _sysctl_callback(const ico_syc_ev_e event, const void *detail, void *user_data)
50 ico_syc_userlist_t *userlist;
54 case ICO_SYC_EV_USERLIST:
55 userlist = (ico_syc_userlist_t *)detail;
57 fprintf(org_stdout, "%s: # of users = %d\n", progname, userlist->user_num);
58 ICO_INF("%s: # of users = %d", progname, userlist->user_num);
59 for (i = 0; i < userlist->user_num; i++) {
60 if (strcmp(userlist->user_login, userlist->userlist[i])) {
61 fprintf(org_stdout, "%s:%2d. %s *\n", progname, i+1, userlist->userlist[i]);
62 ICO_INF("%s:%2d. %s *", progname, i+1, userlist->userlist[i]);
65 fprintf(org_stdout, "%s:%2d. %s\n", progname, i+1, userlist->userlist[i]);
66 ICO_INF("%s:%2d. %s", progname, i+1, userlist->userlist[i]);
69 (void)ico_syc_disconnect();
72 case ICO_SYC_EV_AUTH_FAIL:
73 fprintf(org_stdout, "%s: fail to authenticate user<%s>\n", progname, newuser);
74 ICO_ERR("%s: fail to authenticate user<%s>", progname, newuser);
75 (void)ico_syc_disconnect();
79 ICO_WRN("other event (%d)", event);
88 main(int argc, char *argv[])
93 strncpy(progname, argv[0], sizeof(progname));
94 progname[sizeof(progname)-1] = 0;
96 /* setting the log output */
98 ico_log_open("ico_change_loginuser");
100 memset(newuser, 0, sizeof(newuser));
102 strncpy(newuser, argv[1], sizeof(newuser)-1);
103 ICO_INF("%s: change user to <%s>", progname, newuser);
106 ICO_INF("%s: user list", progname);
109 /* connect to SystemController */
110 ret = ico_syc_connect(_sysctl_callback, NULL);
111 if (ret != ICO_SYC_ERR_NONE) {
112 ICO_WRN("%s: ico_syc_connect failed (ret: %d)", progname, ret);
114 fprintf(org_stdout, "%s: ico_syc_connect failed (ret: %d)\n", progname, ret);
117 /* connect wait 200 ms */
118 for (retry = 0; retry < (200/20); retry++) {
119 /* service for conection of SystemController */
125 (void)ico_syc_get_userlist();
128 /* change login user */
129 if (strcasecmp(newuser, "logoff") == 0) {
130 strcpy(newuser, " ");
132 (void)ico_syc_change_user(newuser, "\0");
136 for (retry = 0; retry < (300/20); retry++) {
137 /* service for send/receive */
142 (void)ico_syc_disconnect();