Changeset 671


Ignore:
Timestamp:
Dec 3, 2011, 4:41:18 PM (14 years ago)
Author:
Herwig Bauernfeind
Message:

Samba Server 3.5: Fix for Ticket #182 via OS/2 API call

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/utils/net_time.c

    r670 r671  
    2121
    2222#ifdef __OS2__
    23 #define INCL_DOSNLS        /* National Language Support values */
     23#define INCL_DOSDATETIME   /* Date and time values */
    2424#define INCL_DOSERRORS     /* DOS error values */
    2525#include <os2.h>
     
    9797                               tm->tm_min, tm->tm_year + 1900, tm->tm_sec);
    9898}
     99
    99100#ifdef __OS2__
    100 /* return time as a string ready to be passed to cmd time command */
    101 static const char *os2_systime(time_t t)
     101/* set date/time on OS/2 */
     102static int os2_setdatetime(time_t t)
    102103{
    103104        struct tm *tm;
     
    105106        tm = localtime(&t);
    106107        if (!tm) {
    107                 return "unknown";
    108         }
    109 
    110         return talloc_asprintf(talloc_tos(), "%02d:%02d:%02d",
    111                                tm->tm_hour, tm->tm_min, tm->tm_sec);
    112 }
    113 
    114 /* return a date as a string ready to be passed to cmd date command */
    115 static const char *os2_sysdate(time_t t)
    116 {
    117         struct tm *tm;
    118 
    119         tm = localtime(&t);
    120         if (!tm) {
    121                 return "unknown";
    122         }
    123 
    124         COUNTRYCODE  Country    = {0};   /* Country code info (0 = current country) */
    125         COUNTRYINFO  CtryInfo   = {0};   /* Buffer for country-specific information */
    126         ULONG        ulInfoLen  = 0;
    127         APIRET       rc         = NO_ERROR;  /* Return code                         */
    128 
    129         rc = DosQueryCtryInfo(sizeof(CtryInfo), &Country, &CtryInfo, &ulInfoLen);
    130 
     108                return -1;
     109        }
     110
     111        DATETIME   DateTime = {0};      /* Structure to hold date/time info.   */
     112        APIRET     rc       = NO_ERROR; /* Return code                         */
     113
     114        rc = DosGetDateTime(&DateTime); /* Get current date/time to fill structure */
    131115        if (rc != NO_ERROR) {
    132                 printf("DosQueryCtryInfo error: return code = %u\n",rc);
    133                 return talloc_asprintf(talloc_tos(), "%02d.%02d.%04d",
    134                         tm->tm_mon+1, tm->tm_mday, tm->tm_year + 1900);
    135         }
    136         switch (CtryInfo.fsDateFmt) {
    137                 case(1): /* dd/mm/yy */
    138                         return talloc_asprintf(talloc_tos(), "%02d%s%02d%s%04d",
    139                                    tm->tm_mday,  CtryInfo.szDateSeparator,
    140                                    tm->tm_mon+1, CtryInfo.szDateSeparator,
    141                                    tm->tm_year + 1900);
    142                 break;
    143 
    144                 case(2): /* yy/mm/dd */
    145                         return talloc_asprintf(talloc_tos(), "%04d%s%02d%s%02d",
    146                                    tm->tm_year + 1900, CtryInfo.szDateSeparator,
    147                                    tm->tm_mon+1,       CtryInfo.szDateSeparator,
    148                                    tm->tm_mday);
    149                 break;
    150 
    151                 default: /* mm/dd/yy */
    152                         return talloc_asprintf(talloc_tos(), "%02d%s%02d%s%04d",
    153                                    tm->tm_mday,  CtryInfo.szDateSeparator,
    154                                    tm->tm_mon+1, CtryInfo.szDateSeparator,
    155                                    tm->tm_year + 1900);
    156                 break;
    157         } /* endswitch */
     116                return rc;
     117        }
     118
     119        DateTime.year    = (USHORT) ((BYTE) tm->tm_year+1900);
     120        DateTime.month   = (UCHAR) ((BYTE) tm->tm_mon+1);
     121        DateTime.day     = (UCHAR) ((BYTE) tm->tm_mday);
     122        DateTime.hours   = (UCHAR) ((BYTE) tm->tm_hour);
     123        DateTime.minutes = (UCHAR) ((BYTE) tm->tm_min);
     124        DateTime.seconds = (UCHAR) ((BYTE) tm->tm_sec);
     125
     126        rc = DosSetDateTime(&DateTime);  /* Update the date and time */
     127
     128        if (rc!= NO_ERROR) {
     129                printf ("DosSetDateTime error : return code = %u\n", rc);
     130        }
     131        return rc;
    158132}
    159133#endif
     
    181155
    182156#ifdef __OS2__
    183         /* eCS (OS/2) "net time set" routine */
    184         /* First we set the time using cmd internal time command */
    185         if (asprintf(&cmd, "time %s", os2_systime(t)) == -1) {
    186                 return -1;
    187         }
    188         result = system(cmd);
    189         if (result)
    190                 d_fprintf(stderr, _("eCS (OS/2) time set: %s failed.  Error was (%s)\n"),
    191                         cmd, strerror(errno));
    192         /* Then we set the date using cmd internal date command */
    193         if (asprintf(&cmd, "date %s", os2_sysdate(t)) == -1) {
    194                 return -1;
    195         }
    196         result = system(cmd);
    197         if (result)
    198                 d_fprintf(stderr, _("eCS (OS/2) date set: %s failed.  Error was (%s)\n"),
    199                         cmd, strerror(errno));
     157        /* eCS (OS/2) native "net time set" routine */
     158        result = os2_setdatetime(t);
    200159#else
    201160        /* yes, I know this is cheesy. Use "net time system" if you want to
     
    206165        }
    207166        result = system(cmd);
     167#endif
    208168        if (result)
    209169                d_fprintf(stderr, _("%s failed.  Error was (%s)\n"),
    210170                        cmd, strerror(errno));
    211 #endif
    212171        free(cmd);
    213172
Note: See TracChangeset for help on using the changeset viewer.