LinphoneAddress *account_manager_check_account(AccountManager *m, LinphoneProxyConfig *cfg){ LinphoneCore *lc=linphone_proxy_config_get_core(cfg); const char *identity=linphone_proxy_config_get_identity(cfg); LinphoneAddress *id_addr=linphone_address_new(identity); Account *account=account_manager_get_account(m,id_addr); LinphoneAuthInfo *ai; char *tmp; bool_t create_account=FALSE; if (!account){ account=account_new(id_addr,m->unique_id); ms_message("No account for %s exists, going to create one.",identity); create_account=TRUE; m->accounts=ms_list_append(m->accounts,account); } /*modify the username of the identity of the proxy config*/ linphone_address_set_username(id_addr, linphone_address_get_username(account->modified_identity)); tmp=linphone_address_as_string(id_addr); linphone_proxy_config_set_identity(cfg,tmp); ms_free(tmp); if (create_account){ account_create_on_server(account,cfg); } ai=linphone_auth_info_new(linphone_address_get_username(account->modified_identity), NULL, account->password,NULL,NULL,linphone_address_get_domain(account->modified_identity)); linphone_core_add_auth_info(lc,ai); linphone_auth_info_destroy(ai); linphone_address_unref(id_addr); return account->modified_identity; }
void cmd_join_uses_account_mucservice_when_no_service_specified(void **state) { char *account_name = "an_account"; char *room = "room"; char *nick = "bob"; char *account_service = "conference.server.org"; char *expected_room = "*****@*****.**"; gchar *args[] = { room, "nick", nick, NULL }; ProfAccount *account = account_new(account_name, "*****@*****.**", NULL, NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); muc_init(); will_return(connection_get_status, JABBER_CONNECTED); will_return(session_get_account_name, account_name); expect_string(accounts_get_account, name, account_name); will_return(accounts_get_account, account); expect_string(presence_join_room, room, expected_room); expect_string(presence_join_room, nick, nick); expect_value(presence_join_room, passwd, NULL); gboolean result = cmd_join(NULL, CMD_JOIN, args); assert_true(result); }
void cmd_join_uses_password_when_supplied(void **state) { char *account_name = "an_account"; char *room = "room"; char *password = "******"; char *account_nick = "a_nick"; char *account_service = "a_service"; char *expected_room = "room@a_service"; CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, "password", password, NULL }; ProfAccount *account = account_new(account_name, "*****@*****.**", NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick); muc_init(); mock_connection_status(JABBER_CONNECTED); mock_connection_account_name(account_name); mock_accounts_get_account(); accounts_get_account_expect_and_return(account_name, account); mock_presence_join_room(); presence_join_room_expect(expected_room, account_nick, password); ui_room_join_expect(expected_room, TRUE); gboolean result = cmd_join(args, *help); assert_true(result); free(help); }
void cmd_join_uses_password_when_supplied(void **state) { char *account_name = "an_account"; char *room = "room"; char *password = "******"; char *account_nick = "a_nick"; char *account_service = "a_service"; char *expected_room = "room@a_service"; gchar *args[] = { room, "password", password, NULL }; ProfAccount *account = account_new(account_name, "*****@*****.**", NULL, NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, account_nick, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); muc_init(); will_return(jabber_get_connection_status, JABBER_CONNECTED); will_return(jabber_get_account_name, account_name); expect_string(accounts_get_account, name, account_name); will_return(accounts_get_account, account); expect_string(presence_join_room, room, expected_room); expect_string(presence_join_room, nick, account_nick); expect_value(presence_join_room, passwd, password); gboolean result = cmd_join(NULL, CMD_JOIN, args); assert_true(result); }
void cmd_join_uses_account_mucservice_when_no_service_specified(void **state) { char *account_name = "an_account"; char *room = "room"; char *nick = "bob"; char *account_service = "conference.server.org"; char *expected_room = "*****@*****.**"; CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { room, "nick", nick, NULL }; ProfAccount *account = account_new(account_name, "*****@*****.**", NULL, TRUE, NULL, 0, "laptop", NULL, NULL, 0, 0, 0, 0, 0, account_service, NULL); muc_init(); mock_connection_status(JABBER_CONNECTED); mock_connection_account_name(account_name); mock_accounts_get_account(); accounts_get_account_expect_and_return(account_name, account); mock_presence_join_room(); presence_join_room_expect(expected_room, nick, NULL); ui_room_join_expect(expected_room, TRUE); gboolean result = cmd_join(args, *help); assert_true(result); free(help); }
void cmd_account_show_shows_account_when_exists(void **state) { gchar *args[] = { "show", "account_name", NULL }; ProfAccount *account = account_new("jabber_org", "*****@*****.**", NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); expect_any(accounts_get_account, name); will_return(accounts_get_account, account); expect_memory(cons_show_account, account, account, sizeof(account)); gboolean result = cmd_account_show(NULL, CMD_ACCOUNT, args); assert_true(result); }
void cmd_account_set_eval_password_when_password_set(void **state) { gchar *args[] = { "set", "a_account", "eval_password", "a_password", NULL }; ProfAccount *account = account_new("a_account", NULL, "a_password", NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); expect_string(accounts_get_account, name, "a_account"); will_return(accounts_get_account, account); expect_cons_show("Cannot set eval_password when password is set."); gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args); assert_true(result); }
void cmd_account_shows_account_when_connected_and_no_args(void **state) { ProfAccount *account = account_new("jabber_org", "*****@*****.**", NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); gchar *args[] = { NULL }; will_return(connection_get_status, JABBER_CONNECTED); will_return(session_get_account_name, "account_name"); expect_any(accounts_get_account, name); will_return(accounts_get_account, account); expect_memory(cons_show_account, account, account, sizeof(ProfAccount)); gboolean result = cmd_account(NULL, CMD_ACCOUNT, args); assert_true(result); }
void cmd_rooms_uses_account_default_when_no_arg(void **state) { gchar *args[] = { NULL }; ProfAccount *account = account_new("testaccount", NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, strdup("default_conf_server"), NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); will_return(jabber_get_connection_status, JABBER_CONNECTED); will_return(jabber_get_account_name, "account_name"); expect_any(accounts_get_account, name); will_return(accounts_get_account, account); expect_string(iq_room_list_request, conferencejid, "default_conf_server"); gboolean result = cmd_rooms(NULL, CMD_ROOMS, args); assert_true(result); }
void cmd_account_show_shows_account_when_exists(void **state) { mock_cons_show_account(); mock_accounts_get_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "show", "account_name", NULL }; ProfAccount *account = account_new("jabber_org", "*****@*****.**", NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL); accounts_get_account_return(account); expect_cons_show_account(account); gboolean result = cmd_account(args, *help); assert_true(result); free(help); }
void cmd_otr_gen_generates_key_for_connected_account(void **state) { gchar *args[] = { "gen", NULL }; char *account_name = "myaccount"; ProfAccount *account = account_new(account_name, "*****@*****.**", NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); will_return(jabber_get_connection_status, JABBER_CONNECTED); will_return(jabber_get_account_name, account_name); expect_string(accounts_get_account, name, account_name); will_return(accounts_get_account, account); expect_memory(otr_keygen, account, account, sizeof(ProfAccount)); gboolean result = cmd_otr(NULL, CMD_OTR, args); assert_true(result); }
void cmd_account_shows_account_when_connected_and_no_args(void **state) { mock_cons_show_account(); mock_accounts_get_account(); CommandHelp *help = malloc(sizeof(CommandHelp)); ProfAccount *account = account_new("jabber_org", "*****@*****.**", NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL); gchar *args[] = { NULL }; mock_connection_status(JABBER_CONNECTED); mock_connection_account_name("account_name"); accounts_get_account_return(account); expect_cons_show_account(account); gboolean result = cmd_account(args, *help); assert_true(result); free(help); }
void cmd_connect_connects_with_account(void **state) { CommandHelp *help = malloc(sizeof(CommandHelp)); gchar *args[] = { "jabber_org", NULL }; ProfAccount *account = account_new("jabber_org", "*****@*****.**", "password", NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL); will_return(jabber_get_connection_status, JABBER_DISCONNECTED); expect_any(accounts_get_account, name); will_return(accounts_get_account, account); expect_cons_show("Connecting with account jabber_org as [email protected]"); expect_memory(jabber_connect_with_account, account, account, sizeof(account)); will_return(jabber_connect_with_account, JABBER_CONNECTING); gboolean result = cmd_connect(NULL, args, *help); assert_true(result); free(help); }
void cmd_account_set_password_sets_password(void **state) { gchar *args[] = { "set", "a_account", "password", "a_password", NULL }; ProfAccount *account = account_new("a_account", NULL, NULL, NULL, TRUE, NULL, 0, NULL, NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); expect_string(accounts_get_account, name, "a_account"); will_return(accounts_get_account, account); expect_string(accounts_set_password, account_name, "a_account"); expect_string(accounts_set_password, value, "a_password"); expect_cons_show("Updated password for account a_account"); expect_cons_show(""); gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args); assert_true(result); }
void cmd_account_set_priority_updates_presence_when_account_connected_with_presence(void **state) { gchar *args[] = { "set", "a_account", "online", "10", NULL }; expect_any(accounts_account_exists, account_name); will_return(accounts_account_exists, TRUE); expect_any(accounts_set_priority_online, account_name); expect_any(accounts_set_priority_online, value); will_return(connection_get_status, JABBER_CONNECTED); expect_any(accounts_get_last_presence, account_name); will_return(accounts_get_last_presence, RESOURCE_ONLINE); will_return(session_get_account_name, "a_account"); #ifdef HAVE_LIBGPGME ProfAccount *account = account_new("a_account", "a_jid", NULL, NULL, TRUE, NULL, 5222, "a_resource", NULL, NULL, 10, 10, 10, 10, 10, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); will_return(session_get_account_name, "a_account"); expect_any(accounts_get_account, name); will_return(accounts_get_account, account); #endif will_return(connection_get_presence_msg, "Free to chat"); expect_value(presence_send, status, RESOURCE_ONLINE); expect_string(presence_send, msg, "Free to chat"); expect_value(presence_send, idle, 0); expect_value(presence_send, signed_status, NULL); expect_cons_show("Updated online priority for account a_account: 10"); expect_cons_show(""); gboolean result = cmd_account_set(NULL, CMD_ACCOUNT, args); assert_true(result); }
static void user_added (ActUserManager *um, ActUser *user, Accounts *accounts) { if (act_user_is_system_account (user)) return; GDBusObjectManagerServer *object_manager_server = daemon_get_object_manager (daemon_get ()); CockpitAccount *acc = account_new (); account_update (ACCOUNT (acc), user); gs_free gchar *path = utils_generate_object_path ("/com/redhat/Cockpit/Accounts", cockpit_account_get_user_name (acc)); gs_unref_object CockpitObjectSkeleton *obj = cockpit_object_skeleton_new (path); cockpit_object_skeleton_set_account (obj, acc); g_dbus_object_manager_server_export_uniquely (object_manager_server, G_DBUS_OBJECT_SKELETON (obj)); g_hash_table_insert (accounts->act_user_to_account, user, ACCOUNT(acc)); }
ProfAccount* accounts_get_account(const char *const name) { if (!g_key_file_has_group(accounts, name)) { return NULL; } else { gchar *jid = g_key_file_get_string(accounts, name, "jid", NULL); // fix accounts that have no jid property by setting to name if (jid == NULL) { g_key_file_set_string(accounts, name, "jid", name); _save_accounts(); } gchar *password = g_key_file_get_string(accounts, name, "password", NULL); gchar *eval_password = g_key_file_get_string(accounts, name, "eval_password", NULL); gboolean enabled = g_key_file_get_boolean(accounts, name, "enabled", NULL); gchar *server = g_key_file_get_string(accounts, name, "server", NULL); gchar *resource = g_key_file_get_string(accounts, name, "resource", NULL); int port = g_key_file_get_integer(accounts, name, "port", NULL); gchar *last_presence = g_key_file_get_string(accounts, name, "presence.last", NULL); gchar *login_presence = g_key_file_get_string(accounts, name, "presence.login", NULL); int priority_online = g_key_file_get_integer(accounts, name, "priority.online", NULL); int priority_chat = g_key_file_get_integer(accounts, name, "priority.chat", NULL); int priority_away = g_key_file_get_integer(accounts, name, "priority.away", NULL); int priority_xa = g_key_file_get_integer(accounts, name, "priority.xa", NULL); int priority_dnd = g_key_file_get_integer(accounts, name, "priority.dnd", NULL); gchar *muc_service = g_key_file_get_string(accounts, name, "muc.service", NULL); gchar *muc_nick = g_key_file_get_string(accounts, name, "muc.nick", NULL); gchar *otr_policy = NULL; if (g_key_file_has_key(accounts, name, "otr.policy", NULL)) { otr_policy = g_key_file_get_string(accounts, name, "otr.policy", NULL); } gsize length; GList *otr_manual = NULL; gchar **manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL); if (manual) { int i = 0; for (i = 0; i < length; i++) { otr_manual = g_list_append(otr_manual, strdup(manual[i])); } g_strfreev(manual); } GList *otr_opportunistic = NULL; gchar **opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL); if (opportunistic) { int i = 0; for (i = 0; i < length; i++) { otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i])); } g_strfreev(opportunistic); } GList *otr_always = NULL; gchar **always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL); if (always) { int i = 0; for (i = 0; i < length; i++) { otr_always = g_list_append(otr_always, strdup(always[i])); } g_strfreev(always); } gchar *pgp_keyid = NULL; if (g_key_file_has_key(accounts, name, "pgp.keyid", NULL)) { pgp_keyid = g_key_file_get_string(accounts, name, "pgp.keyid", NULL); } gchar *startscript = NULL; if (g_key_file_has_key(accounts, name, "script.start", NULL)) { startscript = g_key_file_get_string(accounts, name, "script.start", NULL); } gchar *tls_policy = g_key_file_get_string(accounts, name, "tls.policy", NULL); if (tls_policy && ((g_strcmp0(tls_policy, "force") != 0) && (g_strcmp0(tls_policy, "allow") != 0) && (g_strcmp0(tls_policy, "disable") != 0))) { g_free(tls_policy); tls_policy = NULL; } ProfAccount *new_account = account_new(name, jid, password, eval_password, enabled, server, port, resource, last_presence, login_presence, priority_online, priority_chat, priority_away, priority_xa, priority_dnd, muc_service, muc_nick, otr_policy, otr_manual, otr_opportunistic, otr_always, pgp_keyid, startscript, tls_policy); g_free(jid); g_free(password); g_free(eval_password); g_free(server); g_free(resource); g_free(last_presence); g_free(login_presence); g_free(muc_service); g_free(muc_nick); g_free(otr_policy); g_free(pgp_keyid); g_free(startscript); g_free(tls_policy); return new_account; } }
static void login_httpd_account(struct httpd_session_data *sd,const char* url) { char* userid = httpd_get_value(sd,"userid"); int userid_len = (int)strlen(userid); char* passwd = httpd_get_value(sd,"passwd"); int passwd_len = (int)strlen(passwd); char* gender = httpd_get_value(sd,"gender"); char* check = httpd_get_value(sd,"check"); const char* msg = ""; int i; do { if(httpd_get_method(sd) != HTTPD_METHOD_POST) { // POST以外お断り msg = "Illegal request."; break; } if(!httpd_new_account_flag) { msg = "Now stopping to create accounts on httpd."; break; } if(userid_len < 4 || userid_len > 23) { msg = "Please input UserID 4-23 bytes."; break; } for(i = 0; i < userid_len; i++) { if(!isalnum((unsigned char)userid[i])) break; } if(i != userid_len) { msg = "Illegal character found in UserID."; break; } if(check[0]) { // ID のチェックは userid だけでいい if(account_load_str(userid) == NULL) { msg = "OK : You can use UserID."; } else { msg = "NG : UserID is already used."; } break; } if(passwd_len < 4 || passwd_len > 23) { msg = "Please input Password 4-23 bytes."; break; } for(i = 0; i < passwd_len; i++) { if(!isalnum((unsigned char)passwd[i])) break; } if(i != passwd_len) { msg = "Illegal character found in Password."; break; } if(gender[0] != 'M' && gender[0] != 'F') { msg = "Gender error."; break; } if(!check[0]) { struct mmo_account ma; char buf[32]; memset(&ma,0,sizeof(ma)); strncpy(ma.userid,userid,24); strncpy(ma.pass ,passwd,24); ma.sex = gender[0]; strncpy(ma.mail ,"@" ,40); // 暫定 strncpy(ma.birth ,"000000", 7); sprintf(buf,"( httpd %08lx )",httpd_get_ip(sd)); if( !account_new(&ma,buf) ) { msg = "Account creation failed."; } else { msg = "Account successfully created."; } } } while(0); // HTTP/1.1で返すとアカウントを連続して作成する馬鹿がいそうなので、 // あえてHTTP/1.0扱いしている。 httpd_send_head(sd,200,"text/plain",-1); httpd_send_data(sd,(int)strlen(msg),msg); aFree(userid); aFree(passwd); aFree(gender); aFree(check); return; }