home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5326 < prev    next >
Encoding:
Text File  |  1992-08-14  |  3.1 KB  |  92 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!rayssd!ras
  3. From: ras@rayssd.ssd.ray.com (Shaw)
  4. Subject: Bad label: _EVAL_, inconsistent behavior
  5. Message-ID: <1992Aug14.184402.25912@rayssd.ssd.ray.com>
  6. Summary: eval works nonsetuid, fails when setuid
  7. Keywords: eval, setuidness, etc.
  8. Sender: Ralph Shaw (ras@ssd.ray.com)
  9. Organization: Raytheon Submarine Signal Division, Portsmouth, RI
  10. Distribution: usa
  11. Date: Fri, 14 Aug 1992 18:44:02 GMT
  12. Lines: 78
  13.  
  14. Got a problem maybe somebody can help shed light on.  I've been
  15. working on a program that will run (with a wrapper) setuid to root,
  16. (as it's "chfn" - working on the password file), which behaves
  17. differently when running from a C wrapper, setuid, then when it isn't.
  18. (I'm running PERL 4.19, I know I should update, but haven't yet.)
  19.  
  20. I've done similar things before, (setuid wrapper running perl that
  21. eval's something), and have beaten my way thru the gauntlet of
  22. "taintperl", and it does not seem to object to anything I've done.
  23. basically, I've got an array of field names and constraint-patterns,
  24. and am passing them down to a subroutine that queries the user for
  25. the new value, or accepts the old one (if it's valid), etc.  See below:
  26.  
  27. $ chfn ras
  28. Warning: Employee Nbr. (UNIX Support) is not numeric (5-digit)
  29.  
  30. Cannot change Last Name: Shaw
  31. Change First Name: (Ralph A.) 
  32. Change Mail Stop: (130) 131
  33. Change Employee Nbr.: (UNIX Support) 00000
  34. Bad label: _EVAL_ at passutils.pl line 375, <STDIN> line 3.
  35.  
  36. $ pik 345 385 passutils.pl
  37. 345 sub chfn { # change what they gave you, or return it
  38. 346     local($N) = $_[0];    # index into @FN array
  39. 347     local($old) = $_[1];    # what it was set to
  40. 348 
  41. 349     die "$PROGNAME: chfn: invalid index $N\n"
  42. 350         if(($N % 4) > $#FN);
  43. 351 
  44. 352     local($prompt) = $FN[$N];    # what to ask them
  45. 353     local($test) = $FN[$N+1];    # what to check it against
  46. 354     local($warn) = $FN[$N+2];    # what to tell them for failures
  47. 355     local($allow) = $FN[$N+3];    # can this be changed by a user?
  48. 356     local($answer, $tries);
  49. 357 
  50. 358     
  51. 359 #
  52. 360 #     Some fields only the Superuser can change
  53. 361 #
  54. 362     if($RUID && $allow == 0) {
  55. 363         print "Cannot change $FN[$N]: $A[$C]\n";
  56. 364         return $old;
  57. 365     }
  58. 366 
  59. 367     $warn = "Alphabetic" if(length($warn) == 0);
  60. 368 
  61. 369     while($tries++ < 10) {
  62. 370         print "Change $prompt: ($old) ";
  63. 371         $answer = <STDIN>;
  64. 372         chop($answer);
  65. 373         $answer = $old if($answer eq '');
  66. 374 
  67. 375         if(length($test)) {
  68. 376             print "if($answer =~ $test)\n" if $DEBUG;
  69. 377             eval qq:return "$answer" if "$answer" =~ $test:;
  70. 378             print "$prompt must be $warn\n\n";
  71. 379         } else {
  72. 380             return($answer);
  73. 381         }
  74. 382     }
  75. 383     print STDERR "Too many tries, I give up!\n";
  76. 384     exit(1);
  77. 385 }
  78.  
  79. I've also tried:
  80.     eval "return \$answer if (\$answer =~ $test)";
  81. and
  82.     eval qq:return $answer if (\$answer =~ $test):;
  83. as well as a few other combnations.  The "Bad label:" message
  84. comes out on the next call to the subroutine after I've changed
  85. something, and refers to <STDIN> line N, where N is the number of
  86. times it's run the sub and gotten an answer.
  87.  
  88. Any clues?  I find no reference to _EVAL_ in the Book, and mysterious
  89. references to the "qq" mechanism didn't seem to help either.
  90. Thanks,
  91. Ralph Shaw        ras@ssd.ray.com
  92.