summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2003-09-21 03:16:05 +0000
committerJelmer Vernooij <jelmer@samba.org>2003-09-21 03:16:05 +0000
commit8031b1655c41a9feecd064f7a125c1dcacb4a292 (patch)
tree06b0d8745759e487e91668c3d8b7e7b891e00c94 /source3
parent2862f64374143e43ffe271ea22cfc73e43bc891b (diff)
downloadsamba-8031b1655c41a9feecd064f7a125c1dcacb4a292.tar.gz
samba-8031b1655c41a9feecd064f7a125c1dcacb4a292.tar.bz2
samba-8031b1655c41a9feecd064f7a125c1dcacb4a292.zip
Fix bug and do more error checking. Noticed by Wilco Baan Hofman <wilco@andoburg.nl>
(This used to be commit ec32501cefe1ea27bcf08b5be9d53cdce8cbbbdc)
Diffstat (limited to 'source3')
-rw-r--r--source3/passdb/pdb_mysql.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/source3/passdb/pdb_mysql.c b/source3/passdb/pdb_mysql.c
index 460e260ddc..7c2c56e359 100644
--- a/source3/passdb/pdb_mysql.c
+++ b/source3/passdb/pdb_mysql.c
@@ -156,7 +156,7 @@ static const char * config_value_write(pdb_mysql_data * data, const char *name,
if (!v)
return NULL;
- swrite = strchr(v, ':');
+ swrite = strrchr(v, ':');
/* Default to the same field as read field */
if (!swrite)
@@ -182,7 +182,7 @@ static const char * config_value_read(pdb_mysql_data * data, const char *name, c
if (!v)
return "NULL";
- swrite = strchr(v, ':');
+ swrite = strrchr(v, ':');
/* If no write is specified, there are no problems */
if (!swrite) {
@@ -241,14 +241,20 @@ static NTSTATUS row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u)
pdb_set_unknown_str(u, row[16], PDB_SET);
pdb_set_munged_dial(u, row[17], PDB_SET);
- if(row[18])string_to_sid(&sid, row[18]);
- pdb_set_user_sid(u, &sid, PDB_SET);
- if(row[19])string_to_sid(&sid, row[19]);
- pdb_set_group_sid(u, &sid, PDB_SET);
+ if(!row[18] || !string_to_sid(&sid, row[18])) {
+ DEBUG(0,("No user SID retrieved from database!\n"));
+ } else {
+ pdb_set_user_sid(u, &sid, PDB_SET);
+ }
+
+ if(row[19]) {
+ string_to_sid(&sid, row[19]);
+ pdb_set_group_sid(u, &sid, PDB_SET);
+ }
- if (pdb_gethexpwd(row[20], temp), PDB_SET)
+ if (pdb_gethexpwd(row[20], temp))
pdb_set_lanman_passwd(u, temp, PDB_SET);
- if (pdb_gethexpwd(row[21], temp), PDB_SET)
+ if (pdb_gethexpwd(row[21], temp))
pdb_set_nt_passwd(u, temp, PDB_SET);
/* Only use plaintext password storage when lanman and nt are
@@ -335,9 +341,9 @@ static NTSTATUS mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update)
CONFIG_LOGON_DIVS_DEFAULT),
config_value_read(data, "hours len column",
CONFIG_HOURS_LEN_DEFAULT),
- config_value_read(data, "bad_password_count column",
+ config_value_read(data, "bad password count column",
CONFIG_BAD_PASSWORD_COUNT_DEFAULT),
- config_value_read(data, "logon_count column",
+ config_value_read(data, "logon count column",
CONFIG_LOGON_COUNT_DEFAULT),
config_value_read(data, "unknown 6 column",
CONFIG_UNKNOWN_6_DEFAULT),
@@ -446,7 +452,7 @@ static NTSTATUS mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOU
}
asprintf(&query,
- "SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s WHERE %s = '%s'",
+ "SELECT %s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s FROM %s WHERE %s = '%s'",
config_value_read(data, "logon time column",
CONFIG_LOGON_TIME_DEFAULT),
config_value_read(data, "logoff time column",
@@ -501,8 +507,10 @@ static NTSTATUS mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOU
CONFIG_LOGON_DIVS_DEFAULT),
config_value_read(data, "hours len column",
CONFIG_HOURS_LEN_DEFAULT),
- config_value_read(data, "unknown 5 column",
- CONFIG_UNKNOWN_5_DEFAULT),
+ config_value_read(data, "bad password count column",
+ CONFIG_BAD_PASSWORD_COUNT_DEFAULT),
+ config_value_read(data, "logon count column",
+ CONFIG_LOGON_COUNT_DEFAULT),
config_value_read(data, "unknown 6 column",
CONFIG_UNKNOWN_6_DEFAULT),
config_value(data, "table", CONFIG_TABLE_DEFAULT), field,
@@ -649,6 +657,7 @@ static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods,
const SAM_ACCOUNT * newpwd, char isupdate)
{
pstring temp;
+ char *field;
struct pdb_mysql_data *data;
pdb_mysql_query query;
fstring sid_str;
@@ -659,6 +668,7 @@ static NTSTATUS mysqlsam_replace_sam_account(struct pdb_methods *methods,
}
data = (struct pdb_mysql_data *) methods->private_data;
+
if (data == NULL || data->handle == NULL) {
DEBUG(0, ("invalid handle!\n"));
return NT_STATUS_INVALID_HANDLE;
@@ -876,6 +886,7 @@ static NTSTATUS mysqlsam_init(struct pdb_context * pdb_context, struct pdb_metho
{
NTSTATUS nt_status;
struct pdb_mysql_data *data;
+ const char *sid_column, *username_column;
mysqlsam_debug_level = debug_add_class("mysqlsam");
if (mysqlsam_debug_level == -1) {
@@ -884,6 +895,7 @@ static NTSTATUS mysqlsam_init(struct pdb_context * pdb_context, struct pdb_metho
("mysqlsam: Couldn't register custom debugging class!\n"));
}
+
if (!pdb_context) {
DEBUG(0, ("invalid pdb_methods specified\n"));
return NT_STATUS_UNSUCCESSFUL;
@@ -931,6 +943,14 @@ static NTSTATUS mysqlsam_init(struct pdb_context * pdb_context, struct pdb_metho
DEBUG(0, ("Failed to connect to server\n"));
return NT_STATUS_UNSUCCESSFUL;
}
+
+ sid_column = config_value_read(data, "user sid column", CONFIG_USER_SID_DEFAULT);
+ username_column = config_value_read(data, "username column", CONFIG_USERNAME_DEFAULT);
+ if(!strcmp(sid_column,"NULL") || !strcmp(username_column, "NULL")) {
+ DEBUG(0,("Please specify both a valid 'user sid column' and a valid 'username column' in smb.conf\n"));
+ return NT_STATUS_UNSUCCESSFUL;
+ }
+
/* Process correct entry in $HOME/.my.conf */
if (!mysql_real_connect(data->handle,
config_value(data, "mysql host", CONFIG_HOST_DEFAULT),