Bug 479635 - CUPS gets MIME type of application/x-shell wrong
Summary: CUPS gets MIME type of application/x-shell wrong
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: cups
Version: 5.3
Hardware: All
OS: Linux
low
medium
Target Milestone: rc
: ---
Assignee: Tim Waugh
QA Contact: desktop-bugs@redhat.com
URL:
Whiteboard:
: 479471 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-01-12 09:48 UTC by Opher Shachar
Modified: 2018-08-20 10:56 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of: 426089
Environment:
Last Closed: 2009-09-02 11:25:51 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
CUPS Bugs and Features 3055 0 None None None Never
CUPS Bugs and Features 3059 0 None None None Never
Red Hat Product Errata RHBA-2009:1360 0 normal SHIPPED_LIVE cups bug fix update 2009-09-01 10:55:27 UTC

Description Opher Shachar 2009-01-12 09:48:48 UTC
Hello,
Please see exact details further down, but first two comments:
There is a workaround for STR #3059 by way of a configuration change in mime.types.
    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))
or 
    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)))
and similarly for 
    application/x-cshell
    application/x-perl

The workaround for STR #3055 is adding "-odocument-name=<the doc name>"


+++ This bug was initially created as a clone of Bug #426089 +++

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.3.7-6

How reproducible:
Always.

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

Expected results:
1. The scheduler should auto-type as "application/x-shell".

Additional info:
1. Typing:
   lp -d printer -o prettyprint -o document-format=application/x-shell 
foo.bash
has CUPS mark the correct MIME type on the file. In error_log:
   envp[20]="CONTENT_TYPE=application/x-shell"

--- Additional comment from twaugh on 2007-12-18 08:51:08 EDT ---

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?

--- Additional comment from ophers.il on 2007-12-18 10:19:29 EDT ---

Hi,
The file is in the attached zip archive. It has 

#!/bin/ksh

as the first line.
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 `foo.sh' and `foo.ksh'
(exact same content) are typed 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.


--- Additional comment from ophers.il on 2007-12-18 10:51:03 EDT ---

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.

--- Additional comment from twaugh on 2008-01-08 13:11:06 EDT ---

I think this might be to do with a bug I just filed upstream:
  http://cups.org/str.php?L2659

--- Additional comment from twaugh on 2008-02-26 11:39:06 EDT ---

Believed fixed in 1.3.6-2.fc8.

--- Additional comment from ophers.il on 2009-01-06 08:52:29 EDT ---

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.
Filed STR #3055 upstream.

--- Additional comment from ophers.il on 2009-01-12 03:44:26 EDT ---

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 1 Tim Waugh 2009-01-28 18:07:49 UTC
*** Bug 479471 has been marked as a duplicate of this bug. ***

Comment 8 errata-xmlrpc 2009-09-02 11:25:51 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2009-1360.html


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