Solved

dbm problem

Posted on 1998-08-17
45
304 Views
Last Modified: 2012-05-04
Morning all, I'm totally new to all this Perl malarkey, so I'm praying you
> guys can help me.
>
> I'm trying to run a bulletin board application written by someone else, however whenever it gets
> to
> a DBM statement it stops, no error messages, nothing. I've been told that
> "The problem seems to be that your perl interpreter cannot handle any DBM
> activity from within a CGI script." and that it's some sort of
> configuration issue.
>
> I'm running activestate Perl for win32 on NT4 IIS4
>
0
Comment
Question by:ntollfree
  • 27
  • 17
45 Comments
 
LVL 5

Expert Comment

by:b2pi
ID: 1203559
Let me guess.  The bulletin board application wasn't written for ActiveState Perl, but rather for generic perl.

I have a vague suspicion/rememberance that dbm is one of the things that ActiveState perl doesn't support...
0
 

Author Comment

by:ntollfree
ID: 1203560
I just checked the faq, and it does support DBM. However I think that it was generic perl that this was written for
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203561
Up at the top of the script, it should have a bunch of lines that say something like

use ...


One of those lines has a 'db' in it.  What is it?
0
 

Author Comment

by:ntollfree
ID: 1203562
I just checked the faq, and it does support DBM. However I think that it was generic perl that this was written for
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203563
Misstype... that should be a DBM_File...

0
 

Author Comment

by:ntollfree
ID: 1203564
I just checked the faq, and it does support DBM. However I think that it was generic perl that this was written for
0
 

Author Comment

by:ntollfree
ID: 1203565
Okay, these are the only lines that I've found that may be of help
$areas_db="$(db_dir)/areas";
$dates_db="$(db_dir)/dates";
$sched_db="$(db_dir)/schedule";

I can't find any use.... or any dbm_file

Neil
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203566

Are there any lines like

require ...

Wait a minute, you're running activestate, so you can't be running perl4.  Therefore, if your script is actually using any dbm stuff, there absolutely must be a command to include the module.  

Ummm, that ellipsis (...) was meant to mean "anything goes here". For instance, you might have:

use NDBM_File;


0
 

Author Comment

by:ntollfree
ID: 1203567
Okay, running activestate Perl v5.007. There are definately no use... lines anywhere. But the guy who developed it says they are not required and that it runs fine on his NT4 box...

0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203568
> I'm trying to run a bulletin board application written by someone else, however whenever it gets
    > to
    > a DBM statement it stops, no error messages, nothing. I've been told that
    > "The problem seems to be that your perl interpreter cannot handle any DBM


What are the DBM statements?  How big is the script?
0
 

Author Comment

by:ntollfree
ID: 1203569
Okay, running activestate Perl v5.007. There are definately no use... lines anywhere. But the guy who developed it says they are not required and that it runs fine on his NT4 box...

0
 

Author Comment

by:ntollfree
ID: 1203570
Okay, my man tells me that if we can get this bit of script running then we should be able to get the bbs software working.

and it can be viewed at http://www.essexcc.gov.uk/scripts/discuss/test.pl

neil

print "Content-type: text/html \n\n";

print "MIH1 <br>\n";

dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444);

print "MIH2 <br>\n";

$DB{'1'} = "Testing";

print "MIH3 <br>\n";

dbmclose(%DB);

print "MIH4 <br>\n";

exit(0);
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203571
try

dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";


Also, check your permissions on both the directory (\inetpub\scritps\discuss) and the file.
0
 

Author Comment

by:ntollfree
ID: 1203572
permissions are set to Everyone-full control, and have modified the line to no avail
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203573
There's no output at all?

