-/* @(#) $Id$ */
+/* @(#) $Id: ./src/rootcheck/os_string.c, 2011/09/08 dcid Exp $
+ */
/* Included and modified strings.c from the OpenBSD project.
* Copyright bellow.
*/
-
+
/*
* Copyright (c) 1980, 1987, 1993
* The Regents of the University of California. All rights reserved.
#ifdef AIX
-typedef struct aouthdr EXEC;
+typedef struct aouthdr EXEC;
#else
-typedef struct exec EXEC;
+typedef struct exec EXEC;
#endif
typedef struct _os_strings
int os_string(char *file, char *regex)
{
int ch, cnt;
-
+
unsigned char *C;
unsigned char *bfr;
-
+
char line[OS_SIZE_1024 +1];
char *buf;
-
+
EXEC *head;
os_strings oss;
-
+
/* Return didn't match */
if(!file || !regex)
{
return(0);
}
-
-
- /* Allocating for the buffer */
+
+
+ /* Allocating for the buffer */
bfr = calloc(STR_MINLEN + 2, sizeof(char *));
if (!bfr)
{
/* cleaning the line */
memset(line, '\0', OS_SIZE_1024 +1);
-
+
/* starting .. (from old strings.c) */
oss.foff = 0;
oss.head_len = 0;
-
+
oss.read_len = -1;
head = (EXEC *)oss.hbfr;
-
+
if ((oss.head_len = read(fileno(oss.fp), head, sizeof(EXEC))) == -1)
{
oss.head_len = 0;
oss.read_len = -1;
}
- else if (oss.head_len == sizeof(EXEC) && !N_BADMAG(*head))
+ else if (oss.head_len == sizeof(EXEC) && !N_BADMAG(*head))
{
oss.foff = N_TXTOFF(*head);
if (fseek(stdin, oss.foff, SEEK_SET) == -1)
}
/* Read the file and perform the regex comparison */
- for (cnt = 0; (ch = os_getch(&oss)) != EOF;)
+ for (cnt = 0; (ch = os_getch(&oss)) != EOF;)
{
- if (ISSTR(ch))
+ if (ISSTR(ch))
{
if (!cnt)
C = bfr;
*C++ = ch;
if (++cnt < STR_MINLEN)
continue;
-
+
strncpy(line, (char *)bfr, STR_MINLEN +1);
buf = line;
buf+=strlen(line);
-
+
while ((ch = os_getch(&oss)) != EOF && ISSTR(ch))
{
int os_getch(os_strings *oss)
{
++oss->foff;
- if (oss->head_len)
+ if (oss->head_len)
{
if (oss->hcnt < oss->head_len)
return((int)oss->hbfr[oss->hcnt++]);