ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/tools.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/tools.c (file contents):
Revision 1.17 by pajs, Mon Jan 5 14:21:07 2004 UTC vs.
Revision 1.23 by tdb, Fri Jan 16 15:54:54 2004 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * i-scream central monitoring system
3   * http://www.i-scream.org
4 < * Copyright (C) 2000-2003 i-scream
4 > * Copyright (C) 2000-2004 i-scream
5   *
6 < * This program is free software; you can redistribute it and/or
7 < * modify it under the terms of the GNU General Public License
8 < * as published by the Free Software Foundation; either version 2
9 < * of the License, or (at your option) any later version.
6 > * This library is free software; you can redistribute it and/or
7 > * modify it under the terms of the GNU Lesser General Public
8 > * License as published by the Free Software Foundation; either
9 > * version 2.1 of the License, or (at your option) any later version.
10   *
11 < * This program is distributed in the hope that it will be useful,
11 > * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 < * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 < * GNU General Public License for more details.
13 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 > * Lesser General Public License for more details.
15   *
16 < * You should have received a copy of the GNU General Public License
17 < * along with this program; if not, write to the Free Software
18 < * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 > * You should have received a copy of the GNU Lesser General Public
17 > * License along with this library; if not, write to the Free Software
18 > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 > * 02111-1307 USA
20   */
21  
22   #ifdef HAVE_CONFIG_H
# Line 25 | Line 26
26   #include <stdio.h>
27   #include <string.h>
28   #include <stdlib.h>
29 + #include <unistd.h>
30   #include <sys/types.h>
31   #include <regex.h>
32   #ifdef ALLBSD
# Line 186 | Line 188 | int get_alias(char *alias){
188          return 0;
189   }
190  
191 +
192 + #define BIG_ENOUGH 512
193   int build_mapping(){
194 <        char device_name[512];
194 >        char device_name[BIG_ENOUGH];
195          int x;
196          kstat_ctl_t *kc;
197          kstat_t *ksp;
198          kstat_io_t kios;
199  
200 +        char driver_list[BIG_ENOUGH][BIG_ENOUGH];
201 +        int list_entries = 0;
202 +        int found;
203 +
204          if ((kc = kstat_open()) == NULL) {
205                  return;
206          }
# Line 209 | Line 217 | int build_mapping(){
217                          }
218                          if(x == sizeof device_name) x--;
219                          device_name[x] = '\0';
220 <                        if((get_alias(device_name)) != 0){
221 <                                return 1;
220 >
221 >                        /* Check if we've not already looked it up */
222 >                        found = 0;
223 >                        for(x=0;x<list_entries;x++){
224 >                                if (x>=BIG_ENOUGH){
225 >                                        /* We've got bigger than we thought was massive */
226 >                                        /* If we hit this.. Make big enough bigger */
227 >                                        return 1;
228 >                                }
229 >                                if( !strncmp(driver_list[x], device_name, BIG_ENOUGH)){
230 >                                        found = 1;
231 >                                        break;
232 >                                }
233                          }
234 +
235 +                        if(!found){
236 +                                if((get_alias(device_name)) != 0){
237 +                                        return 1;
238 +                                }
239 +                                strncpy(driver_list[x], device_name, BIG_ENOUGH);
240 +                                list_entries++;
241 +                        }
242                  }
243          }
244  
# Line 267 | Line 294 | static long long atoll(const char *s) {
294   }
295   #endif
296  
297 + #ifndef HAVE_STRLCPY
298 + /*      $OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $     */
299 +
300 + /*
301 + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
302 + *
303 + * Permission to use, copy, modify, and distribute this software for any
304 + * purpose with or without fee is hereby granted, provided that the above
305 + * copyright notice and this permission notice appear in all copies.
306 + *
307 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
308 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
309 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
310 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
311 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
312 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
313 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
314 + */
315 +
316 + /*
317 + * Copy src to string dst of size siz.  At most siz-1 characters
318 + * will be copied.  Always NUL terminates (unless siz == 0).
319 + * Returns strlen(src); if retval >= siz, truncation occurred.
320 + */
321 + size_t strlcpy(char *dst, const char *src, size_t siz){
322 +        register char *d = dst;
323 +        register const char *s = src;
324 +        register size_t n = siz;
325 +
326 +        /* Copy as many bytes as will fit */
327 +        if (n != 0 && --n != 0) {
328 +                do {
329 +                        if ((*d++ = *s++) == 0)
330 +                                break;
331 +                } while (--n != 0);
332 +        }
333 +
334 +        /* Not enough room in dst, add NUL and traverse rest of src */
335 +        if (n == 0) {
336 +                if (siz != 0)
337 +                        *d = '\0';              /* NUL-terminate dst */
338 +                while (*s++)
339 +                        ;
340 +        }
341 +
342 +        return(s - src - 1);    /* count does not include NUL */
343 + }
344 + #endif
345 +
346 + #ifndef HAVE_STRLCAT
347 + /*      $OpenBSD: strlcat.c,v 1.11 2003/06/17 21:56:24 millert Exp $    */
348 +
349 + /*
350 + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
351 + *
352 + * Permission to use, copy, modify, and distribute this software for any
353 + * purpose with or without fee is hereby granted, provided that the above
354 + * copyright notice and this permission notice appear in all copies.
355 + *
356 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
357 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
358 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
359 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
360 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
361 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
362 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
363 + */
364 +
365 + /*
366 + * Appends src to string dst of size siz (unlike strncat, siz is the
367 + * full size of dst, not space left).  At most siz-1 characters
368 + * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
369 + * Returns strlen(src) + MIN(siz, strlen(initial dst)).
370 + * If retval >= siz, truncation occurred.
371 + */
372 + size_t strlcat(char *dst, const char *src, size_t siz){
373 +        register char *d = dst;
374 +        register const char *s = src;
375 +        register size_t n = siz;
376 +        size_t dlen;
377 +
378 +        /* Find the end of dst and adjust bytes left but don't go past end */
379 +        while (n-- != 0 && *d != '\0')
380 +                d++;
381 +        dlen = d - dst;
382 +        n = siz - dlen;
383 +
384 +        if (n == 0)
385 +                return(dlen + strlen(s));
386 +        while (*s != '\0') {
387 +                if (n != 1) {
388 +                        *d++ = *s;
389 +                        n--;
390 +                }
391 +                s++;
392 +        }
393 +        *d = '\0';
394 +
395 +        return(dlen + (s - src));       /* count does not include NUL */
396 + }
397 +
398 + #endif
399 +
400   long long get_ll_match(char *line, regmatch_t *match){
401          char *ptr;
402          long long num;
# Line 333 | Line 463 | int statgrab_init(){
463          }
464   #endif
465   #ifdef SOLARIS
466 <        if((build_mapping()) != 0) return 1;
466 >        /* On solaris 7, this will fail if you are not root. But, everything
467 >         * will still work, just no disk mappings. So we will ignore the exit
468 >         * status of this, and carry on merrily.
469 >         */
470 >        build_mapping();
471   #endif
472          return 0;
473   }
474 +
475 + int statgrab_drop_privileges() {
476 +        if (setegid(getgid()) != 0) return -1;
477 +        if (seteuid(getuid()) != 0) return -1;
478 +        return 0;
479 + }
480 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines