/
gsec.cpp
1460 lines (1318 loc) · 38.2 KB
/
gsec.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* PROGRAM: Security data base manager
* MODULE: gsec.cpp
* DESCRIPTION: Main line routine
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "firebird.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include "../jrd/common.h"
#include "../jrd/ibase.h"
#include "../jrd/gds_proto.h"
#include "../jrd/msg_encode.h"
#include "../jrd/isc_f_proto.h"
#include "../utilities/gsec/gsec.h"
#include "../utilities/gsec/gsec_proto.h"
#include "../jrd/jrd_pwd.h"
#include "../jrd/license.h"
#include "../jrd/svc.h"
#include "../jrd/svc_proto.h"
#include "../utilities/gsec/secur_proto.h"
#include "../utilities/gsec/gsecswi.h"
#include "../utilities/common/cmd_util_proto.h"
#include "../common/classes/ClumpletWriter.h"
#include "../utilities/gsec/call_service.h"
#include "../common/utils_proto.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef WIN_NT
#include <io.h>
#endif
#if defined (WIN95)
static bool fAnsiCP = false;
#define TRANSLATE_CP(a) if (!fAnsiCP) CharToOem(a, a)
#else
#define TRANSLATE_CP(a)
#endif
const int MAXARGS = 20; /* max number of args allowed on command line */
const int MAXSTUFF = 1000; /* longest interactive command line */
#ifndef SERVICE_THREAD
class tsec *gdsec;
#endif
static int common_main(int, const char**, Jrd::pfn_svc_output, Jrd::Service*);
static void util_output(const SCHAR*, ...);
static int util_print(const SCHAR*, ...);
static int vutil_print(SCHAR*, va_list);
static void data_print(void*, const internal_user_data*, bool);
static bool get_line(int*, SCHAR**, TEXT*, size_t);
static bool get_switches(int, const TEXT* const*, const in_sw_tab_t*, tsec*, bool*);
static SSHORT parse_cmd_line(int, const TEXT* const*, tsec*);
static void printhelp(void);
#ifndef SERVICE_THREAD
static int output_main(Jrd::Service*, const UCHAR*);
#endif
inline void msg_get(USHORT number, TEXT* msg);
void inline gsec_exit(int code, tsec* tdsec)
{
tdsec->tsec_exit_code = code;
if (tdsec->tsec_throw)
Firebird::LongJump::raise();
}
#ifdef SERVICE_THREAD
THREAD_ENTRY_DECLARE GSEC_main(THREAD_ENTRY_PARAM arg)
{
/**********************************************
*
* G S E C _ m a i n
*
**********************************************
* Functional Description:
* Entrypoint for GSEC via the services manager
**********************************************/
Jrd::Service* service = (Jrd::Service*)arg;
const int exit_code = common_main(service->svc_argc, service->svc_argv.begin(),
SVC_output, service);
/* Mark service thread as finished. */
/* If service is detached, cleanup memory being used by service. */
SVC_finish(service, Jrd::SVC_finished);
return (THREAD_ENTRY_RETURN)(IPTR)(exit_code);
}
#else
int CLIB_ROUTINE main( int argc, const char* argv[])
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
* If there is no command line, prompt for one, read it
* and make an artificial argc/argv. Otherwise, pass
* the specified argc/argv to SECURITY_exec_line (see below).
*
**************************************/
return common_main(argc, argv, output_main, NULL);
}
static int output_main(Jrd::Service* output_data, const UCHAR* output_buf)
{
/**************************************
*
* o u t p u t _ m a i n
*
**************************************
*
* Functional description
* Routine which is passed to GBAK for calling back when there is output.
*
**************************************/
// fprintf(stderr, "%s", output_buf);
fprintf(stdout, "%s", output_buf);
return 0;
}
inline void envPick(TEXT* dest, size_t size, const TEXT* var)
{
if (dest && (!dest[0]))
{
Firebird::string val;
if (fb_utils::readenv(var, val))
val.copyTo(dest, size);
}
}
#endif /* SERVICE_THREAD */
int common_main(int argc,
const char* argv[],
Jrd::pfn_svc_output output_proc,
Jrd::Service* output_data)
{
/**************************************
*
* c o m m o n _ m a i n
*
**************************************
*
* Functional description
* If there is no command line, prompt for one, read it
* and make an artificial argc/argv. Otherwise, pass
* the specified argc/argv to SECURITY_exec_line (see below).
*
**************************************/
TEXT stuff[MAXSTUFF]; /* a place to put stuff */
#ifdef VMS
argc = VMS_parse(&argv, argc);
#endif
tsec tsecInstance(output_proc, output_data);
tsec* tdsec = &tsecInstance;
tsec::putSpecific(tdsec);
internal_user_data u;
tdsec->tsec_user_data = &u;
try {
/* Perform some special handling when run as an Interbase service. The
first switch can be "-svc" (lower case!) or it can be "-svc_re" followed
by 3 file descriptors to use in re-directing stdin, stdout, and stderr. */
tdsec->tsec_throw = true;
tdsec->tsec_interactive = true;
internal_user_data* user_data = tdsec->tsec_user_data;
if (argc > 1 && !strcmp(argv[1], "-svc")) {
tdsec->tsec_service_gsec = true;
argv++;
argc--;
}
#ifdef SERVICE_THREAD
else if (argc > 1 && !strcmp(argv[1], "-svc_thd")) {
tdsec->tsec_service_gsec = true;
tdsec->tsec_service_thd = true;
tdsec->tsec_service_blk = output_data;
tdsec->tsec_status = tdsec->tsec_service_blk->svc_status;
argv++;
argc--;
}
#endif
else if (argc > 4 && !strcmp(argv[1], "-svc_re")) {
tdsec->tsec_service_gsec = true;
long redir_in = atol(argv[2]);
long redir_out = atol(argv[3]);
long redir_err = atol(argv[4]);
#ifdef WIN_NT
redir_in = _open_osfhandle(redir_in, 0);
redir_out = _open_osfhandle(redir_out, 0);
redir_err = _open_osfhandle(redir_err, 0);
#endif
if (redir_in != 0)
if (dup2((int) redir_in, 0))
close((int) redir_in);
if (redir_out != 1)
if (dup2((int) redir_out, 1))
close((int) redir_out);
if (redir_err != 2)
if (dup2((int) redir_err, 2))
close((int) redir_err);
argv += 4;
argc -= 4;
}
ISC_STATUS* status = tdsec->tsec_status;
SSHORT ret = parse_cmd_line(argc, argv, tdsec);
Firebird::PathName databaseName;
bool databaseNameEntered = user_data->database_name_entered;
if (user_data->database_name_entered)
{
databaseName = user_data->database_name;
}
else
{
TEXT database_name[MAXPATHLEN];
SecurityDatabase::getPath(database_name);
databaseName = database_name;
}
Firebird::PathName serverName;
bool useServices = false;
switch (ISC_extract_host(databaseName, serverName, true))
{
case ISC_PROTOCOL_TCPIP:
serverName += ":";
useServices = true;
break;
case ISC_PROTOCOL_WLAN:
serverName = "\\\\" + serverName + "\\";
useServices = true;
break;
}
if (! useServices)
{
serverName = "";
}
databaseName.copyTo(user_data->database_name, sizeof(user_data->database_name));
#ifdef SUPERCLIENT
useServices = true;
#else //SUPERCLIENT
FB_API_HANDLE db_handle = 0;
if (! useServices)
{
Firebird::ClumpletWriter dpb(Firebird::ClumpletReader::Tagged, MAX_DPB_SIZE, isc_dpb_version1);
dpb.insertByte(isc_dpb_gsec_attach, 1); // not 0 - yes, I'm gsec
#ifdef TRUSTED_SERVICES
if (user_data->dba_trust_user_name_entered)
{
dpb.insertString(isc_dpb_trusted_auth,
user_data->dba_trust_user_name, strlen(user_data->dba_trust_user_name));
}
else
#endif
{
if (user_data->dba_user_name_entered)
{
dpb.insertString(isc_dpb_user_name,
user_data->dba_user_name, strlen(user_data->dba_user_name));
}
if (user_data->dba_password_entered)
{
dpb.insertString(tdsec->tsec_service_gsec ?
isc_dpb_password_enc : isc_dpb_password,
user_data->dba_password, strlen(user_data->dba_password));
}
}
if (user_data->sql_role_name_entered) {
dpb.insertString(isc_dpb_sql_role_name,
user_data->sql_role_name, strlen(user_data->sql_role_name));
}
if (isc_attach_database(status, 0, databaseName.c_str(), &db_handle,
dpb.getBufferLength(),
reinterpret_cast<const char*>(dpb.getBuffer())))
{
GSEC_error_redirect(status, GsecMsg15, NULL, NULL);
}
}
#endif //SUPERCLIENT
isc_svc_handle sHandle = 0;
if (useServices)
{
#ifndef SERVICE_THREAD
envPick(user_data->dba_user_name, sizeof user_data->dba_user_name, "ISC_USER");
envPick(user_data->dba_password, sizeof user_data->dba_password, "ISC_PASSWORD");
#endif //SERVICE_THREAD
sHandle = attachRemoteServiceManager(
status,
user_data->dba_user_name,
user_data->dba_password,
serverName.c_str());
if (! sHandle)
{
GSEC_error_redirect(status, GsecMsg15, NULL, NULL);
}
}
if (!tdsec->tsec_interactive) {
if (ret == 0) {
#ifdef SERVICE_THREAD
/* Signal the start of the service here ONLY if we are displaying users
* since the number of users may exceed the service buffer. This
* will cause the service to wait for the client to request data. However,
* if the server is not signaled, then the client can never request anything */
if (user_data->operation == DIS_OPER)
tdsec->tsec_service_blk->svc_started();
#endif
#ifndef SUPERCLIENT
if (! useServices)
{
ret = SECURITY_exec_line(status, db_handle,
user_data, data_print, NULL);
if (ret) {
GSEC_print(ret, user_data->user_name, NULL, NULL, NULL, NULL);
if (status[1])
{
GSEC_print_status(status);
}
}
}
else
#endif //SUPERCLIENT
{
callRemoteServiceManager(status, sHandle, *user_data, data_print, NULL);
if (status[1])
{
GSEC_print_status(status);
ret = GsecMsg75;
}
}
}
}
else {
int local_argc;
SCHAR* local_argv[MAXARGS];
for (;;) {
/* Clear out user data each time through this loop. */
MOVE_CLEAR(tdsec->tsec_user_data, sizeof(internal_user_data));
if (get_line(&local_argc, local_argv, stuff, sizeof(stuff)))
break;
if (local_argc > 1) {
ret = parse_cmd_line(local_argc, local_argv, tdsec);
databaseName.copyTo(user_data->database_name, sizeof(user_data->database_name));
user_data->database_name_entered = databaseNameEntered;
if (ret == 1)
break;
if (ret == 0) {
#ifndef SUPERCLIENT
if (!useServices)
{
ret = SECURITY_exec_line(status, db_handle,
user_data, data_print, NULL);
}
else
#endif //SUPERCLIENT
{
callRemoteServiceManager(status, sHandle, *user_data, data_print, NULL);
if (status[1])
{
GSEC_print_status(status);
ret = GsecMsg75;
break;
}
}
if (ret) {
GSEC_print(ret, user_data->user_name, NULL, NULL,
NULL, NULL);
if (status[1]) {
GSEC_print_status(status);
}
break;
}
}
}
}
}
#ifndef SUPERCLIENT
if (db_handle) {
ISC_STATUS_ARRAY loc_status;
if (isc_detach_database(loc_status, &db_handle)) {
GSEC_error_redirect(loc_status, 0, NULL, NULL);
}
}
#endif //SUPERCLIENT
if (sHandle)
{
ISC_STATUS_ARRAY loc_status;
detachRemoteServiceManager(loc_status, sHandle);
if (loc_status[1]) {
GSEC_print_status(loc_status);
}
}
if (tdsec->tsec_interactive)
gsec_exit(FINI_OK, tdsec);
gsec_exit(ret, tdsec);
return ret; // silence compiler warning
} // try
catch (const Firebird::LongJump&) {
/* All calls to gsec_exit(), normal and error exits, wind up here */
tdsec->tsec_service_blk->svc_started();
tdsec->tsec_throw = false;
const int exit_code = tdsec->tsec_exit_code;
return exit_code;
}
catch (const Firebird::Exception& e) {
// Real exceptions are coming here
ISC_STATUS_ARRAY status;
Firebird::CircularStringsBuffer<4096> localStrings;
e.stuff_exception(status, &localStrings);
GSEC_print_status(status, false);
tdsec->tsec_service_blk->svc_started();
tdsec->tsec_throw = false;
return 127;
}
}
static void data_print(void* arg, const internal_user_data* data, bool first)
{
/**************************************
*
* d a t a _ p r i n t
*
**************************************
*
* Functional description
* print out user data row by row
* if first is TRUE print the header then the data
*
**************************************/
tsec* tdsec = tsec::getSpecific();
#ifdef SERVICE_THREAD
#define STUFF_USER(item) SVC_putc(tdsec->tsec_service_blk, item)
#else
#define STUFF_USER(item) fputc(item, stderr)
#endif
if (tdsec->tsec_service_gsec) {
int i, len;
/* Send the username */
len = strlen(data->user_name);
STUFF_USER((UCHAR) isc_spb_sec_username);
STUFF_USER((UCHAR) len);
STUFF_USER((UCHAR) (len >> 8));
for (i = 0; i < len; i++)
STUFF_USER((UCHAR) data->user_name[i]);
/* Send the first name */
len = strlen(data->first_name);
STUFF_USER((UCHAR) isc_spb_sec_firstname);
STUFF_USER((UCHAR) len);
STUFF_USER((UCHAR) (len >> 8));
for (i = 0; i < len; i++)
STUFF_USER((UCHAR) data->first_name[i]);
/* Send the middle name */
len = strlen(data->middle_name);
STUFF_USER((UCHAR) isc_spb_sec_middlename);
STUFF_USER((UCHAR) len);
STUFF_USER((UCHAR) (len >> 8));
for (i = 0; i < len; i++)
STUFF_USER((UCHAR) data->middle_name[i]);
/* Send the last name */
len = strlen(data->last_name);
STUFF_USER((UCHAR) isc_spb_sec_lastname);
STUFF_USER((UCHAR) len);
STUFF_USER((UCHAR) (len >> 8));
for (i = 0; i < len; i++)
STUFF_USER((UCHAR) data->last_name[i]);
/* Send the uid */
STUFF_USER((UCHAR) isc_spb_sec_userid);
STUFF_USER((UCHAR) data->uid);
STUFF_USER((UCHAR) (data->uid >> 8));
STUFF_USER((UCHAR) (data->uid >> 16));
STUFF_USER((UCHAR) (data->uid >> 24));
/* Send the gid */
STUFF_USER((UCHAR) isc_spb_sec_groupid);
STUFF_USER((UCHAR) data->gid);
STUFF_USER((UCHAR) (data->gid >> 8));
STUFF_USER((UCHAR) (data->gid >> 16));
STUFF_USER((UCHAR) (data->gid >> 24));
}
else {
if (first) {
GSEC_print(GsecMsg26, NULL, NULL, NULL, NULL, NULL);
GSEC_print(GsecMsg27, NULL, NULL, NULL, NULL, NULL);
/* msg26: " user name uid gid full name" */
/* msg27: "-------------------------------------------------------------------------------------------" */
}
util_output("%-31.31s %5d %5d %s %s %s\n", data->user_name,
data->uid, data->gid, data->first_name, data->middle_name,
data->last_name);
}
}
static bool get_line(int* argc, SCHAR** argv, TEXT* stuff, size_t maxstuff)
{
/**************************************
*
* g e t _ l i n e
*
**************************************
*
* Functional description
* Read the current line and put its pieces into an argc/argv
* structure. Reads a max of MAXARGS - 1 pieces (argv [0] is
* unused), and a max of MAXSTUFF characters, at which point
*
**************************************/
GSEC_print_partial(GsecMsg1, NULL, NULL, NULL, NULL, NULL);
*argc = 1;
TEXT* cursor = stuff;
int count = (int) maxstuff - 1;
bool first = true;
/* for each input character, if it's white space (or any non-printable,
non-newline for that matter), ignore it; if it's a newline, we're
done; otherwise, put it in the current argument */
while (*argc < MAXARGS && count > 0) {
TEXT c = getc(stdin);
if (c > ' ' && c <= '~') {
/* note that the first argument gets a '-' appended to the front to fool
the switch checker into thinking it came from the command line */
for (argv[(*argc)++] = cursor; count > 0; count--) {
if (first) {
first = false;
if (c != '?') {
*cursor++ = '-';
count--;
}
}
*cursor++ = c;
c = getc(stdin);
if (c <= ' ' || c > '~')
break;
}
*cursor++ = '\0';
count--;
}
if (c == '\n')
break;
if (c == EOF) {
if (SYSCALL_INTERRUPTED(errno)) {
errno = 0;
continue;
}
else
return true;
}
}
*cursor = '\0';
return false;
}
static bool get_switches(
int argc,
const TEXT* const* argv,
const in_sw_tab_t* in_sw_table,
tsec* tdsec, bool* quitflag)
{
/**************************************
*
* g e t _ s w i t c h e s
*
**************************************
*
* Functional description
* Parse the input line arguments, saving
* interesting switches in a switch table.
*
**************************************/
TEXT msg[MSG_LENGTH];
int l;
SSHORT err_msg_no;
/* look at each argument. it's either a switch or a parameter.
parameters must always follow a switch, but not all switches
need parameters. this is how, for example, parameters are
cleared (like a -fname switch followed by no first name
parameter). */
internal_user_data* user_data = tdsec->tsec_user_data;
*quitflag = false;
USHORT last_sw = IN_SW_GSEC_0;
tdsec->tsec_sw_version = false;
for (--argc; argc > 0; argc--) {
const TEXT* string = *++argv;
if (*string == '?')
user_data->operation = HELP_OPER;
else if (*string != '-') {
/* this is not a switch, so it must be a parameter for
the previous switch, if any */
switch (last_sw) {
case IN_SW_GSEC_ADD:
case IN_SW_GSEC_DEL:
case IN_SW_GSEC_DIS:
case IN_SW_GSEC_MOD:
for (l = 0; l < 32 && string[l] && string[l] != ' '; l++)
user_data->user_name[l] = UPPER(string[l]);
if (l == 32) {
#ifdef SERVICE_THREAD
GSEC_error(GsecMsg76, NULL, NULL, NULL, NULL, NULL);
#else
GSEC_print(GsecMsg76, NULL, NULL, NULL, NULL, NULL);
#endif
/* invalid user name (maximum 31 bytes allowed) */
return false;
}
user_data->user_name[l] = '\0';
user_data->user_name_entered = true;
break;
case IN_SW_GSEC_PASSWORD:
for (l = 0; l < 9 && string[l] && string[l] != ' '; l++)
user_data->password[l] = string[l];
if ((l == 9) && !(tdsec->tsec_service_gsec)) {
GSEC_print(GsecMsg77, NULL, NULL, NULL, NULL, NULL);
// warning password maximum 8 significant bytes used
}
user_data->password[l] = '\0';
user_data->password_entered = true;
break;
case IN_SW_GSEC_UID:
user_data->uid = atoi(string);
user_data->uid_entered = true;
break;
case IN_SW_GSEC_GID:
user_data->gid = atoi(string);
user_data->gid_entered = true;
break;
case IN_SW_GSEC_SYSU:
strncpy(user_data->sys_user_name, string, sizeof(user_data->sys_user_name));
user_data->sys_user_entered = true;
break;
case IN_SW_GSEC_GROUP:
strncpy(user_data->group_name, string, sizeof(user_data->group_name));
user_data->group_name_entered = true;
break;
case IN_SW_GSEC_FNAME:
strncpy(user_data->first_name, string, sizeof(user_data->first_name));
user_data->first_name_entered = true;
break;
case IN_SW_GSEC_MNAME:
strncpy(user_data->middle_name, string, sizeof(user_data->middle_name));
user_data->middle_name_entered = true;
break;
case IN_SW_GSEC_LNAME:
strncpy(user_data->last_name, string, sizeof(user_data->last_name));
user_data->last_name_entered = true;
break;
case IN_SW_GSEC_DATABASE:
strncpy(user_data->database_name, string, sizeof(user_data->database_name));
user_data->database_name_entered = true;
break;
case IN_SW_GSEC_DBA_USER_NAME:
strncpy(user_data->dba_user_name, string, sizeof(user_data->dba_user_name));
user_data->dba_user_name_entered = true;
break;
case IN_SW_GSEC_DBA_PASSWORD:
strncpy(user_data->dba_password, string, sizeof(user_data->dba_password));
user_data->dba_password_entered = true;
break;
case IN_SW_GSEC_SQL_ROLE_NAME:
strncpy(user_data->sql_role_name, string, sizeof(user_data->sql_role_name));
user_data->sql_role_name_entered = true;
break;
#ifdef TRUSTED_SERVICES
case IN_SW_GSEC_DBA_TRUST_USER:
strncpy(user_data->dba_trust_user_name, string, sizeof(user_data->dba_trust_user_name));
user_data->dba_trust_user_name_entered = true;
break;
#endif
case IN_SW_GSEC_Z:
case IN_SW_GSEC_0:
#ifdef SERVICE_THREAD
GSEC_error(GsecMsg29, NULL, NULL, NULL, NULL, NULL);
#else
GSEC_print(GsecMsg29, NULL, NULL, NULL, NULL, NULL);
#endif
/* gsec - invalid parameter, no switch defined */
return false;
}
last_sw = IN_SW_GSEC_0;
}
else {
/* iterate through the switch table, looking for matches */
USHORT in_sw = IN_SW_GSEC_0;
{ // scope
const TEXT* q;
for (const in_sw_tab_t* in_sw_tab = in_sw_table;
q = in_sw_tab->in_sw_name; in_sw_tab++)
{
const TEXT* p = string + 1;
/* handle orphaned hyphen case */
if (!*p--)
break;
/* compare switch to switch name in table */
l = 0;
while (*p) {
if (!*++p) {
if (l >= in_sw_tab->in_sw_min_length)
in_sw = in_sw_tab->in_sw;
else
in_sw = IN_SW_GSEC_AMBIG;
}
if (UPPER(*p) != *q++)
break;
l++;
}
/* end of input means we got a match. stop looking */
if (!*p)
break;
}
} // scope
/* this checks to make sure that the switch is not a duplicate. if
it is a duplicate, it's an error. if it's not a duplicate, the
appropriate specified flag is set (to later check for duplicates),
and the applicable parameter value is set to its null value, in
case the user really wants to remove an existing parameter. */
switch (in_sw) {
case IN_SW_GSEC_ADD:
case IN_SW_GSEC_DEL:
case IN_SW_GSEC_DIS:
case IN_SW_GSEC_MOD:
case IN_SW_GSEC_QUIT:
case IN_SW_GSEC_HELP:
if (user_data->operation) {
GSEC_error(GsecMsg30, NULL, NULL, NULL, NULL, NULL);
/* gsec - operation already specified */
return false;
}
switch (in_sw) {
case IN_SW_GSEC_ADD:
user_data->operation = ADD_OPER;
break;
case IN_SW_GSEC_DEL:
user_data->operation = DEL_OPER;
break;
case IN_SW_GSEC_DIS:
user_data->operation = DIS_OPER;
break;
case IN_SW_GSEC_MOD:
user_data->operation = MOD_OPER;
break;
case IN_SW_GSEC_QUIT:
user_data->operation = QUIT_OPER;
*quitflag = true;
break;
case IN_SW_GSEC_HELP:
user_data->operation = HELP_OPER;
break;
}
user_data->user_name[0] = '\0';
tdsec->tsec_interactive = false;
break;
case IN_SW_GSEC_PASSWORD:
case IN_SW_GSEC_UID:
case IN_SW_GSEC_GID:
case IN_SW_GSEC_SYSU:
case IN_SW_GSEC_GROUP:
case IN_SW_GSEC_FNAME:
case IN_SW_GSEC_MNAME:
case IN_SW_GSEC_LNAME:
case IN_SW_GSEC_DATABASE:
#ifdef TRUSTED_SERVICES
case IN_SW_GSEC_DBA_TRUST_USER:
#endif
case IN_SW_GSEC_DBA_USER_NAME:
case IN_SW_GSEC_DBA_PASSWORD:
case IN_SW_GSEC_SQL_ROLE_NAME:
err_msg_no = 0;
switch (in_sw) {
case IN_SW_GSEC_PASSWORD:
if (user_data->password_specified) {
err_msg_no = GsecMsg31;
break;
}
user_data->password_specified = true;
user_data->password[0] = '\0';
break;
case IN_SW_GSEC_UID:
if (user_data->uid_specified) {
err_msg_no = GsecMsg32;
break;
}
user_data->uid_specified = true;
user_data->uid = 0;
break;
case IN_SW_GSEC_GID:
if (user_data->gid_specified) {
err_msg_no = GsecMsg33;
break;
}
user_data->gid_specified = true;
user_data->gid = 0;
break;
case IN_SW_GSEC_SYSU:
if (user_data->sys_user_specified) {
err_msg_no = GsecMsg34;
break;
}
user_data->sys_user_specified = true;
user_data->sys_user_name[0] = '\0';
break;
case IN_SW_GSEC_GROUP:
if (user_data->group_name_specified) {
err_msg_no = GsecMsg35;
break;
}
user_data->group_name_specified = true;
user_data->group_name[0] = '\0';
break;
case IN_SW_GSEC_FNAME:
if (user_data->first_name_specified) {
err_msg_no = GsecMsg36;
break;
}
user_data->first_name_specified = true;
user_data->first_name[0] = '\0';
break;
case IN_SW_GSEC_MNAME:
if (user_data->middle_name_specified) {
err_msg_no = GsecMsg37;
break;
}
user_data->middle_name_specified = true;
user_data->middle_name[0] = '\0';
break;
case IN_SW_GSEC_LNAME:
if (user_data->last_name_specified) {
err_msg_no = GsecMsg38;
break;
}
user_data->last_name_specified = true;
user_data->last_name[0] = '\0';
break;
case IN_SW_GSEC_DATABASE:
if (user_data->database_name_specified) {
err_msg_no = GsecMsg78;
break;
}
user_data->database_name_specified = true;
user_data->database_name[0] = '\0';
break;
case IN_SW_GSEC_DBA_USER_NAME:
if (user_data->dba_user_name_specified) {
err_msg_no = GsecMsg79;
break;
}
user_data->dba_user_name_specified = true;
user_data->dba_user_name[0] = '\0';
break;
#ifdef TRUSTED_SERVICES
case IN_SW_GSEC_DBA_TRUST_USER:
if (user_data->dba_trust_user_name_specified) {
err_msg_no = GsecMsg79;
break;
}
user_data->dba_trust_user_name_specified = true;
user_data->dba_trust_user_name[0] = '\0';
break;
#endif
case IN_SW_GSEC_DBA_PASSWORD:
if (user_data->dba_password_specified) {
err_msg_no = GsecMsg80;
break;
}
user_data->dba_password_specified = true;
user_data->dba_password[0] = '\0';
break;
case IN_SW_GSEC_SQL_ROLE_NAME:
if (user_data->sql_role_name_specified) {
err_msg_no = GsecMsg81;
break;
}
user_data->sql_role_name_specified = true;
user_data->sql_role_name[0] = '\0';
break;
}
if (err_msg_no) {
GSEC_error(err_msg_no, NULL, NULL, NULL, NULL, NULL);
return false;
}
break;
case IN_SW_GSEC_Z:
if (!tdsec->tsec_sw_version) {
msg_get(GsecMsg39, msg);
util_output("%s %s\n", msg, GDS_VERSION);
}
tdsec->tsec_sw_version = true;
break;
case IN_SW_GSEC_0:
#ifdef SERVICE_THREAD
GSEC_error(GsecMsg40, NULL, NULL, NULL, NULL, NULL);
#else
GSEC_print(GsecMsg40, NULL, NULL, NULL, NULL, NULL);
#endif
/* gsec - invalid switch specified */
return false;
case IN_SW_GSEC_AMBIG:
#ifdef SERVICE_THREAD
GSEC_error(GsecMsg41, NULL, NULL, NULL, NULL, NULL);
#else
GSEC_print(GsecMsg41, NULL, NULL, NULL, NULL, NULL);
#endif
/* gsec - ambiguous switch specified */
return false;
}
last_sw = in_sw;
}
/* make sure that the current suite of switches and parameters
is valid, and if not, indicate why not */
if (user_data->uid_entered || user_data->gid_entered ||
user_data->sys_user_entered || user_data->group_name_entered ||
user_data->password_entered || user_data->first_name_entered ||
user_data->middle_name_entered || user_data->last_name_entered)
{
switch (user_data->operation) {
case 0:
GSEC_error(GsecMsg42, NULL, NULL, NULL, NULL, NULL);
/* gsec - no operation specified for parameters */
return false;
case ADD_OPER:
case MOD_OPER:
/* any parameter is ok for these operation states */
break;
case DEL_OPER:
case DIS_OPER:
case QUIT_OPER:
case HELP_OPER: