/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Copyright (c) 1988 AT&T
* All Rights Reserved
*
*/
/*
* Incompatible Archive Header
*
* The archive file member header used in SunOS 4.1 archive files and
* Solaris archive files are incompatible. The header file is:
* The member ar_name[] in Solaris comforms with Standard and the
* member name terminates with '/'. The SunOS's member does not terminate
* with '/' character. A bug 4046054 was filed:
* The ar command in Solaris 2.5.1 is incompatible with archives
* created on 4.x.
*
* To handle archive files created in SunOS 4.1 system on Solaris, the
* following changes were made:
*
* Before writing each member files into the output
* archive file, ar_name[] is checked. If it is NULL,
* it means that the original archive header for this
* member was incompatible with Solaris format.
*
* The original Solaris ar command ended up having
* NULL name for the header. The change here uses the
* ar_rawname, which is much closer to the original
* name.
*
* 2. cmd.c
* For the p command, the code used to use only ar_longname
* to seach the matching name. The member is set to NULL
* if the archive member header was incompatible.
* The ar_rawname is also used to find the matching member name.
*
* For commands to update the archive file, we do not
* use ar_rawname, and just use the ar_longname. The commands are
* r (replace), m (modify the position) and d (delete).
*/
#include "inc.h"
/*
* Forward Declarations
*/
static void ar_select(int *, unsigned long);
/*
* Commands
*/
void
{
FILE *f;
int deleted;
char *gfile;
new_listhead = NULL;
new_listend = NULL;
prev_entry = NULL;
deleted = 0;
else if (!abifile)
/*
* NOTE:
* Refer to "Incompatible Archive Header"
* blocked comment at the beginning of this file.
*/
if (f == NULL) {
}
/*
* Created
*/
} else {
(void) fclose(f);
continue;
}
/*
* Replaced
*/
/*
* Clear the previous contents.
*/
/*
* clear ar_elf
*/
}
/* clear 'ar_flag' */
/*
* Defer reading contents until needed, and
* then use an in-kernel file-to-file transfer
* to avoid excessive in-process memory use.
*/
if ((fileptr->ar_pathname =
exit(1);
}
(void) fclose(f);
deleted = 1;
/* remove from archive list */
if (prev_entry != NULL)
else
/* add to moved list */
if (new_listhead == NULL)
else
}
}
}
else
/*
* Unchaged
*/
if (deleted)
deleted = 0;
else
}
if (!abifile) {
exit(2);
}
/*
*/
if (new_listhead) {
if (!moved_files)
}
/* 2: insert at appropriate position... */
if (abifile) {
} else {
}
}
void
{
/*
* NOTE:
* Refer to "Incompatible Archive Header"
* blocked comment at the beginning of this file.
*/
/*
* Deleted
*/
} else {
}
} else {
/*
* Unchaged
*/
}
}
}
void
{
int f;
int rawname = 0;
long f_len = 0;
/*
* If -T is specified, get the maximum file name length.
*/
if (f_len == -1) {
exit(1);
}
}
rawname = 1;
/*
* NOTE:
* Refer to "Incompatible Archive Header"
* blocked comment at the beginning of this file.
*/
if (f >= 0) {
if (rawname) {
/*
* eXtracted
*/
exit(1);
}
} else {
/*
* eXtracted
*/
exit(1);
}
}
(void) close(f);
} else
exit(1);
}
rawname = 0;
} /* for */
}
void
{
/*
* NOTE:
* Refer to "Incompatible Archive Header"
* blocked comment at the beginning of this file.
*/
next->ar_longname);
}
}
}
}
void
{
/*
* position Modified
*/
if (tmphead)
else
if (backptr1) {
}
else
continue;
}
/*
* position Unchaged
*/
else
}
}
if (!tmphead)
return;
else {
if (!abifile) {
exit(2);
}
if (abifile) {
} else {
}
}
}
void
{
int **mp;
int *m[10];
m[0] = m1;
m[1] = m2;
m[2] = m3;
m[3] = m4;
m[4] = m5;
m[5] = m6;
m[6] = m7;
m[7] = m8;
m[8] = m9;
m[9] = 0;
/*
* NOTE:
* Refer to "Incompatible Archive Header"
* blocked comment at the beginning of this file.
*/
exit(1);
}
}
if ((next->ar_longname[0] == 0) &&
(next->ar_rawname[0] != 0))
else
}
} /* for */
}
void
{
exit(1);
}
;
}
/*
* Supplementary functions
*/
static char *
{
int i;
continue;
return (file);
}
}
return (NULL);
}
/*
* puts the file which was in the list in the linked list
*/
static void
{
int i;
FILE *f;
continue;
/*
* Appended
*/
if (f == NULL) {
} else {
/* if short name */
if ((fileptr->ar_longname =
NULL) {
exit(1);
}
if ((fileptr->ar_pathname =
exit(1);
}
/* clear 'ar_flag' */
/*
* Defer reading contents until needed, and then use
* an in-kernel file-to-file transfer to avoid
* excessive in-process memory use.
*/
(void) fclose(f);
}
}
}
/*
* insert the file 'file' into the temporary file
*/
static void
{
/*
* The format of an 'ar' file includes a 6 character
* decimal string to contain the uid.
*
* If the uid or gid is too big to fit, then set it to
* nobody (for want of a better value). Clear the
* or setgid nobody files unexpectedly coming into existence.
*/
}
}
}
static FILE *
{
FILE *f;
if (f == NULL)
return (f);
(void) fclose(f);
return (NULL);
}
return (f);
}
/*
* Used by xcmd()
*/
int
{
int f;
char *f_name;
if (rawname)
f_name = a->ar_rawname;
else
f_name = a->ar_longname;
/*
* If -T is specified, check the file length.
*/
int len;
exit(1);
}
}
}
/*
* Bug 4052067 - If a file to be extracted has the same
* filename as the archive, the archive gets overwritten
* which can lead to a corrupted archive or worse, a ufs
* deadlock because libelf has mmap'ed the archive! We
* can't rely on strcmp() to test for this case because
* the archive could be prefixed with a partial or full
* path (and we could be using the rawname from the archive)
* This means we have to do the same thing we did for mv,
* which is to explicitly check if the file we would extract
* to is identical to the archive. Because part of this
* test is essentially what the -C flag does, I've merged
* the code together.
*/
/*
* If -C is specified, this is an error anyway
*/
f_name);
return (-1);
}
/*
* Okay, -C wasn't specified. However, now we do
* the check to see if the archive would be overwritten
* by extracting this file. stat() both objects and
* test to see if their identical.
*/
return (-1);
}
}
}
/*
* Okay to create extraction file...
*/
if (f < 0) {
/*
* Created
*/
}
if (dup)
return (f);
}
static void
{
#ifdef XPG4
/*
* XPG4 does not have any message defined for
* 'c' operation.
* In fact, XPG only defines messages for
* d, r, a and x at the present. (03/05/'96)
*/
if (c == 'c' || c == 'u' || c == 'm')
return;
#endif
/*
* If 'u' is passed, convert it to 'c'.
* 'u' makes more sense since the operation did not
* do anything, Unchanged, but 'c' has been used so
* I do no want to break the compatibility at this moment.
* (03/05/'96).
*/
if (c == 'u')
c = 'c';
if (c != 'c')
}
static void
{
int n, *ap;
n = *ap++;
ap++;
}