~ubuntu-branches/ubuntu/hardy/smb4k/hardy

« back to all changes in this revision

Viewing changes to utilities/smb4k_umount.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2006-12-22 12:27:05 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20061222122705-8t2knjt53m79lmbv
Tags: 0.8.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#elif defined(__FreeBSD__)
42
42
#include <sys/param.h>
43
43
#include <sys/mount.h>
44
 
#elif defined(__irix__)
45
 
#include <sys/types.h>
46
44
#endif
47
45
using namespace std;
48
46
 
49
 
#define SMB4K_UMOUNT_VERSION 0.9
 
47
#define SMB4K_UMOUNT_VERSION 0.11
50
48
 
51
49
//
52
50
// Returns the information about the program
304
302
 
305
303
  bool ok = false;
306
304
 
307
 
#if !defined(__FreeBSD__) && !defined(__solaris__) && !defined(USE_SOLARIS) && !defined(__irix__)
 
305
#if !defined(__FreeBSD__) && !defined(__solaris__) && !defined(USE_SOLARIS)
308
306
  // First entry is for CIFS, the second for SMBFS.
309
307
  if ( (uint)filesystem.f_type == 0xFF534D42 || (uint)filesystem.f_type == 0x517B )
310
308
  {
311
 
    strcpy( fs_buf, (uint)filesystem.f_type == 0xFF534D42 ? "cifs" : "smbfs" );
 
309
    const char *fs_type = (uint)filesystem.f_type == 0xFF534D42 ? "cifs" : "smbfs";
 
310
    (void) strncpy( fs_buf, fs_type, strlen( fs_type ) + 1 );
312
311
#elif defined(__FreeBSD__)
313
312
  if ( !strcmp( filesystem.f_fstypename, "smbfs" ) )
314
313
  {
315
 
    strcpy( fs_buf, "smbfs" );
 
314
    const char *fs_type = "smbfs";
 
315
    (void) strncpy( fs_buf, fs_type, strlen( fs_type ) + 1 );
316
316
#elif defined(__solaris__) || defined(USE_SOLARIS)
317
317
  if ( (uint)filesystem.f_basetype == 0xFF534D42 || (uint)filesystem.f_basetype == 0x517B )
318
318
  {
319
 
    strcpy( fs_buf, (uint)filesystem.f_basetype == 0xFF534D42 ? "cifs" : "smbfs" );
 
319
    const char *fs_type = (uint)filesystem.f_basetype == 0xFF534D42 ? "cifs" : "smbfs";
 
320
    (void) strncpy( fs_buf, fs_type, strlen( fs_type ) + 1 );
320
321
#elif defined(__irix__)
321
322
  if ( (uint)filesystem.f_fstyp == 0xFF534D42 || (uint)filesystem.f_fstyp == 0x517B )
322
323
  {
323
 
    strcpy( fs_buf, (uint)filesystem.f_fstyp == 0xFF534D42 ? "cifs" : "smbfs" );
 
324
    const char *fs_type = (uint)filesystem.f_fstyp == 0xFF534D42 ? "cifs" : "smbfs"
 
325
    (void) strncpy( fs_buf, fs_type, strlen( fs_type ) + 1 );
324
326
#endif
325
327
    ok = true;
326
328
  }
375
377
    }
376
378
    else if ( !strcmp( argv[i], "--cifs" ) || !strcmp( argv[i], "--smbfs" ) )
377
379
    {
378
 
      (void) strcpy( fs_arg, argv[i] );
 
380
      (void) strncpy( fs_arg, argv[i], 9 );
 
381
      fs_arg[9] = '\0';
379
382
 
380
383
      continue;
381
384
    }
387
390
 
388
391
      if ( argv[i][0] == '/' || ((argv[i][0] == '\047' /* ' */|| argv[i][0] == '\042' /* " */) && argv[i][1] == '/') )
389
392
      {
390
 
        char *path = new char[strlen( argv[i] )+1];
 
393
        char *path = new char[500];
391
394
 
392
395
        if ( !path )
393
396
        {
395
398
          exit( EXIT_FAILURE );
396
399
        }
397
400
 
398
 
        args[k++] = strcpy( path, replace_special_characters( argv[i] ) );
 
401
        const char *rsc = replace_special_characters( argv[i] );
 
402
        args[k++] = strncpy( path, rsc, 499 );
 
403
        path[499] = '\0';
399
404
 
400
405
        char fs[6];
401
406
 
415
420
            {
416
421
              if ( !strcmp( fs, "smbfs" ) )
417
422
              {
418
 
                args[0] = strcpy( t, findprog( "smbumount" ) );
 
423
                const char *umnt_prg = findprog( "smbumount" );
 
424
                args[0] = strncpy( t, umnt_prg, 254 );
 
425
                t[254] = '\0';
419
426
              }
420
427
              else if ( !strcmp( fs, "cifs" ) )
421
428
              {
422
 
                args[0] = strcpy( t, findprog( "umount.cifs" ) );
 
429
                const char *umnt_prg = findprog( "umount.cifs" );
 
430
                args[0] = strncpy( t, umnt_prg, 254 );
 
431
                t[254] = '\0';
423
432
              }
424
433
              else
425
434
              {
427
436
                // file system info.
428
437
                if ( !strcmp( fs_arg, "--smbfs" ) )
429
438
                {
430
 
                  args[0] = strcpy( t, findprog( "smbumount" ) );
 
439
                  const char *umnt_prg = findprog( "smbumount" );
 
440
                  args[0] = strncpy( t, umnt_prg, 254 );
 
441
                  t[254] = '\0';
431
442
                }
432
443
                else if ( !strcmp( fs_arg, "--cifs" ) )
433
444
                {
434
 
                  args[0] = strcpy( t, findprog( "umount.cifs" ) );
 
445
                  const char *umnt_prg = findprog( "umount.cifs" );
 
446
                  args[0] = strncpy( t, umnt_prg, 254 );
 
447
                  t[254] = '\0';
435
448
                }
436
449
                else
437
450
                {
447
460
            {
448
461
              if ( !strcmp( fs, "smbfs" ) || !strcmp( fs, "cifs" ) )
449
462
              {
450
 
                args[0] = strcpy( t, findprog( "umount" ) );
 
463
                const char *umnt_prg = findprog( "umount" );
 
464
                args[0] = strncpy( t, umnt_prg, 254 );
 
465
                t[254] = '\0';
451
466
              }
452
467
              else
453
468
              {
454
469
                if ( !strcmp( fs_arg, "--smbfs" ) || !strcmp( fs_arg, "--cifs" ) )
455
470
                {
456
 
                  args[0] = strcpy( t, findprog( "umount" ) );
 
471
                  const char *umnt_prg = findprog( "umount" );
 
472
                  args[0] = strncpy( t, umnt_prg, 254 );
 
473
                  t[254] = '\0';
457
474
                }
458
475
                else
459
476
                {
482
499
      }
483
500
      else
484
501
      {
485
 
        char *t = new char[strlen( argv[i] )+1];
 
502
        char *t = new char[500];
486
503
 
487
504
        if ( !t )
488
505
        {
490
507
          exit( EXIT_FAILURE );
491
508
        }
492
509
 
493
 
        args[k++] = strcpy( t, argv[i] );
 
510
        args[k++] = strncpy( t, argv[i], 499 );
 
511
        t[499] = '\0';
494
512
 
495
513
        continue;
496
514
      }
499
517
 
500
518
  args[k] = NULL;
501
519
 
 
520
  if ( k >= 5 )
 
521
  {
 
522
    cerr << "smb4k_umount: Too many arguments" << endl;
 
523
    exit( EXIT_FAILURE );
 
524
  }
 
525
 
502
526
  if ( execve( args[0], args, envp ) == -1 )
503
527
  {
504
528
    int err_code = errno;