Bug 426089 - CUPS gets MIME type of application/x-shell wrong
Summary: CUPS gets MIME type of application/x-shell wrong
Keywords:
Status: CLOSED NEXTRELEASE
Alias: None
Product: Fedora
Classification: Fedora
Component: cups
Version: 9
Hardware: All
OS: Linux
low
low
Target Milestone: ---
Assignee: Tim Waugh
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: F9Target
TreeView+ depends on / blocked
 
Reported: 2007-12-18 12:57 UTC by Opher Shachar
Modified: 2009-03-02 17:03 UTC (History)
0 users

Fixed In Version: 1.3.9-4.fc9
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 479635 (view as bug list)
Environment:
Last Closed: 2009-03-02 16:59:48 UTC


Attachments (Terms of Use)
conf files (20.48 KB, application/x-zip-compressed)
2007-12-18 12:59 UTC, Opher Shachar
no flags Details


Links
System ID Priority Status Summary Last Updated
CUPS Bugs and Features 2659 None None None Never
CUPS Bugs and Features 3055 None None None Never
CUPS Bugs and Features 3059 None None None Never

Description Opher Shachar 2007-12-18 12:57:46 UTC
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 12:59:55 UTC
Created attachment 289889 [details]
conf files

Comment 2 Tim Waugh 2007-12-18 13:51:08 UTC
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 15:19:29 UTC
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 15:51:03 UTC
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 18:11:06 UTC
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 16:39:06 UTC
Believed fixed in 1.3.6-2.fc8.

Comment 8 Opher Shachar 2009-01-06 13:52:29 UTC
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 16:05:06 UTC
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 08:44:26 UTC
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 09:15:57 UTC
Changing version to 9.

Comment 12 Fedora Update System 2009-01-29 23:01:19 UTC
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 23:02:22 UTC
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 16:59:42 UTC
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 17:03:12 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.