Beispiel #1
0
int __connman_storage_save_service(GKeyFile *keyfile, const char *service_id)
{
	int ret = 0;
	gchar *pathname, *dirname;

	dirname = g_strdup_printf("%s/%s", STORAGEDIR, service_id);
	if (!dirname)
		return -ENOMEM;

	/* If the dir doesn't exist, create it */
	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
		if (mkdir(dirname, MODE) < 0) {
			if (errno != EEXIST) {
				g_free(dirname);
				return -errno;
			}
		}
	}

	pathname = g_strdup_printf("%s/%s", dirname, SETTINGS);

	g_free(dirname);

	ret = storage_save(keyfile, pathname);

	g_free(pathname);

	return ret;
}
Beispiel #2
0
static void cmd_save(irc_t *irc, char **cmd)
{
	if ((irc->status & USTATUS_IDENTIFIED) == 0) {
		irc_rootmsg(irc, "Please create an account first (see \x02help register\x02)");
	} else if (storage_save(irc, NULL, TRUE) == STORAGE_OK) {
		irc_rootmsg(irc, "Configuration saved");
	} else {
		irc_rootmsg(irc, "Configuration could not be saved!");
	}
}
Beispiel #3
0
int __connman_storage_save_global(GKeyFile *keyfile)
{
	gchar *pathname;
	int ret;

	pathname = g_strdup_printf("%s/%s", STORAGEDIR, SETTINGS);
	if (!pathname)
		return -ENOMEM;

	ret = storage_save(keyfile, pathname);

	g_free(pathname);

	return ret;
}
Beispiel #4
0
static void storage_serialize(at **pp, int code)
{
   storage_t *st;
   int type, kind;
   size_t size;

   if (code != SRZ_READ) {
      st = Mptr(*pp);
      type = (int)st->type;
      kind = (int)st->kind;
      size = st->size;
   }
   // Read/write basic info
   serialize_int(&type, code);
   serialize_int(&kind, code);
   serialize_size(&size, code);

   // Create storage if needed
   if (code == SRZ_READ) {
      st = new_storage_managed((storage_type_t)type, size, NIL);
      *pp = st->backptr;
   }

   // Read/write storage data
   st = Mptr(*pp);
   if (type == ST_AT) {
      at **data = st->data;
      for (int i=0; i<size; i++)
         serialize_atstar( &data[i], code);

   } else  {
      FILE *f = serialization_file_descriptor(code);
      if (code == SRZ_WRITE) {
         extern int in_bwrite;
         in_bwrite += sizeof(int) + size * storage_sizeof[type];
         write4(f, STORAGE_NORMAL);
         storage_save(st, f);
         
      } else if (code == SRZ_READ) {
         int magic = read4(f);
         storage_load(st, f);
         if (magic == STORAGE_SWAPPED)
            swap_buffer(st->data, size, storage_sizeof[type]);
         else if (magic != STORAGE_NORMAL)
            RAISEF("Corrupted binary file",NIL);
      }
   }
}
Beispiel #5
0
static void cmd_register(irc_t *irc, char **cmd)
{
	char s[16];

	if (global.conf->authmode == AUTHMODE_REGISTERED) {
		irc_rootmsg(irc, "This server does not allow registering new accounts");
		return;
	}

	if (cmd[1] == NULL) {
		irc_rootmsg(irc, "About to register, use /OPER to enter the password");
		irc->status |= OPER_HACK_REGISTER;
		return;
	}

	switch (storage_save(irc, cmd[1], FALSE)) {
	case STORAGE_ALREADY_EXISTS:
		irc_rootmsg(irc, "Nick is already registered");
		break;

	case STORAGE_OK:
		irc_rootmsg(irc, "Account successfully created");
		irc_setpass(irc, cmd[1]);
		irc->status |= USTATUS_IDENTIFIED;
		irc_umode_set(irc, "+R", 1);

		if (irc->caps & CAP_SASL) {
			irc_user_t *iu = irc->user;
			irc_send_num(irc, 900, "%s!%s@%s %s :You are now logged in as %s",
				iu->nick, iu->user, iu->host, iu->nick, iu->nick);
		}

		/* Set this var now, or anyone who logs in to his/her
		   newly created account for the first time gets the
		   whatsnew story. */
		g_snprintf(s, sizeof(s), "%d", BITLBEE_VERSION_CODE);
		set_setstr(&irc->b->set, "last_version", s);
		break;

	default:
		irc_rootmsg(irc, "Error registering");
		break;
	}
}
Beispiel #6
0
void __connman_storage_save_provider(GKeyFile *keyfile, const char *identifier)
{
	gchar *pathname, *dirname;

	dirname = g_strdup_printf("%s/%s_%s", STORAGEDIR,
			"provider", identifier);
	if (!dirname)
		return;

	if (!g_file_test(dirname, G_FILE_TEST_IS_DIR) &&
			mkdir(dirname, MODE) < 0) {
		g_free(dirname);
		return;
	}

	pathname = g_strdup_printf("%s/%s", dirname, SETTINGS);
	g_free(dirname);

	storage_save(keyfile, pathname);
	g_free(pathname);
}
Beispiel #7
0
storage_status_t storage_rename (const char *onick, const char *nnick, const char *password)
{
	storage_status_t status;
	GList *gl = global.storage;
	storage_t *primary_storage = gl->data;
	irc_t *irc;

	/* First, try to rename in the current write backend, assuming onick 
	 * is stored there */
	status = primary_storage->rename(onick, nnick, password);
	if (status != STORAGE_NO_SUCH_USER)
		return status;

	/* Try to load from a migration backend and save to the current backend. 
	 * Explicitly remove the account from the migration backend as otherwise 
	 * it'd still be usable under the old name */
	
	irc = g_new0(irc_t, 1);
	status = storage_load(onick, password, irc);
	if (status != STORAGE_OK) {
		irc_free(irc);
		return status;
	}

	g_free(irc->nick);
	irc->nick = g_strdup(nnick);

	status = storage_save(irc, FALSE);
	if (status != STORAGE_OK) {
		irc_free(irc);
		return status;
	}
	irc_free(irc);

	storage_remove(onick, password);

	return STORAGE_OK;
}
Beispiel #8
0
void irc_free(irc_t * irc)
{
	GSList *l;

	irc->status |= USTATUS_SHUTDOWN;

	log_message(LOGLVL_INFO, "Destroying connection with fd %d", irc->fd);

	if (irc->status & USTATUS_IDENTIFIED && set_getbool(&irc->b->set, "save_on_quit")) {
		if (storage_save(irc, NULL, TRUE) != STORAGE_OK) {
			log_message(LOGLVL_WARNING, "Error while saving settings for user %s", irc->user->nick);
		}
	}

	for (l = irc_plugins; l; l = l->next) {
		irc_plugin_t *p = l->data;
		if (p->irc_free) {
			p->irc_free(irc);
		}
	}

	irc_connection_list = g_slist_remove(irc_connection_list, irc);

	while (irc->queries != NULL) {
		query_del(irc, irc->queries);
	}

	/* This is a little bit messy: bee_free() frees all b->users which
	   calls us back to free the corresponding irc->users. So do this
	   before we clear the remaining ones ourselves. */
	bee_free(irc->b);

	while (irc->users) {
		irc_user_free(irc, (irc_user_t *) irc->users->data);
	}

	while (irc->channels) {
		irc_channel_free(irc->channels->data);
	}

	if (irc->ping_source_id > 0) {
		b_event_remove(irc->ping_source_id);
	}
	if (irc->r_watch_source_id > 0) {
		b_event_remove(irc->r_watch_source_id);
	}
	if (irc->w_watch_source_id > 0) {
		b_event_remove(irc->w_watch_source_id);
	}

	closesocket(irc->fd);
	irc->fd = -1;

	g_hash_table_foreach_remove(irc->nick_user_hash, irc_free_hashkey, NULL);
	g_hash_table_destroy(irc->nick_user_hash);

	g_hash_table_foreach_remove(irc->watches, irc_free_hashkey, NULL);
	g_hash_table_destroy(irc->watches);

	if (irc->iconv != (GIConv) - 1) {
		g_iconv_close(irc->iconv);
	}
	if (irc->oconv != (GIConv) - 1) {
		g_iconv_close(irc->oconv);
	}

	g_free(irc->sendbuffer);
	g_free(irc->readbuffer);
	g_free(irc->password);

	g_free(irc);

	if (global.conf->runmode == RUNMODE_INETD ||
	    global.conf->runmode == RUNMODE_FORKDAEMON ||
	    (global.conf->runmode == RUNMODE_DAEMON &&
	     global.listen_socket == -1 &&
	     irc_connection_list == NULL)) {
		b_main_quit();
	}
}