From: Frank Schlottmann-G. <fs...@us...> - 2001-05-13 13:37:35
|
Update of /cvsroot/firebird/interbase/jrd In directory usw-pr-cvs1:/tmp/cvs-serv27275/interbase/jrd Modified Files: jrd.c jrd.h pwd.c pwd.h pwd_proto.h scl.e scl_proto.h shrinit.c tra.c Log Message: Finally removed my "revolving backdoor" hack and replaced it with Borland's (Stanialav Tsikin's?) solution to the problem. fsg Index: jrd.c =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/jrd.c,v retrieving revision 1.4 retrieving revision 1.5 diff -U3 -r1.4 -r1.5 --- jrd.c 2001/05/07 07:23:23 1.4 +++ jrd.c 2001/05/13 13:37:33 1.5 @@ -478,6 +478,8 @@ UCHAR *p1, *p2; SSHORT cnt, len; BOOLEAN delimited_done = FALSE; +BOOLEAN internal; +IHNDL ihandle; API_ENTRY_POINT_INIT; @@ -861,9 +863,19 @@ options.dpb_sql_dialect = 0; +/* Don't run internal handles thru the security gauntlet. */ + +internal = FALSE; +for (ihandle = internal_db_handles; ihandle; ihandle = ihandle->ihndl_next) + if (ihandle->ihndl_object == (isc_db_handle *) handle) + { + internal = TRUE; + break; + } + SCL_init (FALSE, options.dpb_sys_user_name, options.dpb_user_name, options.dpb_password, options.dpb_password_enc, - options.dpb_role_name, tdbb); + options.dpb_role_name, tdbb, internal); #ifdef V4_THREADING initing_security = FALSE; V4_JRD_MUTEX_LOCK (dbb->dbb_mutexes + DBB_MUTX_init_fini); @@ -1541,6 +1553,8 @@ JMP_BUF env1; #endif struct tdbb thd_context, *tdbb = NULL; +BOOLEAN internal; +IHNDL ihandle; API_ENTRY_POINT_INIT; @@ -1726,9 +1740,20 @@ V4_JRD_MUTEX_UNLOCK (dbb->dbb_mutexes + DBB_MUTX_init_fini); initing_security = TRUE; #endif + +/* Don't run internal handles thru the security gauntlet. */ + +internal = FALSE; +for (ihandle = internal_db_handles; ihandle; ihandle = ihandle->ihndl_next) + if (ihandle->ihndl_object == (isc_db_handle *) handle) + { + internal = TRUE; + break; + } + SCL_init (TRUE, options.dpb_sys_user_name, options.dpb_user_name, options.dpb_password, options.dpb_password_enc, - options.dpb_role_name, tdbb); + options.dpb_role_name, tdbb, internal); #ifdef V4_THREADING initing_security = FALSE; V4_JRD_MUTEX_LOCK (dbb->dbb_mutexes + DBB_MUTX_init_fini); Index: jrd.h =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/jrd.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- jrd.h 2000/08/03 20:50:53 1.1.1.1 +++ jrd.h 2001/05/13 13:37:33 1.2 @@ -696,6 +696,13 @@ #define TDBB_no_cache_unwind 2 /* Don't unwind page buffer cache */ #define TDBB_prc_being_dropped 4 /* Dropping a procedure */ +/* List of internal database handles */ + +typedef struct ihndl { + struct ihndl *ihndl_next; + void *ihndl_object; +} *IHNDL; + /* Threading macros */ #ifdef GET_THREAD_DATA @@ -794,11 +801,14 @@ #ifndef SHLIB_DEFS #ifdef JRD_MAIN int debug; +IHNDL internal_db_handles = 0; #else extern int debug; +extern IHNDL internal_db_handles; #endif #else extern int debug; +extern IHNDL internal_db_handles; #endif #endif /* REQUESTER */ Index: pwd.c =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/pwd.c,v retrieving revision 1.6 retrieving revision 1.7 diff -U3 -r1.6 -r1.7 --- pwd.c 2000/12/23 10:59:47 1.6 +++ pwd.c 2001/05/13 13:37:33 1.7 @@ -102,9 +102,8 @@ isc_tpb_wait }; static BOOLEAN lookup_user (TEXT *, int *, int *, TEXT *); -static BOOLEAN open_user_db (SLONG **, SLONG *); +static BOOLEAN open_user_db (isc_db_handle *, SLONG *); - /* kludge to make sure pwd sits below why.c on the PC (Win16) platform */ #ifdef WINDOWS_ONLY @@ -119,50 +118,7 @@ #define isc_start_transaction jrd8_start_transaction #endif - - -static char ls_user[12]="Firebird "; -static char ls_pw[8]="Phoenix"; - - -void mk_pwd(TEXT *pw) -{ - unsigned char i=0; - unsigned char j=0; - -/* I hope that this will work on all platforms - FSG 22.Dez.2000 -*/ - srand( (unsigned)time (NULL)); - for (i=0; i < strlen(pw); i++) - { - j=1+(int) (255.0*rand()/(RAND_MAX+1.0)); - pw[i]=j; - } -} - -char *PWD_ls_user() -{ - if (strcmp(ls_user,"Firebird ")==0) - { - mk_pwd(ls_user); - } - return ls_user; -} - - -char *PWD_ls_pw() - -{ - if (strcmp(ls_pw,"Phoenix")==0) - { - mk_pwd(ls_pw); - } - return ls_pw; -} - - - + void PWD_get_user_dbpath ( TEXT *path_buffer) { @@ -262,7 +218,7 @@ * **************************************/ BOOLEAN notfound; /* user found flag */ -SLONG *uinfo; /* database handle */ +isc_db_handle uinfo; /* database handle */ SLONG *lookup_trans; /* default transaction handle */ STATUS status [20]; /* status vector */ SLONG *lookup_req; /* request handle */ @@ -347,7 +303,7 @@ } static BOOLEAN open_user_db ( - SLONG **uihandle, + isc_db_handle *uihandle, SLONG *status) { /************************************** @@ -366,21 +322,31 @@ **************************************/ TEXT user_info_name [MAX_PATH_LENGTH]; BOOLEAN notopened; /* open/not open flag */ -SLONG *uinfo; /* database handle */ +isc_db_handle uinfo; /* database handle */ +IHNDL ihandle; SCHAR *p, *dpb, dpb_buffer [256]; SSHORT dpb_len; -TEXT locksmith_password_enc [33]; #ifdef WINDOWS_ONLY SCHAR *expanded_name; #endif -/* Encrypt and copy locksmith's password under the global scheduler's - mutex since the implementation of the encryption isn't thread-safe - on most of our platforms. */ +/* Register as internal database handle */ +for (ihandle = internal_db_handles; ihandle; ihandle = ihandle->ihndl_next) + if (ihandle->ihndl_object == NULL) + { + ihandle->ihndl_object = &uinfo; + break; + } +if (!ihandle) + { + ihandle = (IHNDL) gds__alloc ((SLONG) sizeof (struct ihndl)); + ihandle->ihndl_object = &uinfo; + ihandle->ihndl_next = internal_db_handles; + internal_db_handles = ihandle; + } -strcpy (locksmith_password_enc, ENC_crypt (LOCKSMITH_PASSWORD, PASSWORD_SALT)); THREAD_EXIT; /* initialize the data base's name */ @@ -400,13 +366,13 @@ *dpb++ = gds__dpb_version1; *dpb++ = gds__dpb_user_name; -*dpb++ = strlen (LOCKSMITH_USER); -p = LOCKSMITH_USER; +p = "authenticator"; +*dpb++ = strlen (p); while (*p) *dpb++ = *p++; -*dpb++ = gds__dpb_password_enc; -p = locksmith_password_enc + 2; +*dpb++ = gds__dpb_password; +p = "none"; *dpb++ = strlen (p); while (*p) *dpb++ = *p++; @@ -421,7 +387,7 @@ if (status [1] == gds__login) { /* we may be going against a V3 database which does not - * understand the "hello, god" combination. + * understand this combination. */ isc_attach_database (status, 0, user_info_name, &uinfo, 0, 0); @@ -430,6 +396,9 @@ if (status [1]) notopened = TRUE; *uihandle = uinfo; + +assert (ihandle->ihndl_object == &uinfo); +ihandle->ihndl_object = NULL; #ifdef WINDOWS_ONLY gds__free( (SLONG*)expanded_name); Index: pwd.h =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/pwd.h,v retrieving revision 1.5 retrieving revision 1.6 diff -U3 -r1.5 -r1.6 --- pwd.h 2000/12/23 02:14:20 1.5 +++ pwd.h 2001/05/13 13:37:33 1.6 @@ -30,9 +30,6 @@ #define PASSWORD_SALT "9z" #define MAX_PASSWORD_ENC_LENGTH 12 -#define LOCKSMITH_USER PWD_ls_user() -#define LOCKSMITH_PASSWORD PWD_ls_pw() - #ifdef APOLLO #define USER_INFO_NAME "/interbase/isc4.gdb" #endif @@ -40,7 +37,7 @@ #ifdef VMS #define USER_INFO_NAME "[sysmgr]isc4.gdb" #endif - + #if (defined WINDOWS_ONLY || defined WIN_NT) #define USER_INFO_NAME "isc4.gdb" #endif Index: pwd_proto.h =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/pwd_proto.h,v retrieving revision 1.2 retrieving revision 1.3 diff -U3 -r1.2 -r1.3 --- pwd_proto.h 2000/12/22 16:05:05 1.2 +++ pwd_proto.h 2001/05/13 13:37:33 1.3 @@ -28,7 +28,5 @@ extern void PWD_get_user_dbpath (TEXT *); extern void PWD_verify_user (TEXT *, TEXT *, TEXT *, TEXT *, int *, int *, int *); -extern char *PWD_ls_user(void); -extern char *PWD_ls_pw(void); #endif /* _JRD_PWD_PROTO_H_ */ Index: scl.e =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/scl.e,v retrieving revision 1.2 retrieving revision 1.3 diff -U3 -r1.2 -r1.3 --- scl.e 2001/04/11 17:16:19 1.2 +++ scl.e 2001/05/13 13:37:33 1.3 @@ -29,7 +29,6 @@ #include "../jrd/jrd.h" #include "../jrd/ods.h" #include "../jrd/scl.h" -#include "../jrd/pwd.h" #include "../jrd/acl.h" #include "../jrd/blb.h" #include "../jrd/irq.h" @@ -40,7 +39,6 @@ #include "../jrd/all_proto.h" #include "../jrd/blb_proto.h" #include "../jrd/cmp_proto.h" -#include "../jrd/enc_proto.h" #include "../jrd/err_proto.h" #include "../jrd/exe_proto.h" #include "../jrd/gds_proto.h" @@ -505,7 +503,8 @@ TEXT *password, TEXT *password_enc, TEXT *sql_role, - TDBB tdbb) + TDBB tdbb, + BOOLEAN internal) { /************************************** * @@ -529,9 +528,6 @@ TEXT name [129], project [33], organization [33], *p; USHORT length; int id, group, wheel, node_id; -TEXT locksmith_password[20]; -TEXT locksmith_password_enc[33]; -TEXT user_locksmith[20]; TEXT role_name[33], login_name [129], *q; USHORT major_version, minor_original; @@ -559,11 +555,7 @@ if ((user_name == NULL) || ((password_enc == NULL) && (password == NULL))) ERR_post (gds__login, 0); - strcpy (locksmith_password, LOCKSMITH_PASSWORD); - strcpy (user_locksmith, LOCKSMITH_USER); - strcpy (locksmith_password_enc, ENC_crypt (locksmith_password, PASSWORD_SALT)); - if (strcmp (user_name, user_locksmith) || (password_enc == NULL) || - strcmp (password_enc, locksmith_password_enc + 2)) + if (!internal) PWD_verify_user (name, user_name, password, password_enc, &id, &group, &node_id); Index: scl_proto.h =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/scl_proto.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- scl_proto.h 2000/08/03 20:51:17 1.1.1.1 +++ scl_proto.h 2001/05/13 13:37:33 1.2 @@ -30,7 +30,7 @@ extern struct scl *SCL_get_class (TEXT *); extern int SCL_get_mask (TEXT *, TEXT *); extern void SCL_init (BOOLEAN, TEXT *, TEXT *, TEXT *, - TEXT *, TEXT *, TDBB); + TEXT *, TEXT *, TDBB, BOOLEAN); extern void SCL_move_priv (UCHAR **, USHORT, STR *, ULONG *); extern struct scl *SCL_recompute_class (TDBB, TEXT *); extern void SCL_release (struct scl *); Index: shrinit.c =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/shrinit.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- shrinit.c 2000/08/03 20:51:19 1.1.1.1 +++ shrinit.c 2001/05/13 13:37:33 1.2 @@ -287,6 +287,7 @@ int DSQL_yychar = 0; int *DSQL_hash_table = 0; void *gdbb = 0; +int *internal_db_handles = 0; #ifdef IMP /**** Index: tra.c =================================================================== RCS file: /cvsroot/firebird/interbase/jrd/tra.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -U3 -r1.1.1.1 -r1.2 --- tra.c 2000/08/03 20:51:32 1.1.1.1 +++ tra.c 2001/05/13 13:37:33 1.2 @@ -3086,35 +3086,26 @@ * Sweep database. * **************************************/ -SLONG db_handle; +isc_db_handle db_handle; +IHNDL ihandle; STATUS status_vector [ISC_STATUS_LENGTH]; UCHAR *dpb; SSHORT dpb_length; UCHAR *q; UCHAR sweep_dpb [100]; -TEXT password_enc[100]; -/* The implementation of the encryption algorithm is not thread-safe - on most of our platforms. Wrap the encryption and copy operation - with the global scheduler's mutex. When we support SMP, we'll have - to do better than this. */ - -THREAD_ENTER; -strcpy (password_enc, (char *)ENC_crypt (LOCKSMITH_PASSWORD, PASSWORD_SALT)); -THREAD_EXIT; - db_handle = NULL; dpb = sweep_dpb; *dpb++ = gds__dpb_version1; *dpb++ = gds__dpb_user_name; -*dpb++ = strlen (LOCKSMITH_USER); -q = LOCKSMITH_USER; +q = "sweeper"; +*dpb++ = strlen (q); while (*q) *dpb++ = *q++; -*dpb++ = gds__dpb_password_enc; -q = password_enc + 2; +*dpb++ = gds__dpb_password; +q = "none"; *dpb++ = strlen (q); while (*q) *dpb++ = *q++; @@ -3124,12 +3115,34 @@ *dpb++ = gds__dpb_records; dpb_length = dpb - sweep_dpb; +/* Register as internal database handle */ + +THREAD_ENTER; +for (ihandle = internal_db_handles; ihandle; ihandle = ihandle->ihndl_next) + if (ihandle->ihndl_object == NULL) + { + ihandle->ihndl_object = &db_handle; + break; + } + +if (!ihandle) + { + ihandle = (IHNDL) gds__alloc ((SLONG) sizeof (struct ihndl)); + ihandle->ihndl_object = &db_handle; + ihandle->ihndl_next = internal_db_handles; + internal_db_handles = ihandle; + } +THREAD_EXIT; + gds__attach_database (status_vector, 0, GDS_VAL (database), GDS_REF (db_handle), dpb_length, GDS_VAL (sweep_dpb)); + +assert (ihandle->ihndl_object == &db_handle); +ihandle->ihndl_object = NULL; if (db_handle) gds__detach_database (status_vector, GDS_REF (db_handle)); |