This service will be undergoing maintenance at 00:00 UTC, 2016-09-28. It is expected to last about 1 hours

Bug 426089

Summary: CUPS gets MIME type of application/x-shell wrong
Product: [Fedora] Fedora Reporter: Opher Shachar <ophers>
Component: cupsAssignee: Tim Waugh <twaugh>
Status: CLOSED NEXTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: 9Keywords: Reopened
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: 1.3.9-4.fc9 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
: 479635 (view as bug list) Environment:
Last Closed: 2009-03-02 11:59:48 EST Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Bug Depends On:    
Bug Blocks: 235705    
Attachments:
Description Flags
conf files none

Description Opher Shachar 2007-12-18 07:57:46 EST
Description of problem:
By my understanding the default installed mime.convs and mime.types should 
correctly get the type of *.sh files to be application/x-shell.
This doesn't happen.

Version-Release number of selected component (if applicable):
cups-1.2.12-6

How reproducible:
Very.

Steps to Reproduce:
1. lp -d FC6_HPTasht -o prettyprint cups_selective_rm.sh
2. error_log (debug level) has:    envp[20]="CONTENT_TYPE=text/plain"
  
Actual results:


Expected results:


Additional info:
1. Typing:
   lp -d FC6_HPTasht -o prettyprint -o document-format=application/x-shell 
cups_selective_rm.sh
has CUPS mark the correct MIME type on the file. In error_log:
   envp[20]="CONTENT_TYPE=application/x-shell"
Comment 1 Opher Shachar 2007-12-18 07:59:55 EST
Created attachment 289889 [details]
conf files
Comment 2 Tim Waugh 2007-12-18 08:51:08 EST
The mime.types entry is this:

application/x-shell             sh printable(0,1024) + string(0,#!) +\
                                (contains(2,80,/bash) contains(2,80,/ksh)\
                                 contains(2,80,/sh) contains(2,80,/zsh))

which checks that the first 1k of the file contains printable characters, that
the first two characters are '#!' (the "shebang"), and that the first line
contains of those recognised shell names.

What does the first line of the shell script you are trying to print look like?
Comment 3 Opher Shachar 2007-12-18 10:19:29 EST
Hi,
The file is in the attached zip archive. It has 

#!/bin/ksh

as the first line.
Also, as I understand, in mime.types whitespace is 'OR'; Namely, the file should
be typed `application/x-shell' just because it end with `.sh' .
I tried renaming to `cups_selective_rm.ksh' - no change.
Then I split the application/x-shell entry in two:

application/x-shell             sh
application/x-shell             printable(0,1024) + string(0,#!) +\
                                (contains(2,80,/bash) contains(2,80,/ksh)\
                                 contains(2,80,/sh) contains(2,80,/zsh))

restarted cups and now both `cups_selective_rm.sh' and `cups_selective_rm.ksh'
(exact same content) are type correctly :).

The head of mime.types documents that:

    Multiple occurrences of a type will cause the provided rules to be appended
to the existing definition.

so the two forms should be equivalent. It seems not to be the case.
Comment 4 Opher Shachar 2007-12-18 10:51:03 EST
Hey, further testing showed this to work too!!

application/x-shell             sh sh printable(0,1024) + string(0,#!) +\
                                (contains(2,80,/bash) contains(2,80,/ksh)\
                                 contains(2,80,/sh) contains(2,80,/zsh))

notice `sh' is doubled.
(I noticed that .html files were being typed correctly - the difference being 
that `text/html' lists two extensions.)
Comment 6 Tim Waugh 2008-01-08 13:11:06 EST
I think this might be to do with a bug I just filed upstream:
  http://cups.org/str.php?L2659
Comment 7 Tim Waugh 2008-02-26 11:39:06 EST
Believed fixed in 1.3.6-2.fc8.
Comment 8 Opher Shachar 2009-01-06 08:52:29 EST
I don't believe this is so.
Please look at scheduler/ipp.c line 7637:
    doc_name = ippFindAttribute(con->request, "document-name", IPP_TAG_NAME);
    filetype = mimeFileType(MimeDatabase, con->filename,
                            doc_name ? doc_name->values[0].string.text : NULL,
			    &compression);

The scheduler is looking for an attribute "document-name", BUT the client ONLY sends this attribute when printing more than one file per job:
in cups/util.c this attribute is sent in cupsPrintFiles2, BUT
cupsDoFileRequest in cups/request.c does not.
Comment 9 Tim Waugh 2009-01-06 11:05:06 EST
Thanks for investigating this further.

This will be fixed in CUPS 1.4 (in Fedora 11).  The fix was introduced as a side effect of fixing STR #2261 in commit 7170:
  http://cups.org/str.php?L2261
Comment 10 Opher Shachar 2009-01-12 03:44:26 EST
I'm afraid the fat lady has not sung yet :)

Further code review revealed a bug(?) in function mimeAddTypeRule() in scheduler/type.c that is the *real* culprit. Please see STR #3059 (that I've filed upstream) for details.
The code for v1.4 is the same so this is not resolved for Fedora 11 either at this point.

Regards,
Opher Shachar.
Comment 11 Tim Waugh 2009-01-12 04:15:57 EST
Changing version to 9.
Comment 12 Fedora Update System 2009-01-29 18:01:19 EST
cups-1.3.9-4.fc9 has been pushed to the Fedora 9 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing-newkey update cups'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F9/FEDORA-2009-1082
Comment 13 Fedora Update System 2009-01-29 18:02:22 EST
cups-1.3.9-8.fc10 has been pushed to the Fedora 10 testing repository.  If problems still persist, please make note of it in this bug report.
 If you want to test the update, you can install it with 
 su -c 'yum --enablerepo=updates-testing update cups'.  You can provide feedback for this update here: http://admin.fedoraproject.org/updates/F10/FEDORA-2009-1091
Comment 14 Fedora Update System 2009-03-02 11:59:42 EST
cups-1.3.9-8.fc10 has been pushed to the Fedora 10 stable repository.  If problems still persist, please make note of it in this bug report.
Comment 15 Fedora Update System 2009-03-02 12:03:12 EST
cups-1.3.9-4.fc9 has been pushed to the Fedora 9 stable repository.  If problems still persist, please make note of it in this bug report.