By the way, change your access mode to 0666 (you're trying to write to a database which is read only)

Also, just for further debugging, try :


open(STDERR, ">&STDOUT");
my($dbf) = "\inetpub\scripts\discuss\testdb";
if (-f $dbf) {
   print "File exists<BR>\n";
   print "File size is " . -s $dbf;
   print "<BR>\n";
}
dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";
dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";
0
 

Author Comment

by:ntollfree
ID: 1203574
no output at all I'm afraid, and with this amendment, still no output. Remember, I'm a novice at this, could there be something regarding the Perl configuration that I need to do ?
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203575
I get it at least printing out the MIH1  
I assume you're getting that?
0
 

Author Comment

by:ntollfree
ID: 1203576
no output at all I'm afraid, and with this amendment, still no output. Remember, I'm a novice at this, could there be something regarding the Perl configuration that I need to do ?
0
 

Author Comment

by:ntollfree
ID: 1203577
sorry, yeah, that's what I mean, nada after the dbm statement
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203578
But those debug lines I gave you should have gone in BEFORE the dbm statement....

0
 

Author Comment

by:ntollfree
ID: 1203579
sorry, yeah, that's what I mean, nada after the dbm statement
0
 

Author Comment

by:ntollfree
ID: 1203580
To confirm, this is what I got in my script now, and I'm still getting nothing after MIH1. Sorry I'm slow on this, but I first saw Perl about 48 hours to me.

Cheers

Neil

print "Content-type: text/html \n\n";

print "MIH1 <br>\n";

open(STDERR, ">&STDOUT");
my($dbf) = "\inetpub\scripts\discuss\testdb";
if (-f $dbf) {
   print "File exists<BR>\n";
   print "File size is " . -s $dbf;
   print "<BR>\n";
}
dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";
dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";

print "MIH2 <br>\n";

$DB{'1'} = "Testing";

print "MIH3 <br>\n";

dbmclose(%DB);

print "MIH4 <br>\n";

exit(0);
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 5

Expert Comment

by:b2pi
ID: 1203581
OK, now we're getting there.

First, you only need one dbmopen (it was a typo on my part.

Second, replace

}
dbmopen...

with

} else {
   print "db file not found<BR>\n";
}
if (-w $dbf) {
   print "File is writeable";
} else {
   print "File is NOT writeable";
}
print "<BR>\n";
dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";


0
 

Author Comment

by:ntollfree
ID: 1203582
And the response is.....

MIH1
db file not found
File is NOT writeable

Neil


0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203583
OK, now (This should actually do it!) remove the old code (everything between
open(STDERR, ">&STDOUT");

to

dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";

and use this instead...

my($dbf) = "\inetpub\scripts\discuss\testdb";
open(FH, ">\inetpub\scripts\discuss\testdb") || die "No Write Access to directory";
print FH "asdfqwer" || die "No write access to file (Huh?)";
close(FH);
unlink("\inetpub\scripts\discuss\testdb")

print "<BR>\n";
dbmopen(%DB, "$dbf", 0664) || die "dbmopen failed: $!";
print "Opened successfully\n<BR>\n";
if (-f $dbf) {
       print "File exists<BR>\n";
       print "File size is " . -s $dbf;
       print "<BR>\n";
} else {
      print "db file not found<BR>\n";
}
if (-w $dbf) {
     print "File is writeable";
} else {
    print "File is NOT writeable";
}
print "<BR>\n";

0
 

Author Comment

by:ntollfree
ID: 1203584
And the response is.....

MIH1
db file not found
File is NOT writeable

Neil


0
 

Author Comment

by:ntollfree
ID: 1203585
Oh boy you're so going to hate this. I'm back to just getting MIH1 again.....

The code being used

print "Content-type: text/html \n\n";

print "MIH1 <br>\n";

open(STDERR, ">&STDOUT");
my($dbf) = "\inetpub\scripts\discuss\testdb";
open(FH, ">\inetpub\scripts\discuss\testdb") || die "No Write Access to directory";
print FH "asdfqwer" || die "No write access to file (Huh?)";
close(FH);
unlink("\inetpub\scripts\discuss\testdb")

print "<BR>\n";
dbmopen(%DB, "$dbf", 0664) || die "dbmopen failed: $!";
print "Opened successfully\n<BR>\n";
if (-f $dbf) {
       print "File exists<BR>\n";
       print "File size is " . -s $dbf;
       print "<BR>\n";
} else {
      print "db file not found<BR>\n";
}
if (-w $dbf) {
     print "File is writeable";
} else {
    print "File is NOT writeable";
}
print "<BR>\n";
dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";

print "MIH2 <br>\n";

$DB{'1'} = "Testing";

print "MIH3 <br>\n";

dbmclose(%DB);

print "MIH4 <br>\n";

exit(0);


0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203586
Have you tried running this from the command line rather than the browser?
0
 

Author Comment

by:ntollfree
ID: 1203587
Oh boy you're so going to hate this. I'm back to just getting MIH1 again.....

The code being used

print "Content-type: text/html \n\n";

print "MIH1 <br>\n";

open(STDERR, ">&STDOUT");
my($dbf) = "\inetpub\scripts\discuss\testdb";
open(FH, ">\inetpub\scripts\discuss\testdb") || die "No Write Access to directory";
print FH "asdfqwer" || die "No write access to file (Huh?)";
close(FH);
unlink("\inetpub\scripts\discuss\testdb")

print "<BR>\n";
dbmopen(%DB, "$dbf", 0664) || die "dbmopen failed: $!";
print "Opened successfully\n<BR>\n";
if (-f $dbf) {
       print "File exists<BR>\n";
       print "File size is " . -s $dbf;
       print "<BR>\n";
} else {
      print "db file not found<BR>\n";
}
if (-w $dbf) {
     print "File is writeable";
} else {
    print "File is NOT writeable";
}
print "<BR>\n";
dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444) || die "dbmopen failed: $!";

