2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include <tzplatform_config.h>
30 #define DBPATH_LEN_MAX 4096
31 #define ERR_BUF_MAX 1024
33 char *_rua_util_get_db_path(uid_t uid, char *db_name)
35 char db_path[DBPATH_LEN_MAX];
39 tzplatform_set_user(uid);
40 db_path_prefix = tzplatform_getenv(TZ_USER_DB);
41 tzplatform_reset_user();
43 snprintf(db_path, sizeof(db_path), "%s/%s", db_path_prefix, db_name);
44 LOGD("db path %s", db_path);
46 return strdup(db_path);
49 int _rua_util_open_db(sqlite3 **db, int flags, uid_t uid, char *db_name)
52 char *db_path = _rua_util_get_db_path(uid, db_name);
53 if (db_path == NULL) {
54 LOGE("out of memory _rua_util_get_db_path fail");
58 r = db_util_open_with_options(db_path, db, flags, NULL);
60 LOGE("db util open error(%d/%d/%d/%s)", r,
62 sqlite3_extended_errcode(*db),
72 int _rua_util_check_uid(uid_t target_uid)
75 if (uid > BASE_UID && uid != target_uid) {
76 LOGE("Invalid UID : %d, target UID : %d", uid, target_uid);