当 mod_dbd 不支持我的驱动程序时,我应该如何将 DB Conn 保留在 Apache 中?
我正在从 Linux Apache 2.x 主机使用到 SQL Server 的 ODBTP 接口。 mod_dbm 不支持这一点,我需要能够将代码移动到任何支持 Apache 的主机。
关于我的环境的说明:我正在使用 Apache 2.2.17、用 C for Apache 封装的 C++、ODBTP 1.14、SQL Server 2008。
我已经成功实现了 ODBTP 连接,并且能够充分使用模块本身内的数据,但我想保持连接,而不是连续连接、断开连接,然后重新开始我的应用程序,该应用程序使用本地 HTTP 调用以 JSON 格式检索数据。
问题是我需要在一个我不信任纯文本编写应用程序的安全性的环境中部署此应用程序和模块,以通过数据库凭据进行安全保护。当应用程序通过 HTTP 连接时,它仅提供加密的凭据,我的模块会在发送到数据库之前对其进行解密。
我当前正在为数据库创建一个句柄并将其存储在模块定义中的带键 apr_hash_t 表中。应用程序连接后,模块会查找应用程序在 URL 中指定的唯一的每个请求令牌,以查找该应用程序的连接。这有效,但只能一次。
哈希密钥是 32 位密钥,最初是从池中创建的 char *,并与 ODBTP 句柄一起作为哈希表中的一行存储。不知何故,调用之间的密钥正在被修改,原始密钥现在是截断版本。
例子: 1) 我从我的应用程序中进行 1 次调用来启动持久连接。这有效。 2) 我从应用程序中进行了 3 次连续调用来执行 sql 字符串。 (/stars/execute_sql/unique/<>/sql/<>) x 3
第一次调用非常完美,我检索了数据。 下一次调用保存为密钥的令牌被截断,并且模块找不到关联的密钥。 下一次调用令牌处于与尝试 2 相同的截断状态。
我不确定是否覆盖内存?我编写了一个短循环函数来吐出哈希表的内容,以便我可以在代码中的每个点上粘贴该函数,以找出数据可能已损坏的位置,但我的发现没有任何意义。我必须拆分 uri 才能找到嵌入在 uri 中的数据。我跟踪内存转移到该函数中的一行“raw = apr_psprintf(apache->pool,"%s", subject);”这是在下面的代码中。
void theRequest::get_exploded_str(char *subject, char *delimiter)
{
// variables
char *raw, *next, *last;
// create the split chars database if not created
loadSDB();
apr_array_clear(x_split_chars);
subject = apr_pstrndup(apache->pool, subject, string(subject).length());
raw = apr_psprintf(apache->pool,"%s", subject);
next = (char*)apr_strtok(raw, delimiter, &last);
while (next)
{
// add next to array
*(char **) apr_array_push(x_split_chars) = apr_pstrdup(apache->pool, next);
// fetch next
next = (char*)apr_strtok(NULL, delimiter, &last);
}
return;
};
它在呼叫 1 上工作得很好,但在呼叫 2 上却不行,因为密钥以某种方式发生了转移。
有什么想法吗?或者甚至是关于如何使用 APR_RESLIST 更好地完成此任务的一些想法?
提前致谢!
I am working with the ODBTP interface to SQL Server from a Linux Apache 2.x host. mod_dbm does not support this and I require being able to move the code to any host that supports Apache.
A note on my environment: I am using the Apache 2.2.17, C++ wrapped in C for Apache, ODBTP 1.14, SQL Server 2008.
I have successfully implemented the ODBTP connections and I am able to fully use the data within the module itself, but i wanted to persist the connections rather continuously connecting, disconnecting, and starting over again for my application that uses local HTTP calls to the retrieve data in a JSON format.
The issue is that I need to deploy this application and module in an environment where I do not trust the security of the plain text written application, to safely guard by the database credentials. When the application connects over HTTP, it provides only encrypted credentials that my module decrypts before sending to the database.
I am currently creating a handle for the database and storing it in a keyed apr_hash_t table in the module definition. Once the application connects, the module looks up the unique per request token that the application specifies in the URL to find the connection for that application. This works but only one time.
The hash key is 32 digit key that is initially a char * created out of the pool, and stored with the ODBTP handle as a row in the hash table. Some how, the key in between calls is being modified and the original key is now a truncated version.
Example:
1) I make 1 call from my application to start a persisted connection. This works.
2) I make 3 back to back calls from my application to execute a sql string.
(/stars/execute_sql/unique/<>/sql/<>) x 3
The first call is perfect and I retrieve the data.
The next call the token saved as the key is truncated and the module can't find the associated key.
The next call the token is in the same truncated state as in attempt 2.
I am not sure if I am overwriting memory or not? I wrote a short loop function to spit out the contents of the hash table so that i could stick the function at every point in my code to find out where the data may have been corrupted, but my findings make no sense. I have to split the uri in order to find data embedded in the uri. I tracked the memory shifting to a line in this function as "raw = apr_psprintf(apache->pool,"%s", subject);" which is in the code below.
void theRequest::get_exploded_str(char *subject, char *delimiter)
{
// variables
char *raw, *next, *last;
// create the split chars database if not created
loadSDB();
apr_array_clear(x_split_chars);
subject = apr_pstrndup(apache->pool, subject, string(subject).length());
raw = apr_psprintf(apache->pool,"%s", subject);
next = (char*)apr_strtok(raw, delimiter, &last);
while (next)
{
// add next to array
*(char **) apr_array_push(x_split_chars) = apr_pstrdup(apache->pool, next);
// fetch next
next = (char*)apr_strtok(NULL, delimiter, &last);
}
return;
};
It works perfectly on call 1, but not on call 2, because the key is being shifted somehow.
Any ideas? Or even some thoughts on how I could use APR_RESLIST to accomplish this better?
Thanks in Advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现我无法直接通过应用程序进行池化,而是通过 ODBTP 库本身进行池化。由于它是 TCP 到 ODBC 的桥接器,因此能够在一定程度上汇集连接,但效率不够高。
不过,由于服务器环境发生变化,我已经放弃了这个任务,转而使用 SQLite3 作为应用程序数据库。
I found that I was unable to directly pool via the application but through the ODBTP library itself. Being that it is a TCP to ODBC bridge it was able to pool the connections to a degree, but not efficiently enough.
I have abandoned this mission though and have move to using SQLite3 for the application database because of a server environment change.