|
From: <he...@us...> - 2008-08-12 17:58:05
|
Revision: 160
http://pdbsql.svn.sourceforge.net/pdbsql/?rev=160&view=rev
Author: herwinw
Date: 2008-08-12 17:58:14 +0000 (Tue, 12 Aug 2008)
Log Message:
-----------
* Placed all mysql queries/reconnect/printing debug information in one central function (saves a lot of duplicate code)
* Removed all // comments from pdb_mysql.c and pdb_sql.c (according to samba coding guidelines it's bad)
Modified Paths:
--------------
branches/pdbsql_32-test/pdb_mysql.c
branches/pdbsql_32-test/pdb_sql.c
Modified: branches/pdbsql_32-test/pdb_mysql.c
===================================================================
--- branches/pdbsql_32-test/pdb_mysql.c 2008-08-11 22:08:42 UTC (rev 159)
+++ branches/pdbsql_32-test/pdb_mysql.c 2008-08-12 17:58:14 UTC (rev 160)
@@ -88,6 +88,37 @@
return NT_STATUS_OK;
}
+static bool pdb_mysql_query(struct pdb_mysql_data *data, char *query, int *mysql_ret)
+{
+ int res;
+
+ DEBUG(5, ("Executing query %s\n", query));
+ res = mysql_query(data->handle, query);
+
+ /* [SYN] If the server has gone away, reconnect and retry */
+ if (res && mysql_errno(data->handle) == CR_SERVER_GONE_ERROR) {
+ DEBUG(5, ("MySQL server has gone away, reconnecting and retrying.\n"));
+
+ /* [SYN] Reconnect */
+ if (!NT_STATUS_IS_OK(pdb_mysql_connect(data))) {
+ DEBUG(0, ("Error: Lost connection to MySQL server\n"));
+ return False;
+ }
+ /* [SYN] Retry */
+ res = mysql_query(data->handle, query);
+ }
+
+ if (res)
+ {
+ DEBUG(0,
+ ("Error while executing MySQL query %s\n",
+ mysql_error(data->handle)));
+ }
+
+ *mysql_ret = res;
+ return True;
+}
+
static NTSTATUS row_to_sam_account(MYSQL_RES * r, struct samu * u)
{
MYSQL_ROW row;
@@ -204,34 +235,14 @@
talloc_free(esc_sname);
- DEBUG(5, ("Executing query %s\n", query));
-
- mysql_ret = mysql_query(data->handle, query);
-
- /* [SYN] If the server has gone away, reconnect and retry */
- if (mysql_ret && mysql_errno(data->handle) == CR_SERVER_GONE_ERROR) {
- DEBUG(5, ("MySQL server has gone away, reconnecting and retrying.\n"));
-
- /* [SYN] Reconnect */
- if (!NT_STATUS_IS_OK(pdb_mysql_connect(data))) {
- DEBUG(0, ("Error: Lost connection to MySQL server\n"));
- talloc_free(query);
- return NT_STATUS_UNSUCCESSFUL;
- }
- /* [SYN] Retry */
- mysql_ret = mysql_query(data->handle, query);
- }
-
- talloc_free(query);
-
- if (mysql_ret) {
- DEBUG(0,
- ("Error while executing MySQL query %s\n",
- mysql_error(data->handle)));
+ if (pdb_mysql_query(data, query, &mysql_ret) == False)
+ {
+ talloc_free(query);
talloc_free(mem_ctx);
return NT_STATUS_UNSUCCESSFUL;
}
+ talloc_free(query);
res = mysql_store_result(data->handle);
if (res == NULL) {
DEBUG(0,
@@ -281,7 +292,7 @@
SET_DATA(data, methods);
sid_to_fstring(sid_str, sid);
- // sid_string_dbg(sid);
+ /* sid_string_dbg(sid); */
return mysqlsam_select_by_field(methods, user, SQL_SEARCH_USER_SID, sid_str);
}
@@ -338,32 +349,15 @@
talloc_free(esc);
- mysql_ret = mysql_query(data->handle, query);
-
- /* [SYN] If the server has gone away, reconnect and retry */
- if (mysql_ret && mysql_errno(data->handle) == CR_SERVER_GONE_ERROR) {
- DEBUG(5, ("MySQL server has gone away, reconnecting and retrying.\n"));
-
- /* [SYN] Reconnect */
- if (!NT_STATUS_IS_OK(pdb_mysql_connect(data))) {
- DEBUG(0, ("Error: Lost connection to MySQL server\n"));
- talloc_free(query);
- return NT_STATUS_UNSUCCESSFUL;
- }
- /* [SYN] Retry */
- mysql_ret = mysql_query(data->handle, query);
- }
-
- talloc_free(query);
-
- if (mysql_ret) {
- DEBUG(0,
- ("Error while executing query: %s\n",
- mysql_error(data->handle)));
+ if (pdb_mysql_query(data, query, &mysql_ret) == False)
+ {
+ talloc_free(query);
talloc_free(mem_ctx);
return NT_STATUS_UNSUCCESSFUL;
}
+ talloc_free(query);
+
DEBUG(5, ("User '%s' deleted\n", sname));
talloc_free(mem_ctx);
return NT_STATUS_OK;
@@ -392,33 +386,14 @@
if ( query == NULL ) /* Nothing to update. */
return NT_STATUS_OK;
- /* Execute the query */
- mysql_ret = mysql_query(data->handle, query);
- /* [SYN] If the server has gone away, reconnect and retry */
- if (mysql_ret && mysql_errno(data->handle) == CR_SERVER_GONE_ERROR) {
- DEBUG(5, ("MySQL server has gone away, reconnecting and retrying.\n"));
-
- /* [SYN] Reconnect */
- if (!NT_STATUS_IS_OK(pdb_mysql_connect(data))) {
- DEBUG(0, ("Error: Lost connection to MySQL server\n"));
- talloc_free(query);
- return NT_STATUS_UNSUCCESSFUL;
- }
- /* [SYN] Retry */
- mysql_ret = mysql_query(data->handle, query);
- }
-
- if (mysql_ret) {
- DEBUG(0,
- ("Error executing %s, %s\n", query,
- mysql_error(data->handle)));
+ if (pdb_mysql_query(data, query, &mysql_ret) == False)
+ {
talloc_free(query);
- return NT_STATUS_INVALID_PARAMETER;
+ return NT_STATUS_UNSUCCESSFUL;
}
talloc_free(query);
-
return NT_STATUS_OK;
}
@@ -444,7 +419,7 @@
uint32_t acct_flags;
MYSQL_RES *pwent;
-// struct samr_displayentry *entries;
+ /* struct samr_displayentry *entries; */
uint32_t num_entries;
uint32_t current;
};
@@ -461,8 +436,6 @@
return false;
}
-
-
row = mysql_fetch_row(state->pwent);
if (row[18]) {
string_to_sid(&sid, row[18]);
@@ -483,7 +456,6 @@
if ((entry->acct_flags & state->acct_flags) != state->acct_flags) {
return mysqlsam_search_next_entry(search, entry);
-
}
return true;
@@ -517,33 +489,17 @@
}
state->acct_flags = acct_flags;
-//
+
query = sql_account_query_select(NULL, data->location, False, SQL_SEARCH_NONE, NULL);
- mysql_ret = mysql_query(data->handle, query);
-
-// /* [SYN] If the server has gone away, reconnect and retry */
- if (mysql_ret && mysql_errno(data->handle) == CR_SERVER_GONE_ERROR) {
- DEBUG(5, ("MySQL server has gone away, reconnecting and retrying.\n"));
-
-// /* [SYN] Reconnect */
- if (!NT_STATUS_IS_OK(pdb_mysql_connect(data))) {
- DEBUG(0, ("Error: Lost connection to MySQL server\n"));
- talloc_free(query);
- return false;
- }
-// /* [SYN] Retry */
- mysql_ret = mysql_query(data->handle, query);
+ if (pdb_mysql_query(data, query, &mysql_ret) == False)
+ {
+ talloc_free(query);
+ return False;
}
-
+
talloc_free(query);
- if (mysql_ret) {
- DEBUG(0,
- ("Error executing MySQL query %s\n", mysql_error(data->handle)));
- return false;
- }
-
state->pwent = mysql_store_result(data->handle);
if (state->pwent == NULL) {
Modified: branches/pdbsql_32-test/pdb_sql.c
===================================================================
--- branches/pdbsql_32-test/pdb_sql.c 2008-08-11 22:08:42 UTC (rev 159)
+++ branches/pdbsql_32-test/pdb_sql.c 2008-08-12 17:58:14 UTC (rev 160)
@@ -412,7 +412,7 @@
config_value_write(location, "user sid column",
CONFIG_USER_SID_DEFAULT),
sid_to_fstring(sid_str,
-// sid_string_dbg(sid,
+ /* sid_string_dbg(sid, */
pdb_get_user_sid(newpwd)));
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|