print "MIH2 <br>\n";

$DB{'1'} = "Testing";

print "MIH3 <br>\n";

dbmclose(%DB);

print "MIH4 <br>\n";

exit(0);


0
 

Author Comment

by:ntollfree
ID: 1203588
okay, from the command prompt

No write access to directory C:\inetpub\scripts\discuss\testdb at line 8
0
 

Author Comment

by:ntollfree
ID: 1203589
okay, from the command prompt

No write access to directory C:\inetpub\scripts\discuss\testdb at line 8
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203590
OK, can you arrange for write access (at least temporarily) to that directory for you as a user?
0
 

Author Comment

by:ntollfree
ID: 1203591
okay, from the command prompt

No write access to directory C:\inetpub\scripts\discuss\testdb at line 8
0
 

Author Comment

by:ntollfree
ID: 1203592
tried that, still the same response
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203593
Add the full debug info (note the two "($!)"'s

open(FH, ">\inetpub\scripts\discuss\testdb") || die "No Write Access to directory ($!)";
print FH "asdfqwer" || die "No write access to file (Huh?) ($!)";
close(FH);
0
 

Author Comment

by:ntollfree
ID: 1203594
tried that, still the same response
0
 

Author Comment

by:ntollfree
ID: 1203595
result is...

No write access to directory <invalid arguement> C:\inetpub\scripts\discuss\testdb at line 8
0
 
LVL 84

Expert Comment

by:ozo
ID: 1203596
open(FH, ">\inetpub\scripts\discuss\testdb")
should be
open(FH, '>\inetpub\scripts\discuss\testdb')
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203597
I'm about to give up here, these comments don't make sense.. try this.

Bloody hell....

Everywhere it says \inetpub\scripts\discuss\testdb, make it $dbf

change the assignment to $dbf to

$dbf = "C:\\inetpub\\scripts\\discuss\\testdb";


0
 

Author Comment

by:ntollfree
ID: 1203598
From ozo's comment, I now get this error

MHI1<br>
<BR>

dbmopen failed : No such line or directory at C:\Inetpub\scripts\discuss\test.pl at line 14

and from b2pi
MIH1<br>
<BR>
Opened Successfully
<BR>
dbfile not found<BR>
MIH2<br>
MIH3<br>
MIH4<br>

Does this mean that we are there ?
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1203599
After the program has executed, what files are in c:\inetpub\scripts\discuss\ ?
Most specifically, I'm looking for testdb*.*

0
 

Author Comment

by:ntollfree
ID: 1203600
we got testdb.dir and .pag

Neil
0
 
LVL 5

Accepted Solution

by:
b2pi earned 200 total points
ID: 1203601
Assuming that 1.) they're not zero sized, and 2.) you can write to them, ... you're done!!!

Thus, the problem all along was

      dbmopen(%DB, "\inetpub\scripts\discuss\testdb", 0444);

1.) Opening a db with 444 (read-only for everyone) makes no sense. Noone will be able to write to it, which is fine, save that it will have no data in it.

2.) one must escape directory separators with Win32 (Arghhh!! Should have seen that right off.

0
 

Author Comment

by:ntollfree
ID: 1203602
we got testdb.dir and .pag

Neil
0
 

Author Comment

by:ntollfree
ID: 1203603
Okay, we're done. The chap who wrote this still has a few issues, but they're for another question.

Thank you very much for all your help, above and beyond the call of duty

Neil
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now